Back to index

unity  6.0.0
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
unity.emulators.launcher.Launcher Class Reference
Inheritance diagram for unity.emulators.launcher.Launcher:
Inheritance graph
[legend]
Collaboration diagram for unity.emulators.launcher.Launcher:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def move_mouse_to_right_of_launcher
def move_mouse_over_launcher
def move_mouse_to_icon
def mouse_reveal_launcher
def keyboard_reveal_launcher
def keyboard_unreveal_launcher
def keyboard_select_icon
def key_nav_start
def key_nav_cancel
def key_nav_activate
def key_nav_next
def key_nav_prev
def key_nav_enter_quicklist
def key_nav_exit_quicklist
def switcher_start
def switcher_cancel
def switcher_activate
def switcher_next
def switcher_prev
def switcher_up
def switcher_down
def click_launcher_icon
def drag_icon_to_position
def lock_to_launcher
def unlock_from_launcher
def geometry

Public Attributes

 show_timeout
 hide_timeout
 in_keynav_mode
 in_switcher_mode
 hidemode

Static Public Attributes

string DBUS_SERVICE = "com.canonical.Unity"
string DBUS_OBJECT = "/com/canonical/Unity/Debug"

Private Member Functions

def _perform_key_nav_binding
def _perform_key_nav_exit_binding
def _perform_switcher_binding
def _perform_switcher_exit_binding
def _get_controller

Private Attributes

 _mouse
 _screen

Detailed Description

An individual launcher for a monitor.

Definition at line 67 of file launcher.py.


Constructor & Destructor Documentation

def unity.emulators.launcher.Launcher.__init__ (   self,
  args,
  kwargs 
)

Definition at line 70 of file launcher.py.

00070 
00071     def __init__(self, *args, **kwargs):
00072         super(Launcher, self).__init__(*args, **kwargs)
00073 
00074         self.show_timeout = 1
00075         self.hide_timeout = 1
00076         self.in_keynav_mode = False
00077         self.in_switcher_mode = False
00078 
00079         self._mouse = Mouse()
00080         self._screen = ScreenGeometry()


Member Function Documentation

Get the launcher controller.

Definition at line 104 of file launcher.py.

00104 
00105     def _get_controller(self):
00106         """Get the launcher controller."""
00107         [controller] = LauncherController.get_all_instances()
00108         return controller

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher._perform_key_nav_binding (   self,
  keybinding 
) [private]

Definition at line 81 of file launcher.py.

00081 
00082     def _perform_key_nav_binding(self, keybinding):
00083         if not self.in_keynav_mode:
00084                 raise RuntimeError("Cannot perform key navigation when not in kaynav mode.")
00085         self.keybinding(keybinding)

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher._perform_key_nav_exit_binding (   self,
  keybinding 
) [private]

Definition at line 86 of file launcher.py.

00086 
00087     def _perform_key_nav_exit_binding(self, keybinding):
00088         self._perform_key_nav_binding(keybinding)
00089         self.in_keynav_mode = False

Here is the call graph for this function:

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher._perform_switcher_binding (   self,
  keybinding 
) [private]

Definition at line 90 of file launcher.py.

00090 
00091     def _perform_switcher_binding(self, keybinding):
00092         if not self.in_switcher_mode:
00093             raise RuntimeError("Cannot interact with launcher switcher when not in switcher mode.")
00094         self.keybinding(keybinding)

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher._perform_switcher_exit_binding (   self,
  keybinding 
) [private]

Definition at line 95 of file launcher.py.

00095 
00096     def _perform_switcher_exit_binding(self, keybinding):
00097         # If we're doing a normal activation, all we need to do is release the
00098         # keybinding. Otherwise, perform the keybinding specified *then* release
00099         # the switcher keybinding.
00100         if keybinding != "launcher/switcher":
00101             self._perform_switcher_binding(keybinding)
00102         self.keybinding_release("launcher/switcher")
00103         self.in_switcher_mode = False

Here is the call graph for this function:

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher.click_launcher_icon (   self,
  icon,
  button = 1 
)
Move the mouse over the launcher icon, and click it.
`icon` must be an instance of SimpleLauncherIcon or it's descendants.

Definition at line 308 of file launcher.py.

