def change_s_dialog_key(self, gconfclient=None, gconfentry=None, gconfvalue=None, d=None): try: keybinder.unbind(self.prev_sel_dialog_key) except: pass keybinder.bind(prefs.get_sel_dialog_key(), lambda: self.s_dialog.show()) self.prev_sel_dialog_key = prefs.get_sel_dialog_key()
def __init__(self): # try to load custom icon from user's config dir if os.path.isfile(ClipboardProtector.PASTIE_ICON) == True: self.indicator = appindicator.Indicator("pastie", "pastie", appindicator.CATEGORY_APPLICATION_STATUS, ClipboardProtector.PASTIE_CONFIG_DIR) else: self.indicator = appindicator.Indicator("pastie", "gtk-paste", appindicator.CATEGORY_APPLICATION_STATUS) # set the indicator as active (pastie must be always shown) self.indicator.set_status(appindicator.STATUS_ACTIVE) # get the clipboard gdk atom self.clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) self.primary = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY) # we use this to check if clipboard contents changed on special cases self.specials_text = "" self.primary_text = "" # create the history data strucure self.history = history.HistoryMenuItemCollector() # the menu will be updated when the "item-lenght-adjusted" signal in the history object is emitted self.history.connect("length-adjusted", self.update_menu) # ... and when data changes self.history.connect("data-change", self.update_menu) # load history if existent self.history.set_payload(self.recover_history()) # pastie might have been loaded after some contents were added to the X clipboard. # we check if ther's any. self.check() # select the first item in the history. if len(self.history) > 0: self.history[0].set_as_current() # set the gconf_client self.gconf_client = prefs.PrefsGConfClient() # register gconf preferences changes callback functions self.gconf_client.notify_add('show_quit_on_menu', self.update_menu) self.gconf_client.notify_add('show_preferences_on_menu', self.update_menu) self.gconf_client.notify_add('item_length', self.update_menu) self.gconf_client.notify_add('history_size', self.history.adjust_maxlen) self.gconf_client.notify_add('use_primary', self.toggle_primary) self.gconf_client.notify_add('sel_dialog_key', self.change_s_dialog_key) self.gconf_client.notify_add('prefs_dialog_key', self.change_prefs_dialog_key) # check clipboard changes on owner-change event self.clipboard.connect("owner-change", self.check) self.toggle_primary() # run an auxiloary loop for special cases (e.g., gvim) gobject.timeout_add(500, self.check_specials) # create the selection dialog and set the keyboard shortcut for it self.s_dialog = seldiag.SelectionDialog(self) self.prev_sel_dialog_key = prefs.get_sel_dialog_key() self.change_s_dialog_key() # set the preferences dialog's keyboard shortcut self.prev_prefs_dialog_key = prefs.get_prefs_dialog_key() self.change_prefs_dialog_key()
def __init__(self): # try to load custom icon from ~/.pastie/ pastieDir = os.path.join(os.path.expanduser('~'), '.pastie/') pastieIcon = os.path.expanduser('~/.pastie/pastie.svg') if os.path.isfile(pastieIcon) == True: self.indicator = appindicator.Indicator( "pastie", "pastie", appindicator.CATEGORY_OTHER, pastieDir) else: self.indicator = appindicator.Indicator( "pastie", "gtk-paste", appindicator.CATEGORY_OTHER) # set the indicator as active (pastie must be always shown) self.indicator.set_status(appindicator.STATUS_ACTIVE) # get the clipboard gdk atom self.clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD) self.primary = gtk.clipboard_get(gtk.gdk.SELECTION_PRIMARY) # we use this to check if clipboard contents changed on special cases self.specials_text = "" self.primary_text = "" # create the history data strucure self.history = history.HistoryMenuItemCollector() # the menu will be updated when the "item-lenght-adjusted" signal in the history object is emitted self.history.connect("length-adjusted", self.update_menu) # ... and when data changes self.history.connect("data-change", self.update_menu) # load history if existent self.history.set_payload(self.recover_history()) # pastie might have been loaded after some contents were added to the X clipboard. # we check if ther's any. self.check() # select the first item in the history. if len(self.history) > 0: self.history[0].set_as_current() # set the gconf_client self.gconf_client = prefs.PrefsGConfClient() # register gconf preferences changes callback functions self.gconf_client.notify_add('show_quit_on_menu', self.update_menu) self.gconf_client.notify_add('show_preferences_on_menu', self.update_menu) self.gconf_client.notify_add('item_length', self.update_menu) self.gconf_client.notify_add('history_size', self.history.adjust_maxlen) self.gconf_client.notify_add('use_primary', self.toggle_primary) self.gconf_client.notify_add('sel_dialog_key', self.change_s_dialog_key) self.gconf_client.notify_add('prefs_dialog_key', self.change_prefs_dialog_key) # check clipboard changes on owner-change event self.clipboard.connect("owner-change", self.check) self.toggle_primary() # run an auxiloary loop for special cases (e.g., gvim) gobject.timeout_add(500, self.check_specials) # create the selection dialog and set the keyboard shortcut for it self.s_dialog = seldiag.SelectionDialog(self) self.prev_sel_dialog_key = prefs.get_sel_dialog_key() self.change_s_dialog_key() # set the preferences dialog's keyboard shortcut self.prev_prefs_dialog_key = prefs.get_prefs_dialog_key() self.change_prefs_dialog_key()