def _key_release_cb(self, widget, event): """Application-wide key release handler.""" def released(hardware_keycode): action = self.pressed[hardware_keycode] del self.pressed[hardware_keycode] if action.keyup_callback: action.keyup_callback(widget, event) action.keyup_callback = None if event.keyval == gtk.keysyms.Escape: # emergency exit in case of bugs for hardware_keycode in self.pressed.keys(): released(hardware_keycode) # Pop all stacked modes; they should release grabs self.app.doc.modes.reset() # Just in case... gdk.pointer_ungrab(event.time) else: # note: event.keyval would not be suited for this because # it can be different from the one we have seen in # key_press_cb if the user has released a modifier first if event.hardware_keycode in self.pressed: released(event.hardware_keycode) return True # Fallthru handler: dispatch doc-specific stuff. return self._dispatch_fallthru_key_release_event(widget, event)
def key_release_cb(self, widget, event): """Application-wide key release handler. """ def released(hardware_keycode): #gdk.keyboard_ungrab(event.time) action = self.pressed[hardware_keycode] del self.pressed[hardware_keycode] #logger.debug('RELEASE %r', action.get_name()) if action.keyup_callback: action.keyup_callback(widget, event) action.keyup_callback = None if event.keyval == gtk.keysyms.Escape: # emergency exit in case of bugs for hardware_keycode in self.pressed.keys(): released(hardware_keycode) # Pop all stacked modes; they should release grabs self.app.doc.modes.reset() # Just in case... gdk.pointer_ungrab(event.time) else: # note: event.keyval would not be suited for this because # it can be different from the one we have seen in # key_press_cb if the user has released a modifier first if event.hardware_keycode in self.pressed: released(event.hardware_keycode) return True
def ungrab(self): """Ungrab pointer""" pointer_ungrab() while self.events: self.window.disconnect(self.events.pop()) self.grabbing = False self.grab_btn.set_label('Grab')
def __button_release_cb(self, widget, event): if not self.__picking: return False if event.state & gdk.BUTTON1_MASK: color = get_color_at_pointer(self.get_display()) self.set_managed_color(color) self.__picking = False gdk.pointer_ungrab(gdk.CURRENT_TIME)
def popup_grab_on_window(self, window, activate_time): if gdk.pointer_grab( window, True, gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK, None, None, activate_time) == 0: if gdk.keyboard_grab(window, True, activate_time) == 0: return True else: gdk.pointer_ungrab(activate_time) return False return False
def popup_grab_on_window(self, window, activate_time): if gdk.pointer_grab(window, True, gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK, None, None, activate_time) == 0: if gdk.keyboard_grab (window, True, activate_time) == 0: return True else: gdk.pointer_ungrab(activate_time) return False return False
def _stop_drag(self, t=gdk.CURRENT_TIME): # Stops any active drag, calls drag_stop_cb(), and cleans up. if not self.in_drag: return tdw = self._grab_widget tdw.grab_remove() gdk.keyboard_ungrab(t) gdk.pointer_ungrab(t) self._grab_widget = None self.drag_stop_cb(tdw) self._reset_drag_state()
def establish_grab(self, t=0): # Grab, permitting normal interaction with the app (i.e. with the widgets # in the panel). mask = gdk.BUTTON_PRESS_MASK grab_result = gdk.pointer_grab(self.window, True, mask, None, None, t) if grab_result != gdk.GRAB_SUCCESS: print "pointer grab failed:", grab_result return False # Keyboard grab too, to prevent workspace switching. grab_result = gdk.keyboard_grab(self.window, False, t) if grab_result != gdk.GRAB_SUCCESS: print "keyboard grab failed:", grab_result gdk.pointer_ungrab() return False # But limit events to just the panel for neatness and a hint of modality. self.grab_add() self._grabbed = True return True
def establish_grab(self, t=0): # Grab, permitting normal interaction with the app (i.e. with the widgets # in the panel). mask = gdk.BUTTON_PRESS_MASK gdk_window = self.get_window() grab_result = gdk.pointer_grab(gdk_window, True, mask, None, None, t) if grab_result != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_result) return False # Keyboard grab too, to prevent workspace switching. grab_result = gdk.keyboard_grab(gdk_window, False, t) if grab_result != gdk.GRAB_SUCCESS: logger.warning("keyboard grab failed: %r", grab_result) gdk.pointer_ungrab(gdk.CURRENT_TIME) return False # But limit events to just the panel for neatness and a hint of modality. self.grab_add() self._grabbed = True return True
def grab_stop(self): self.grabbing = False gdk.pointer_ungrab() self.grab_remove()
def _hide_cb(self, widget): if self._grabbed: gdk.keyboard_ungrab(gdk.CURRENT_TIME) gdk.pointer_ungrab(gdk.CURRENT_TIME) self._grabbed = False self.grab_remove()
def window_ungrab(self): gdk.pointer_ungrab() gdk.keyboard_ungrab()
def pick_stop(self): self.picking = False gdk.pointer_ungrab() self.grab_remove()
def _end_move_field(self, time): if not self._moving_field: return gdk.pointer_ungrab(long(time)) self._moving_field = None
def _start_drag(self, tdw, event): # Attempt to start a new drag, calling drag_start_cb() if successful. if self.in_drag: return if hasattr(event, "x"): self.start_x = event.x self.start_y = event.y else: #last_x, last_y = tdw.get_pointer() last_t, last_x, last_y = self.doc.get_last_event_info(tdw) self.start_x = last_x self.start_y = last_y tdw_window = tdw.get_window() event_mask = (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK) cursor = self.active_cursor if cursor is None: cursor = self.inactive_cursor # Grab the pointer grab_status = gdk.pointer_grab(tdw_window, False, event_mask, None, cursor, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_status) logger.debug("gdk_pointer_is_grabbed(): %r", gdk.pointer_is_grabbed()) # There seems to be a race condition between this grab under # PyGTK/GTK2 and some other grab - possibly just the implicit grabs # on color selectors: https://gna.org/bugs/?20068 Only pointer # events are affected, and PyGI+GTK3 is unaffected. # # It's probably safest to exit the mode and not start the drag. # This condition should be rare enough for this to be a valid # approach: the irritation of having to click again to do something # should be far less than that of getting "stuck" in a drag. if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() # Sometimes a pointer ungrab is needed even though the grab # apparently failed to avoid the UI partially "locking up" with the # stylus (and only the stylus). Happens when WMs like Xfwm # intercept an <Alt>Button combination for window management # purposes. Results in gdk.GRAB_ALREADY_GRABBED, but this line is # necessary to avoid the rest of the UI becoming unresponsive even # though the canvas can be drawn on with the stylus. Are we # cancelling an implicit grab here, and why is it device specific? gdk.pointer_ungrab(event.time) return # We managed to establish a grab, so watch for it being broken. # This signal is disconnected when the mode leaves. connid = tdw.connect("grab-broken-event", self.tdw_grab_broken_cb) self._grab_broken_conninfo = (tdw, connid) # Grab the keyboard too, to be certain of getting the key release event # for a spacebar drag. grab_status = gdk.keyboard_grab(tdw_window, False, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("Keyboard grab failed: %r", grab_status) gdk.pointer_ungrab(event.time) if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() return # GTK too... tdw.grab_add() self._grab_widget = tdw # Drag has started, perform whatever action the mode needs. self.drag_start_cb(tdw, event)
def _hide_cb(self, widget): if self._grabbed: gdk.pointer_ungrab() self._grabbed = False self.grab_remove()
def unlock(self): pointer_ungrab() keyboard_ungrab()
def _start_drag(self, tdw, event): # Attempt to start a new drag, calling drag_start_cb() if successful. if self.in_drag: return if hasattr(event, "x"): self.start_x = event.x self.start_y = event.y else: #last_x, last_y = tdw.get_pointer() last_t, last_x, last_y = self.doc.get_last_event_info(tdw) self.start_x = last_x self.start_y = last_y tdw_window = tdw.get_window() event_mask = (gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK) cursor = self.active_cursor if cursor is None: cursor = self.inactive_cursor # Grab the pointer grab_status = gdk.pointer_grab(tdw_window, False, event_mask, None, cursor, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("pointer grab failed: %r", grab_status) logger.debug("gdk_pointer_is_grabbed(): %r", gdk.pointer_is_grabbed()) # There seems to be a race condition between this grab under # PyGTK/GTK2 and some other grab - possibly just the implicit grabs # on colour selectors: https://gna.org/bugs/?20068 Only pointer # events are affected, and PyGI+GTK3 is unaffected. # # It's probably safest to exit the mode and not start the drag. # This condition should be rare enough for this to be a valid # approach: the irritation of having to click again to do something # should be far less than that of getting "stuck" in a drag. if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() # Sometimes a pointer ungrab is needed even though the grab # apparently failed to avoid the UI partially "locking up" with the # stylus (and only the stylus). Happens when WMs like Xfwm # intercept an <Alt>Button combination for window management # purposes. Results in gdk.GRAB_ALREADY_GRABBED, but this line is # necessary to avoid the rest of the UI becoming unresponsive even # though the canvas can be drawn on with the stylus. Are we # cancelling an implicit grab here, and why is it device specific? gdk.pointer_ungrab(event.time) return # We managed to establish a grab, so watch for it being broken. # This signal is disconnected when the mode leaves. connid = tdw.connect("grab-broken-event", self.tdw_grab_broken_cb) self._grab_broken_conninfo = (tdw, connid) # Grab the keyboard too, to be certain of getting the key release event # for a spacebar drag. grab_status = gdk.keyboard_grab(tdw_window, False, event.time) if grab_status != gdk.GRAB_SUCCESS: logger.warning("Keyboard grab failed: %r", grab_status) gdk.pointer_ungrab(event.time) if self is self.doc.modes.top: logger.debug("Exiting mode") self.doc.modes.pop() return # GTK too... tdw.grab_add() self._grab_widget = tdw # Drag has started, perform whatever action the mode needs. self.drag_start_cb(tdw, event)
def _end_move_child(self, time): if not self._moving_child: return gdk.pointer_ungrab(long(time)) self._moving_child = None
def popdown(self): gdk.pointer_ungrab(gtk.get_current_event_time()) self.grab_remove() self.destroy()