00308 
00309     def click_launcher_icon(self, icon, button=1):
00310         """Move the mouse over the launcher icon, and click it.
00311         `icon` must be an instance of SimpleLauncherIcon or it's descendants.
00312         """
00313         if not isinstance(icon, SimpleLauncherIcon):
00314             raise TypeError("icon must be a LauncherIcon, not %s" % type(icon))
00315 
00316         logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",
00317             icon, self.monitor, button)
00318         self.mouse_reveal_launcher()
00319 
00320         # The icon may be off the screen, so we do this in a loop:
00321         while 1:
00322             target_x = icon.center_x + self.x
00323             target_y = icon.center_y
00324             if self._mouse.x == target_x and self._mouse.y == target_y:
00325                 break
00326             self._mouse.move(target_x, target_y )
00327             sleep(1)
00328         self._mouse.click(button)
00329         self.move_mouse_to_right_of_launcher()

Here is the call graph for this function:

Here is the caller graph for this function:

def unity.emulators.launcher.Launcher.drag_icon_to_position (   self,
  icon,
  pos,
  drag_type = IconDragType.INSIDE 
)
Place the supplied icon above the icon in the position pos.

The icon is dragged inside or outside the launcher.

>>> drag_icon_to_position(calc_icon, 0, IconDragType.INSIDE)

This will drag the calculator icon above the bfb (but as you can't go
above the bfb it will move below it (to position 1))

Definition at line 330 of file launcher.py.

00330 
00331     def drag_icon_to_position(self, icon, pos, drag_type=IconDragType.INSIDE):
00332         """Place the supplied icon above the icon in the position pos.
00333 
00334         The icon is dragged inside or outside the launcher.
00335 
00336         >>> drag_icon_to_position(calc_icon, 0, IconDragType.INSIDE)
00337 
00338         This will drag the calculator icon above the bfb (but as you can't go
00339         above the bfb it will move below it (to position 1))
00340 
00341         """
00342         if not isinstance(icon, BamfLauncherIcon):
00343             raise TypeError("icon must be a LauncherIcon")
00344 
00345         [launcher_model] = LauncherModel.get_all_instances()
00346         all_icons = launcher_model.get_launcher_icons()
00347         all_icon_len = len(all_icons)
00348         if pos >= all_icon_len:
00349             raise ValueError("pos is outside valid range (0-%d)" % all_icon_len)
00350 
00351         logger.debug("Dragging launcher icon %r on monitor %d to position %s"
00352                      % (icon, self.monitor, pos))
00353         self.mouse_reveal_launcher()
00354 
00355         icon_height = get_compiz_option("unityshell", "icon_size")
00356 
00357         target_icon = all_icons[pos]
00358         if target_icon.id == icon.id:
00359             logger.warning("%s is already the icon in position %d. Nothing to do." % (icon, pos))
00360             return
00361 
00362         self.move_mouse_to_icon(icon)
00363         self._mouse.press()
00364         sleep(2)
00365 
00366         if drag_type == IconDragType.OUTSIDE:
00367             shift_over = self._mouse.x + (icon_height * 2)
00368             self._mouse.move(shift_over, self._mouse.y)
00369             sleep(0.5)
00370 
00371         # find the target drop position, between the center & top of the target icon
00372         target_y = target_icon.center_y - floor(icon_height / 4)
00373 
00374         # Need to move the icons top (if moving up) or bottom (if moving
00375         # downward) to the target position
00376         moving_up = True if icon.center_y > target_icon.center_y else False
00377         icon_half_height = floor(icon_height / 2)
00378         fudge_factor = 5
00379         if moving_up or drag_type == IconDragType.OUTSIDE:
00380             target_y += icon_half_height + fudge_factor
00381         else:
00382             target_y -= icon_half_height - fudge_factor
00383 
00384         self._mouse.move(self._mouse.x, target_y, rate=20,
00385                          time_between_events=0.05)
00386         sleep(1)
00387 
00388         self._mouse.release()
00389         self.move_mouse_to_right_of_launcher()

Here is the call graph for this function:

Returns a tuple of (x,y,w,h) for the current launcher.

Definition at line 425 of file launcher.py.

00425 
00426     def geometry(self):
00427         """Returns a tuple of (x,y,w,h) for the current launcher."""
00428         return (self.x, self.y, self.width, self.height)
00429 

Here is the call graph for this function:

Here is the caller graph for this function:

Activates the selected launcher icon. In the current implementation
this also exits key navigation

Definition at line 232 of file launcher.py.

00232 
00233     def key_nav_activate(self):
00234         """Activates the selected launcher icon. In the current implementation
00235         this also exits key navigation"""
00236         logger.debug("Ending keyboard navigation mode, activating icon.")
00237         self._perform_key_nav_exit_binding("launcher/keynav/activate")
00238         self._get_controller().key_nav_is_active.wait_for(False)

Here is the call graph for this function:

