Ejemplo n.º 1
0
    def run(self):
        window.set_keep_above(True)
        window.set_app_paintable(True)

        window.add_events(gtk.gdk.POINTER_MOTION_MASK)
        window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        window.add_events(gtk.gdk.BUTTON_RELEASE_MASK)

        window.connect("expose-event", lambda w, e: getCurrentCoord(w))
        window.connect("expose-event", redraw)
        # window.connect("realize", realize_win)
        window.connect("key-press-event", keyPress)
        window.connect("motion-notify-event", motionNotify)
        window.connect("button-press-event", buttonPress)
        window.connect("button-release-event", buttonRelease)
        window.connect('check-resize', resizemainwin)
        window.connect("destroy", gtk.main_quit)
        window.connect("delete-event", delete_event)

        statusicon.connect('activate', status_clicked )
        statusicon.connect('popup-menu', on_right_click)
        window.show_all()
        while 1:
            a= gtk.events_pending()
            print(a)
            print(gtk.get_current_event())
            gtk.main_iteration()
Ejemplo n.º 2
0
    def mode_flip_action_activated_cb(self, flip_action):
        """Callback: mode "flip" action activated.

        :param flip_action: the gtk.Action which was activated

        Mode classes are looked up via `canvasevent.ModeRegistry` based on the
        name of the action: flip actions are named after the RadioActions they
        nominally control, with "Flip" prepended.  Activating a FlipAction has
        the effect of flipping a mode off if it is currently active, or on if
        another mode is active. Mode flip actions are the usual actions bound
        to keypresses since being able to toggle off with the same key is
        useful.

        Because these modes are intended for keyboard activation, they are
        instructed to ignore the initial keyboard modifier state when entered.
        See also: `canvasevent.SpringLoadedModeMixin`.

        """
        flip_action_name = flip_action.get_name()
        assert flip_action_name.startswith("Flip")
        # Find the corresponding gtk.RadioAction
        action_name = flip_action_name.replace("Flip", "", 1)
        mode_class = canvasevent.ModeRegistry.get_mode_class(action_name)
        if mode_class is None:
            warn('"%s" not registered: check imports' % action_name, Warning)
            return

        # If a mode object of this exact class is active, pop the stack.
        # Otherwise, instantiate and enter.
        if self.modes.top.__class__ is mode_class:
            self.modes.pop()
            flip_action.keyup_callback = lambda *a: None  # suppress repeats
        else:
            mode = mode_class(ignore_modifiers=True)
            if flip_action.keydown:
                flip_action.__pressed = True
                # Change what happens on a key-up after a short while.
                # Distinguishes long presses from short.
                timeout = getattr(mode, "keyup_timeout", 500)
                cb = self._modeflip_change_keyup_callback
                ev = gtk.get_current_event()
                if ev is not None:
                    ev = ev.copy()
                if timeout > 0:
                    # Queue a change of key-up callback after the timeout
                    gobject.timeout_add(timeout, cb, mode, flip_action, ev)

                    def _continue_mode_early_keyup_cb(*a):
                        # Record early keyup, but otherwise keep in mode
                        flip_action.__pressed = False

                    flip_action.keyup_callback = _continue_mode_early_keyup_cb
                else:
                    # Key-up exits immediately
                    def _exit_mode_early_keyup_cb(*a):
                        if mode is self.modes.top:
                            self.modes.pop()

                    flip_action.keyup_callback = _exit_mode_early_keyup_cb
            self.modes.context_push(mode)
Ejemplo n.º 3
0
def begin_move():
    global header_button_down, header_button_down_x, header_button_down_y
    
    event = gtk.get_current_event()
    window.begin_move_drag(1,
                           int(round(0.5 + event.x_root)), int(round(event.y_root)),
                           event.time)
Ejemplo n.º 4
0
 def add_event_clicked_callback(self, button):
     """ Add event button pressed. """
     menu = self.__addEventMenu
     x, y = self.__get_widget_xy_position(button, menu)
     self.__toggle_window_close()
     event = gtk.get_current_event()
     menu.popup(None, None, lambda menu: (x, y, True), event.button, event.time)
Ejemplo n.º 5
0
 def image_button_clicked(button):
     event=gtk.get_current_event()
     if event.state & gtk.gdk.CONTROL_MASK:
         self.use_current_position(button)
         return True
     else:
         self.play_from_here(button)
         return True
