Beispiel #1
0
 def on_copy_all(self, treeview):
     """
     Copy tree to clipboard.
     """
     model = treeview.get_model()
     text = model_to_text(model, [0, 1], level=1)
     text_to_clipboard(text)
Beispiel #2
0
 def button_press_event(self, treeview, event):
     index = None
     button_code = None
     event_time = None
     func = None
     if type(event) == bool:  # enter
         button_code = 3
         event_time = 0
         selection = treeview.get_selection()
         store, paths = selection.get_selected_rows()
         tpath = paths[0] if len(paths) > 0 else None
         node = store.get_iter(tpath) if tpath else None
         if node:
             treeview.grab_focus()
             index = store.get_value(node, 0)
             # FIXME: make popup come where cursor is
             #rectangle = treeview.get_visible_rect()
             #column = treeview.get_column(0)
             #rectangle = treeview.get_cell_area("0:0",
             #x, y = rectangle.x, rectangle.y
             #func = lambda menu: (x, y, True)
     elif event.button == 3:
         button_code = 3
         event_time = event.time
         x = int(event.x)
         y = int(event.y)
         path_info = treeview.get_path_at_pos(x, y)
         func = None
         if path_info is not None:
             path, col, cellx, celly = path_info
             selection = treeview.get_selection()
             store, paths = selection.get_selected_rows()
             tpath = paths[0] if len(paths) > 0 else None
             node = store.get_iter(tpath) if tpath else None
             if path:
                 treeview.grab_focus()
                 treeview.set_cursor(path, col, 0)
             if store and node:
                 index = store.get_value(node, 0)  # index Below,
     # you need index, treeview, path, button_code,
     # func, and event_time
     if index is not None:
         self.popup = Gtk.Menu()
         popup = self.popup
         menu_item = Gtk.MenuItem(label=_("Copy all"))
         menu_item.connect(
             "activate", lambda widget: text_to_clipboard(
                 model_to_text(treeview.get_model())))
         popup.append(menu_item)
         menu_item.show()
         # Now add more items to popup menu, if available
         if (index is not None and self._link[index]):
             # See details (edit, etc):
             objclass, handle = self._link[index]
             menu_item = Gtk.MenuItem(label=_("the object|See %s details") %
                                      glocale.trans_objclass(objclass))
             menu_item.connect(
                 "activate",
                 lambda widget: self.on_table_doubleclick(treeview))
             popup.append(menu_item)
             menu_item.show()
         # Add other items to menu:
         if (self._callback_leftclick
                 or (index is not None and self._link[index])):
             objclass, handle = self._link[index]
             if objclass == 'Person':
                 menu_item = Gtk.MenuItem(
                     label=_("the object|Make %s active") %
                     glocale.trans_objclass('Person'))
                 menu_item.connect(
                     "activate",
                     lambda widget: self.on_table_click(treeview))
                 popup.append(menu_item)
                 menu_item.show()
         if (self.simpledoc.doc.dbstate.db !=
                 self.simpledoc.doc.dbstate.db.basedb
                 and (index is not None and self._link[index])):
             objclass, handle = self._link[index]
             if (objclass == 'Filter' and handle[0] in [
                     'Person', 'Family', 'Place', 'Event', 'Repository',
                     'Note', 'Media', 'Citation', 'Source'
             ]):
                 menu_item = Gtk.MenuItem(label=_("See data not in Filter"))
                 menu_item.connect(
                     "activate",
                     lambda widget: self.show_not_in_filter(handle[0]))
                 popup.append(menu_item)
                 menu_item.show()
         # Show the popup menu:
         popup.popup(None, None, func, None, button_code, event_time)
         return True
     return False
Beispiel #3
0
 def button_press_event(self, treeview, event):
     index = None
     button_code = None
     event_time = None
     func = None
     if type(event) == bool: # enter
         button_code = 3
         event_time = 0
         selection = treeview.get_selection()
         store, paths = selection.get_selected_rows()
         tpath = paths[0] if len(paths) > 0 else None
         node = store.get_iter(tpath) if tpath else None
         if node:
             treeview.grab_focus()
             index = store.get_value(node, 0)
             # FIXME: make popup come where cursor is
             #rectangle = treeview.get_visible_rect()
             #column = treeview.get_column(0)
             #rectangle = treeview.get_cell_area("0:0",
             #x, y = rectangle.x, rectangle.y
             #func = lambda menu: (x, y, True)
     elif event.button == 3:
         button_code = 3
         event_time = event.time
         x = int(event.x)
         y = int(event.y)
         path_info = treeview.get_path_at_pos(x, y)
         func = None
         if path_info is not None:
             path, col, cellx, celly = path_info
             selection = treeview.get_selection()
             store, paths = selection.get_selected_rows()
             tpath = paths[0] if len(paths) > 0 else None
             node = store.get_iter(tpath) if tpath else None
             if path:
                 treeview.grab_focus()
                 treeview.set_cursor(path, col, 0)
             if store and node:
                 index = store.get_value(node, 0) # index Below,
     # you need index, treeview, path, button_code,
     # func, and event_time
     if index is not None:
         self.popup = Gtk.Menu()
         popup = self.popup
         menu_item = Gtk.MenuItem(label=_("Copy all"))
         menu_item.connect("activate", lambda widget: text_to_clipboard(model_to_text(treeview.get_model())))
         popup.append(menu_item)
         menu_item.show()
         # Now add more items to popup menu, if available
         if (index is not None and self._link[index]):
         # See details (edit, etc):
             objclass, handle = self._link[index]
             menu_item = Gtk.MenuItem(label=_("the object|See %s details") % glocale.trans_objclass(objclass))
             menu_item.connect("activate",
               lambda widget: self.on_table_doubleclick(treeview))
             popup.append(menu_item)
             menu_item.show()
         # Add other items to menu:
         if (self._callback_leftclick or
             (index is not None and self._link[index])):
             objclass, handle = self._link[index]
             if objclass == 'Person':
                 menu_item = Gtk.MenuItem(label=_("the object|Make %s active") % glocale.trans_objclass('Person'))
                 menu_item.connect("activate",
                   lambda widget: self.on_table_click(treeview))
                 popup.append(menu_item)
                 menu_item.show()
         if (self.simpledoc.doc.dbstate.db !=
             self.simpledoc.doc.dbstate.db.basedb and
             (index is not None and self._link[index])):
             objclass, handle = self._link[index]
             if (objclass == 'Filter' and
                 handle[0] in ['Person', 'Family', 'Place', 'Event',
                               'Repository', 'Note', 'MediaObject',
                               'Citation', 'Source']):
                 menu_item = Gtk.MenuItem(label=_("See data not in Filter"))
                 menu_item.connect("activate",
                   lambda widget: self.show_not_in_filter(handle[0]))
                 popup.append(menu_item)
                 menu_item.show()
         # Show the popup menu:
         popup.popup(None, None, func, None, button_code, event_time)
         return True
     return False