def __init__(self): TransparentWindow.__init__(self) self.set_events(gtk.gdk.BUTTON_RELEASE_MASK) self.mode = STATE_NONE self.connect('leave-notify-event', self.leave_notify_cb) self.connect('enter-notify-event', self.enter_notify_cb) self.widgets = [] self.display = self.get_display() self.screen = self.display.get_default_screen() width, height = self.screen.get_width(), self.screen.get_height() self.resize(width, height) self.layout = cream.gui.CompositeBin() self.add(self.layout) keysym, modifier_mask = gtk.accelerator_parse('Super_L') self.ctrl_l_keysym = keysym self.hotkey_recorder = HotkeyRecorder([(keysym, modifier_mask), (keysym, 64), (keysym, 320)]) self.hotkey_recorder.connect('key-press', self.key_press_cb) self.hotkey_recorder.connect('key-release', self.key_release_cb)
class WidgetLayer(TransparentWindow): def __init__(self): TransparentWindow.__init__(self) self.set_events(gtk.gdk.BUTTON_RELEASE_MASK) self.mode = STATE_NONE self.connect('leave-notify-event', self.leave_notify_cb) self.connect('enter-notify-event', self.enter_notify_cb) self.widgets = [] self.display = self.get_display() self.screen = self.display.get_default_screen() width, height = self.screen.get_width(), self.screen.get_height() self.resize(width, height) self.layout = cream.gui.CompositeBin() self.add(self.layout) keysym, modifier_mask = gtk.accelerator_parse('Super_L') self.ctrl_l_keysym = keysym self.hotkey_recorder = HotkeyRecorder([(keysym, modifier_mask), (keysym, 64), (keysym, 320)]) self.hotkey_recorder.connect('key-press', self.key_press_cb) self.hotkey_recorder.connect('key-release', self.key_release_cb) def enter_notify_cb(self, widget, event): for widget in self.widgets: try: for i in xrange(widget.instance.js_context._mootools_entered.length): e = widget.instance.js_context._mootools_entered[i] e.fireEvent('mouseleave') widget.instance.js_context._mootools_entered.erase() except AttributeError: pass def leave_notify_cb(self, widget, event): for widget in self.widgets: try: for i in xrange(widget.instance.js_context._mootools_entered.length): e = widget.instance.js_context._mootools_entered[i] e.fireEvent('mouseleave') widget.instance.js_context._mootools_entered.erase() except AttributeError: pass def key_press_cb(self, source, keysym, modifier_mask): if keysym == self.ctrl_l_keysym and modifier_mask in [0, 64, 320]: self.mode = STATE_MOVE cursor = gtk.gdk.Cursor(gtk.gdk.FLEUR) for widget in self.widgets: widget.instance.begin_move() widget.instance.view.get_window().set_cursor(cursor) def key_release_cb(self, source, keysym, modifier_mask): if keysym == self.ctrl_l_keysym and modifier_mask in [0, 64, 320]: if self.mode == STATE_MOVE: for widget in self.widgets: widget.instance.end_move() widget.instance.view.get_window().set_cursor(None) self.mode = STATE_NONE elif self.mode == STATE_MOVING: self.mode = STATE_MOVE def button_press_cb(self, window, event): if self.mode == STATE_MOVE: self.mode = STATE_MOVING return True def button_release_cb(self, window, event): if self.mode == STATE_MOVE: for widget in self.widgets: widget.instance.end_move() widget.instance.view.get_window().set_cursor(None) self.mode = STATE_NONE elif self.mode == STATE_MOVING: self.mode = STATE_MOVE return True def add_widget(self, widget): self.widgets.append(widget) view = widget.instance.get_view() view.connect('button-press-event', self.button_press_cb) view.connect('button-release-event', self.button_release_cb) self.layout.add(view, *widget.get_position()) view.show_all() def remove_widget(self, widget): self.widgets.remove(widget) view = widget.instance.get_view() self.layout.remove(view) def raise_widget(self, widget): view = widget.instance.get_view() self.layout.raise_child(view) def move_widget(self, widget, x, y): view = widget.instance.get_view() self.layout.move(view, x, y)