Ejemplo n.º 6
0
 def _popup_menu_selected(self, menuitem, togglebutton, action, keyword):
     event = gtk.get_current_event()
     allow_similar = False
     if (event.state & gtk.gdk.CONTROL_MASK
             or event.state & gtk.gdk.MOD1_MASK):
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         self._action(action, keyword)
     togglebutton.props.active = False
Ejemplo n.º 7
0
 def _popup_menu_selected(self, menuitem, togglebutton, action, keyword):
     event = gtk.get_current_event()
     allow_similar = False
     if (event.state & gtk.gdk.CONTROL_MASK
             or event.state & gtk.gdk.MOD1_MASK):
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         self._action(action, keyword)
     togglebutton.props.active = False
Ejemplo n.º 8
0
 def popup_pan_menu(self, tv, event=None, *args):
     debug("popup_pan_menu (self, tv, *args):", 5)
     self.tv = tv
     if not event:
         event = gtk.get_current_event()
     t = (event and hasattr(event, 'time') and getattr(event, 'time') or 0)
     btn = (event and hasattr(event, 'button') and getattr(event, 'button')
            or 0)
     self.panpop.popup(None, None, None, btn, t)
     return True
Ejemplo n.º 9
0
 def _action_favorite(widget, id_):
     event = gtk.get_current_event()
     allow_similar = (event.state & gtk.gdk.MOD1_MASK
                      or event.state & gtk.gdk.SHIFT_MASK)
     with Window(allow_similar=allow_similar):
         # ids is not defined to prevent to add suffix
         Action.exec_keyword('tree_open', {
             'model': self.menu_screen.model_name,
             'id': id_,
         })
Ejemplo n.º 10
0
 def activate(menuitem, action, atype):
     rec = load(record)
     action = Action.evaluate(action, atype, rec)
     data = {"model": model, "id": rec.id, "ids": [rec.id]}
     event = gtk.get_current_event()
     allow_similar = False
     if event.state & gtk.gdk.CONTROL_MASK or event.state & gtk.gdk.MOD1_MASK:
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         Action._exec_action(action, data, {})
Ejemplo n.º 11
0
 def popup_pan_menu (self, tv, event=None, *args):
     debug("popup_pan_menu (self, tv, *args):",5)
     self.tv = tv
     if not event:
         event = gtk.get_current_event()
     t = (event and hasattr(event,'time') and getattr(event,'time')
             or 0)
     btn = (event and hasattr(event,'button') and getattr(event,'button')
            or 0)
     self.panpop.popup(None,None,None,btn,t)
     return True
Ejemplo n.º 12
0
 def __sig_switch(self, treeview, path, column):
     if column._type == 'button':
         return
     allow_similar = False
     event = gtk.get_current_event()
     if (event.state & gtk.gdk.MOD1_MASK
             or event.state & gtk.gdk.SHIFT_MASK):
         allow_similar = True
     with Window(allow_similar=allow_similar):
         if not self.screen.row_activate() and self.children_field:
             if treeview.row_expanded(path):
                 treeview.collapse_row(path)
             else:
                 treeview.expand_row(path, False)
Ejemplo n.º 13
0
 def __sig_switch(self, treeview, path, column):
     if column._type == 'button':
         return
     allow_similar = False
     event = gtk.get_current_event()
     if (event.state & gtk.gdk.MOD1_MASK
             or event.state & gtk.gdk.SHIFT_MASK):
         allow_similar = True
     with Window(allow_similar=allow_similar):
         if not self.screen.row_activate() and self.children_field:
             if treeview.row_expanded(path):
                 treeview.collapse_row(path)
             else:
                 treeview.expand_row(path, False)
Ejemplo n.º 14
0
  def icon_clicked(self, widget):
    event = gtk.get_current_event()

    #Dialog mode
    if self.client.get_int(group, 'mode') == 0:
      if self.dialog.flags() & gtk.VISIBLE:
        self.dialog.hide()

      else:
        self.dialog_config(event.button)

    #Docklet mode
    else:
      self.dialog_config(event.button)