End the key navigation.

Definition at line 226 of file launcher.py.

00226 
00227     def key_nav_cancel(self):
00228         """End the key navigation."""
00229         logger.debug("Cancelling keyboard navigation mode.")
00230         self._perform_key_nav_exit_binding("launcher/keynav/exit")
00231         self._get_controller().key_nav_is_active.wait_for(False)

Here is the call graph for this function:

Definition at line 253 of file launcher.py.

00253 
00254     def key_nav_enter_quicklist(self):
00255         logger.debug("Opening quicklist for currently selected icon.")
00256         self._perform_key_nav_binding("launcher/keynav/open-quicklist")
00257         self.quicklist_open.wait_for(True)

Here is the call graph for this function:

Definition at line 258 of file launcher.py.

00258 
00259     def key_nav_exit_quicklist(self):
00260         logger.debug("Closing quicklist for currently selected icon.")
00261         self._perform_key_nav_binding("launcher/keynav/close-quicklist")
00262         self.quicklist_open.wait_for(False)

Here is the call graph for this function:

Moves the launcher keynav focus to the next launcher icon

Definition at line 239 of file launcher.py.

00239 
00240     def key_nav_next(self):
00241         """Moves the launcher keynav focus to the next launcher icon"""
00242         logger.debug("Selecting next item in keyboard navigation mode.")
00243         old_selection = self._get_controller().key_nav_selection
00244         self._perform_key_nav_binding("launcher/keynav/next")
00245         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

Here is the caller graph for this function:

Moves the launcher keynav focus to the previous launcher icon

Definition at line 246 of file launcher.py.

00246 
00247     def key_nav_prev(self):
00248         """Moves the launcher keynav focus to the previous launcher icon"""
00249         logger.debug("Selecting previous item in keyboard navigation mode.")
00250         old_selection = self._get_controller().key_nav_selection
00251         self._perform_key_nav_binding("launcher/keynav/prev")
00252         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

Start keyboard navigation mode by pressing Alt+F1.

Definition at line 218 of file launcher.py.

00218 
00219     def key_nav_start(self):
00220         """Start keyboard navigation mode by pressing Alt+F1."""
00221         self._screen.move_mouse_to_monitor(self.monitor)
00222         logger.debug("Initiating launcher keyboard navigation with Alt+F1.")
00223         self.keybinding("launcher/keynav")
00224         self._get_controller().key_nav_is_active.wait_for(True)
00225         self.in_keynav_mode = True

Here is the call graph for this function:

Reveal this launcher using the keyboard.

Definition at line 156 of file launcher.py.

00156 
00157     def keyboard_reveal_launcher(self):
00158         """Reveal this launcher using the keyboard."""
00159         self._screen.move_mouse_to_monitor(self.monitor)
00160         logger.debug("Revealing launcher with keyboard.")
00161         self.keybinding_hold("launcher/reveal")
00162         self.is_showing.wait_for(True)

Here is the call graph for this function:

Using either keynav mode or the switcher, select an icon in the launcher.

The desired mode (keynav or switcher) must be started already before
calling this methods or a RuntimeError will be raised.

This method won't activate the icon, it will only select it.

Icons are selected by passing keyword argument filters to this method.
For example:

>>> launcher.keyboard_select_icon(tooltip_text="Calculator")

...will select the *first* icon that has a 'tooltip_text' attribute equal
to 'Calculator'. If an icon is missing the attribute, it is treated as
not matching.

If no icon is found, this method will raise a ValueError.

Definition at line 172 of file launcher.py.

00172 
00173     def keyboard_select_icon(self, **kwargs):
00174         """Using either keynav mode or the switcher, select an icon in the launcher.
00175 
00176         The desired mode (keynav or switcher) must be started already before
00177         calling this methods or a RuntimeError will be raised.
00178 
00179         This method won't activate the icon, it will only select it.
00180 
00181         Icons are selected by passing keyword argument filters to this method.
00182         For example:
00183 
00184         >>> launcher.keyboard_select_icon(tooltip_text="Calculator")
00185 
00186         ...will select the *first* icon that has a 'tooltip_text' attribute equal
00187         to 'Calculator'. If an icon is missing the attribute, it is treated as
00188         not matching.
00189 
00190         If no icon is found, this method will raise a ValueError.
00191 
00192         """
00193 
00194         if not self.in_keynav_mode and not self.in_switcher_mode:
00195             raise RuntimeError("Launcher must be in keynav or switcher mode")
00196 
00197         [launcher_model] = LauncherModel.get_all_instances()
00198         all_icons = launcher_model.get_launcher_icons()
00199         logger.debug("all_icons = %r", [i.tooltip_text for i in all_icons])
00200         for icon in all_icons:
00201             # can't iterate over the model icons directly since some are hidden
00202             # from the user.
00203             if not icon.visible:
00204                 continue
00205             logger.debug("Selected icon = %s", icon.tooltip_text)
00206             matches = True
00207             for arg,val in kwargs.iteritems():
00208                 if not hasattr(icon, arg) or getattr(icon, arg, None) != val:
00209                     matches = False
00210                     break
00211             if matches:
00212                 return
00213             if self.in_keynav_mode:
00214                 self.key_nav_next()
00215             elif self.in_switcher_mode:
00216                 self.switcher_next()
00217         raise ValueError("No icon found that matches: %r", kwargs)