Ejemplo n.º 15
0
 def activate(menuitem, action, atype):
     rec = load(record)
     action = Action.evaluate(action, atype, rec)
     data = {
         'model': model,
         'id': rec.id,
         'ids': [rec.id],
     }
     event = gtk.get_current_event()
     allow_similar = False
     if (event.state & gtk.gdk.CONTROL_MASK
             or event.state & gtk.gdk.MOD1_MASK):
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         Action._exec_action(action, data, rec.get_context())
Ejemplo n.º 16
0
 def on_click(self, obj, event=None):
     if not event:
         event = gtk.get_current_event()
     if event.button < 3:
         if not self.init:
             button = self.left
             if event.button == 2:
                 button = self.middle
             if button == 1:
                 self.popup_gtk_menu(self.gtk['umenu'], 0, event.time)
                 return True
             elif button < 3:
                 self.change_group(button - 1)
     else:
         self.popup_gtk_menu(self.cmenu, 0, event.time)
         return True
     return False
Ejemplo n.º 17
0
    def validate_and_next(self, new):
        """Validate the current annotation and display the next one.
        """
        i = self.index
        annotation = self.annotations[i]
        batch=object()

        event = gtk.get_current_event()
        if event.state & gtk.gdk.CONTROL_MASK:
            # Control-key is held. Split the annotation.
            if new > annotation.fragment.begin and new < annotation.fragment.end:
                self.controller.split_annotation(annotation, new)
                self.message(_("Split annotation #%(current)d into #%(current)d and #%(next)d") % {
                        'current': i + 1,
                        'next': i + 2
                        })
            else:
                self.message(_("Cannot split annotation #%(current)d: out of bounds.") % {
                        'current': i + 1,
                        })
            return True

        if new != annotation.fragment.begin:
            self.controller.notify('EditSessionStart', element=annotation, immediate=True)
            annotation.fragment.begin = new
            self.controller.notify('AnnotationEditEnd', annotation=annotation, batch=batch)
            self.controller.notify('EditSessionEnd', element=annotation)
            self.undo_button.set_sensitive(True)

        # Update previous annotation end.
        if i > 0:
            annotation = self.annotations[i - 1]
            if new != annotation.fragment.end:
                self.controller.notify('EditSessionStart', element=annotation, immediate=True)
                annotation.fragment.end = new
                self.controller.notify('AnnotationEditEnd', annotation=annotation, batch=batch)
                self.controller.notify('EditSessionEnd', element=annotation)
            self.message(_("Changed cut between #%(first)d and %(second)d") % { 'first': i + 1,
                                                                                  'second': i + 2 })
        else:
            self.message(_("Changed begin time for first annotation"))
        self.set_index(i + 1)
        return True
Ejemplo n.º 18
0
    def on_left_click(self, icon):
        event = gtk.get_current_event()

        volumes = self.monitor.get_volumes()
        pprint(volumes)

        popup = gtk.Menu()

        for volume in volumes:
            pprint(
                dict((i, volume.get_identifier(i))
                     for i in volume.enumerate_identifiers()))

            if self.is_internal(volume):
                continue

            menu = gtk.MenuItem(volume.get_name() + ' (' +
                                volume.get_drive().get_name() + ')')
            submenu = gtk.Menu()
            menu.set_submenu(submenu)
            popup.append(menu)

            # XXX: Show something if `not volume.can_mount`.
            if volume.get_mount() is None:
                submenu.append(self.mk_menu_item('Mount', self.mount, volume))
                submenu.append(
                    self.mk_menu_item('Mount and Open', self.mount_and_open,
                                      volume))

            else:
                submenu.append(
                    self.mk_menu_item('Open', self.open_volume, volume))
                submenu.append(
                    self.mk_menu_item('Unmount', self.unmount, volume))

        if len(popup) == 0:
            dummy_item = gtk.MenuItem('No volumes detected')
            dummy_item.set_sensitive(False)
            popup.add(dummy_item)

        popup.show_all()
        popup.popup(None, None, gtk.status_icon_position_menu, event.button,
                    event.time, icon)
Ejemplo n.º 19
0
 def action_keyword(self, ids):
     if not ids:
         return
     ctx = self.group.context.copy()
     if 'active_ids' in ctx:
         del ctx['active_ids']
     if 'active_id' in ctx:
         del ctx['active_id']
     event = gtk.get_current_event()
     allow_similar = False
     if (event.state & gtk.gdk.CONTROL_MASK
             or event.state & gtk.gdk.MOD1_MASK):
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         return Action.exec_keyword('graph_open', {
                 'model': self.model,
                 'id': ids[0],
                 'ids': ids,
                 }, context=ctx, warning=False)