Here is the call graph for this function:

Un-reveal this launcher using the keyboard.

Definition at line 163 of file launcher.py.

00163 
00164     def keyboard_unreveal_launcher(self):
00165         """Un-reveal this launcher using the keyboard."""
00166         self._screen.move_mouse_to_monitor(self.monitor)
00167         logger.debug("Un-revealing launcher with keyboard.")
00168         self.keybinding_release("launcher/reveal")
00169         # only wait if the launcher is set to autohide
00170         if self.hidemode == 1:
00171             self.is_showing.wait_for(False)

Here is the call graph for this function:

lock 'icon' to the launcher, if it's not already.
`icon` must be an instance of BamfLauncherIcon.

Definition at line 390 of file launcher.py.

00390 
00391     def lock_to_launcher(self, icon):
00392         """lock 'icon' to the launcher, if it's not already.
00393         `icon` must be an instance of BamfLauncherIcon.
00394         """
00395         if not isinstance(icon, BamfLauncherIcon):
00396             raise TypeError("Can only lock instances of BamfLauncherIcon")
00397         if icon.sticky:
00398             # Nothing to do.
00399             return
00400 
00401         logger.debug("Locking icon %r to launcher.", icon)
00402         self.click_launcher_icon(icon, button=3)
00403         quicklist = icon.get_quicklist()
00404         pin_item = quicklist.get_quicklist_item_by_text('Lock to Launcher')
00405         quicklist.click_item(pin_item)

Here is the call graph for this function:

Reveal this launcher with the mouse.

If the launcher is already visible calling this method does nothing.

Definition at line 140 of file launcher.py.

00140 
00141     def mouse_reveal_launcher(self):
00142         """Reveal this launcher with the mouse.
00143 
00144         If the launcher is already visible calling this method does nothing.
00145         """
00146         if self.is_showing:
00147             return
00148         self._screen.move_mouse_to_monitor(self.monitor)
00149         (x, y, w, h) = self.geometry
00150 
00151         target_x = x - 920 # this is the pressure we need to reveal the launcher.
00152         target_y = y + h / 2
00153         logger.debug("Revealing launcher on monitor %d with mouse.", self.monitor)
00154         self._mouse.move(target_x, target_y, True, 5, .002)
00155         sleep(self.show_timeout)

Here is the call graph for this function:

Here is the caller graph for this function:

Move the mouse over this launcher.

Definition at line 120 of file launcher.py.

00120 
00121     def move_mouse_over_launcher(self):
00122         """Move the mouse over this launcher."""
00123         self._screen.move_mouse_to_monitor(self.monitor)
00124         (x, y, w, h) = self.geometry
00125         target_x = x + w / 2
00126         target_y = y + h / 2
00127 
00128         logger.debug("Moving mouse to center of launcher.")
00129         self._mouse.move(target_x, target_y)

Here is the call graph for this function:

Definition at line 130 of file launcher.py.

00130 
00131     def move_mouse_to_icon(self, icon):
00132         # The icon may be off the bottom of screen, so we do this in a loop:
00133         while 1:
00134             target_x = icon.center_x + self.x
00135             target_y = icon.center_y
00136             if self._mouse.x == target_x and self._mouse.y == target_y:
00137                 break
00138             self._mouse.move(target_x, target_y)
00139             sleep(0.5)

Here is the call graph for this function:

Here is the caller graph for this function:

Places the mouse to the right of this launcher.

Definition at line 109 of file launcher.py.

00109 
00110     def move_mouse_to_right_of_launcher(self):
00111         """Places the mouse to the right of this launcher."""
00112         self._screen.move_mouse_to_monitor(self.monitor)
00113         (x, y, w, h) = self.geometry
00114         target_x = x + w + 10
00115         target_y = y + h / 2
00116 
00117         logger.debug("Moving mouse away from launcher.")
00118         self._mouse.move(target_x, target_y, False)
00119         sleep(self.show_timeout)