Ejemplo n.º 20
0
 def action_keyword(self, ids):
     if not ids:
         return
     ctx = self.group._context.copy()
     if 'active_ids' in ctx:
         del ctx['active_ids']
     if 'active_id' in ctx:
         del ctx['active_id']
     event = gtk.get_current_event()
     allow_similar = False
     if (event.state & gtk.gdk.CONTROL_MASK
             or event.state & gtk.gdk.MOD1_MASK):
         allow_similar = True
     with Window(hide_current=True, allow_similar=allow_similar):
         return Action.exec_keyword('graph_open', {
                 'model': self.model,
                 'id': ids[0],
                 'ids': ids,
                 }, context=ctx, warning=False)
Ejemplo n.º 21
0
 def __show_main_menu(self, widget):
     global settings
     menu = gtk.Menu()
     menu_item = gtk.ImageMenuItem(gtk.STOCK_ADD)
     menu_item.connect("activate", self.__edit_file, os.path.join(settings.get_notes_dir(), "index.muse"))
     menu.append(menu_item)
     menu_item = gtk.SeparatorMenuItem()
     menu.append(menu_item)
     wiki_list.update_wiki_list()
     file_list = wiki_list.get_wiki_list()
     length = len(file_list)
     max_menu_item = settings.max_main_menu_item
     if length > max_menu_item:
         length = 10
     for fname in file_list[0:length]:
         wiki = MuseWiki(fname)
         item_label = wiki.get_title()
         menu_item = gtk.MenuItem(item_label)
         menu_item.connect("activate", self.__view_file, fname)
         menu.append(menu_item)
     if len(file_list) > max_menu_item:
         sub_menu = gtk.Menu()
         for fname in file_list[max_menu_item:len(file_list)]:
             wiki = MuseWiki(fname)
             item_label = wiki.get_title()
             menu_item = gtk.MenuItem(item_label)
             menu_item.connect("activate", self.__view_file, fname)
             sub_menu.append(menu_item)
         menu_item = gtk.MenuItem(u"更多笔记")
         menu_item.set_submenu(sub_menu)
         menu.append(menu_item)
     menu_item = gtk.SeparatorMenuItem()
     menu.append(menu_item)
     menu_item = gtk.ImageMenuItem(gtk.STOCK_QUIT)
     menu_item.connect("activate", self.__main_quit)
     menu.append(menu_item)
     menu.show_all()
     event = gtk.get_current_event()
     if event:
         menu.popup(None, None, gtk.status_icon_position_menu, 
                    event.button, event.time, widget)
Ejemplo n.º 22
0
    def on_left_click(self, icon):
        event = gtk.get_current_event()

        volumes = self.monitor.get_volumes()
        pprint(volumes)

        popup = gtk.Menu()

        for volume in volumes:
            pprint(dict((i, volume.get_identifier(i))
                for i in volume.enumerate_identifiers()))

            if self.is_internal(volume):
                continue

            menu = gtk.MenuItem(volume.get_name() +
                    ' (' + volume.get_drive().get_name() + ')')
            submenu = gtk.Menu()
            menu.set_submenu(submenu)
            popup.append(menu)

            # XXX: Show something if `not volume.can_mount`.
            if volume.get_mount() is None:
                submenu.append(self.mk_menu_item('Mount', self.mount, volume))
                submenu.append(self.mk_menu_item('Mount and Open',
                    self.mount_and_open, volume))

            else:
                submenu.append(
                        self.mk_menu_item('Open', self.open_volume, volume))
                submenu.append(
                        self.mk_menu_item('Unmount', self.unmount, volume))

        if len(popup) == 0:
            dummy_item = gtk.MenuItem('No volumes detected')
            dummy_item.set_sensitive(False)
            popup.add(dummy_item)

        popup.show_all()
        popup.popup(None, None, gtk.status_icon_position_menu, event.button,
                event.time, icon)
Ejemplo n.º 23
0
    def activate(self, text=None):
        if self._window.is_active():
            return
        
        try:
            time = gtk.get_current_event().time
        except:
            LOGGER.warning("Using bogus timestamp.")
            time = gtk.get_current_event_time()
        
        workspace = self._window.get_workspace()
        if workspace != None and workspace.is_virtual():
            if not self._window.is_in_viewport(workspace):
                pos_x = workspace.get_viewport_x() + self._window.get_geometry()[0]
                pos_y = workspace.get_viewport_y() + self._window.get_geometry()[1]
                self._window.get_screen().move_viewport(pos_x, pos_y)

        if hasattr(self._window.get_workspace(), 'activate') and self._window.get_workspace() != self._window.get_screen().get_active_workspace():
            self._window.get_workspace().activate(time)

        self._window.activate(time)    
Ejemplo n.º 24
0
	def _changed(self, editable):
		"""
		The entry changed callback: Here we have to be sure to use
		**UNICODE** (unicode()) for the entered text
		"""
		# @text is UTF-8
		text = editable.get_text()
		text = text.decode("UTF-8")
		if not text:
			self.data_controller.cancel_search()
			# See if it was a deleting key press
			curev = gtk.get_current_event()
			if curev and curev.keyval in (self.key_book["Delete"],
					self.key_book["BackSpace"]):
				self._back_key_press()
			return

		pane = self._pane_for_widget(self.current)
		if not self.get_in_text_mode() and self._reset_to_toplevel:
			self.soft_reset(pane)

		self.data_controller.search(pane, key=text, context=text,
				text_mode=self.get_in_text_mode())
Ejemplo n.º 25
0
    def _force_drag_start(self):
        # Attempt to force a drag to start, using the current event.

        # XXX: This is only used by the picker mode, which needs to begin
        # picking straight away in enter even if this is in response to an
        # action activation.
        event = gtk.get_current_event()
        if event is None:
            logger.warning("no event")
            return
        if self.in_drag:
            return
        tdw = self.doc.tdw
        # Duck-profile the starting event. If it's a keypress event or a
        # button-press event, or anything that quacks like those, we can
        # attempt the grab and start the drag if it succeeded.
        if hasattr(event, "keyval"):
            if event.keyval != self._start_keyval:
                self._start_keyval = event.keyval
                self._start_drag(tdw, event)
        elif (hasattr(event, "x") and hasattr(event, "y")
              and hasattr(event, "button")):
            self._start_drag(tdw, event)
            if self.in_drag:
                # Grab succeeded
                self.last_x = event.x
                self.last_y = event.y
                # For the toolbar button, and for menus, it's a button-release
                # event.
                # Record which button is being pressed at start
                if isinstance(event.button, int):
                    # PyGTK supplies the actual button number ...
                    self._start_button = event.button
                else:
                    # ... but GI+GTK3 supplies a <void at 0xNNNNNNNN> object
                    # when the event comes from gtk.get_current_event() :(
                    self._start_button = None
Ejemplo n.º 26
0
Archivo: mode.py Proyecto: j-fu/mypaint
    def _force_drag_start(self):
        # Attempt to force a drag to start, using the current event.

        # XXX: This is only used by the picker mode, which needs to begin
        # picking straight away in enter even if this is in response to an
        # action activation.
        event = gtk.get_current_event()
        if event is None:
            logger.warning("no event")
            return
        if self.in_drag:
            return
        tdw = self.doc.tdw
        # Duck-profile the starting event. If it's a keypress event or a
        # button-press event, or anything that quacks like those, we can
        # attempt the grab and start the drag if it succeeded.
        if hasattr(event, "keyval"):
            if event.keyval != self._start_keyval:
                self._start_keyval = event.keyval
                self._start_drag(tdw, event)
        elif (hasattr(event, "x") and hasattr(event, "y")
              and hasattr(event, "button")):
            self._start_drag(tdw, event)
            if self.in_drag:
                # Grab succeeded
                self.last_x = event.x
                self.last_y = event.y
                # For the toolbar button, and for menus, it's a button-release
                # event.
                # Record which button is being pressed at start
                if isinstance(event.button, int):
                    # PyGTK supplies the actual button number ...
                    self._start_button = event.button
                else:
                    # ... but GI+GTK3 supplies a <void at 0xNNNNNNNN> object
                    # when the event comes from gtk.get_current_event() :(
                    self._start_button = None
Ejemplo n.º 27
0
def begin_resize(*args):
    event = gtk.get_current_event()
    window.begin_resize_drag(gtk.gdk.WINDOW_EDGE_SOUTH,
                             event.button,
                             int(round(0.5 + event.x_root)), int(round(event.y_root)),
                             event.time)
Ejemplo n.º 28
0
    def __init__(self, obj, name, args):
        SignalEvent.__init__(self, obj, name, args)

        ev = gtk.get_current_event()
        self.x = ev.x
        self.y = ev.y
Ejemplo n.º 29
0
    def __init__(self, obj, name, args):
        SignalEvent.__init__(self, obj, name, args)

        ev = gtk.get_current_event()
        self.x = ev.x
        self.y = ev.y