Here is the call graph for this function:

Here is the caller graph for this function:

Activates the selected launcher icon. In the current implementation
this also exits the switcher

Definition at line 277 of file launcher.py.

00277 
00278     def switcher_activate(self):
00279         """Activates the selected launcher icon. In the current implementation
00280         this also exits the switcher"""
00281         logger.debug("Ending keyboard navigation mode.")
00282         self._perform_switcher_exit_binding("launcher/switcher")
00283         self._get_controller().key_nav_is_active.wait_for(False)

Here is the call graph for this function:

End the super+tab swithcer.

Definition at line 271 of file launcher.py.

00271 
00272     def switcher_cancel(self):
00273         """End the super+tab swithcer."""
00274         logger.debug("Cancelling keyboard navigation mode.")
00275         self._perform_switcher_exit_binding("launcher/switcher/exit")
00276         self._get_controller().key_nav_is_active.wait_for(False)

Here is the call graph for this function:

Definition at line 302 of file launcher.py.

00302 
00303     def switcher_down(self):
00304         logger.debug("Selecting previous item in keyboard navigation mode.")
00305         old_selection = self._get_controller().key_nav_selection
00306         self._perform_switcher_binding("launcher/switcher/down")
00307         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

Definition at line 284 of file launcher.py.

00284 
00285     def switcher_next(self):
00286         logger.debug("Selecting next item in keyboard navigation mode.")
00287         old_selection = self._get_controller().key_nav_selection
00288         self._perform_switcher_binding("launcher/switcher/next")
00289         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 290 of file launcher.py.

00290 
00291     def switcher_prev(self):
00292         logger.debug("Selecting previous item in keyboard navigation mode.")
00293         old_selection = self._get_controller().key_nav_selection
00294         self._perform_switcher_binding("launcher/switcher/prev")
00295         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

Start the super+Tab switcher on this launcher.

Definition at line 263 of file launcher.py.

00263 
00264     def switcher_start(self):
00265         """Start the super+Tab switcher on this launcher."""
00266         self._screen.move_mouse_to_monitor(self.monitor)
00267         logger.debug("Starting Super+Tab switcher.")
00268         self.keybinding_hold_part_then_tap("launcher/switcher")
00269         self._get_controller().key_nav_is_active.wait_for(True)
00270         self.in_switcher_mode = True

Here is the call graph for this function:

Definition at line 296 of file launcher.py.

00296 
00297     def switcher_up(self):
00298         logger.debug("Selecting next item in keyboard navigation mode.")
00299         old_selection = self._get_controller().key_nav_selection
00300         self._perform_switcher_binding("launcher/switcher/up")
00301         self._get_controller().key_nav_selection.wait_for(NotEquals(old_selection))

Here is the call graph for this function:

lock 'icon' to the launcher, if it's not already.

`icon` must be an instance of BamfLauncherIcon.

Definition at line 406 of file launcher.py.

00406 
00407     def unlock_from_launcher(self, icon):
00408         """lock 'icon' to the launcher, if it's not already.
00409 
00410         `icon` must be an instance of BamfLauncherIcon.
00411 
00412         """
00413         if not isinstance(icon, BamfLauncherIcon):
00414             raise TypeError("Can only unlock instances of BamfLauncherIcon")
00415         if not icon.sticky:
00416             # nothing to do.
00417             return
00418 
00419         logger.debug("Unlocking icon %r from launcher.")
00420         self.click_launcher_icon(icon, button=3)
00421         quicklist = icon.get_quicklist()
00422         pin_item = quicklist.get_quicklist_item_by_text('Unlock from Launcher')
00423         quicklist.click_item(pin_item)

Here is the call graph for this function:


Member Data Documentation

Definition at line 78 of file launcher.py.

Definition at line 79 of file launcher.py.

string unity.emulators.UnityIntrospectionObject.DBUS_OBJECT = "/com/canonical/Unity/Debug" [static, inherited]

Definition at line 19 of file __init__.py.

string unity.emulators.UnityIntrospectionObject.DBUS_SERVICE = "com.canonical.Unity" [static, inherited]

Definition at line 18 of file __init__.py.

Definition at line 74 of file launcher.py.

Definition at line 169 of file launcher.py.

Definition at line 75 of file launcher.py.

Definition at line 76 of file launcher.py.

Definition at line 73 of file launcher.py.


The documentation for this class was generated from the following file: