def create_entry_widget(cls, title, km): if km: item = cls(None, True) box = gtk.HBox(False, 20) label = gtk.Label(title) label.set_alignment(0, 0.5) label.set_use_underline(True) box.pack_start(label) full_accel_str = ', '.join(gtk.accelerator_get_label(*r[0]) for r in km) if len(km) > 1: accel_label = gtk.Label(gtk.accelerator_get_label(*km[0][0]) + '>') accel_label.set_tooltip_text(full_accel_str) else: accel_label = gtk.Label(full_accel_str) accel_label.set_alignment(1, 0.5) accel_label.modify_fg(gtk.STATE_NORMAL, accel_label.style.fg[gtk.STATE_INSENSITIVE]) accel_label.modify_fg(gtk.STATE_PRELIGHT, accel_label.style.fg[gtk.STATE_INSENSITIVE]) box.pack_start(accel_label) item.add(box) else: item = cls(title, True) return item
def _show_keybindings(self, setctl): names = self.KEYBINDING_NAMES self.keybind_store.clear() for binding in sorted(names, key=lambda k: names[k]): accel = setctl.get_global_keybinding(binding) label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel)) self.keybind_store.append((names[binding], label, binding))
def _show_gkeybindings(self, setctl): names = accelerators.ACCELERATOR_NAMES self.gkeybind_store.clear() for binding in sorted(names, key=lambda k: names[k]): accel = setctl.get_accelerator(binding) or "" label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel)) self.gkeybind_store.append((names[binding], label, binding))
def _show_keybindings(self, setctl): names = self.KEYBINDING_NAMES self.keybind_store.clear() for binding in sorted(names, key=lambda k: names[k]): accel = setctl.get_global_keybinding(binding) or "" label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel)) self.keybind_store.append((names[binding], label, binding))
def _show_gkeybindings(self, setctl): names = self.ACCELERATOR_NAMES self.gkeybind_store.clear() for binding in sorted(names, key=lambda k: names[k]): accel = setctl.get_accelerator(binding) label = gtk.accelerator_get_label(*gtk.accelerator_parse(accel)) self.gkeybind_store.append((names[binding], label, binding))
def refresh_accel(self): """ Refreshes the accelerator """ if not shortcut.is_gsettings_present(): self.button.set_sensitive(False) iter1 = self.liststore.get_iter_first() self.liststore.set_value(iter1, 1, "Disabled") self.cell.set_sensitive(False) if not self.gsettings_install_label_shown: self._show_gsettings_install_label() self.gsettings_install_label_shown = True return iter1 = self.liststore.get_iter_first() self.new_task_binding = shortcut.get_saved_binding() self.binding_backup = self.new_task_binding if self.new_task_binding == "": # User had set a shortcut, but has now disabled it self.button.set_active(False) self.liststore.set_value(iter1, 1, "Disabled") return elif self.new_task_binding is None: # User hasn't set a shortcut ever self.button.set_active(False) self.new_task_binding = self.new_task_default_binding self.binding_backup = self.new_task_binding else: # There exists a shortcut self.button.set_active(True) (accel_key, accel_mods) = gtk.accelerator_parse(self.new_task_binding) self.show_input = gtk.accelerator_get_label(accel_key, accel_mods) self.liststore.set_value(iter1, 1, self.show_input)
def _is_good_keystr(self, keystr): # Reject single letters so you can't bind 'A' etc if keystr is None: return label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr)) ulabel = kupferstring.tounicode(label) return not (len(ulabel) == 1 and ulabel.isalnum())
def _create_accelerators(self, primary=True): """Create accelerators from specified list""" accelerator_list = (self._secondary, self._primary)[primary] # connect all methods in list for method_name in self._methods.keys(): if method_name in self._disabled: continue # skip if method is disabled # try to get saved key combination from manager accelerator = self._manager.get_accelerator( self._name, method_name, primary) # if we don't have saved key combination, use default if accelerator is None and method_name in accelerator_list: accelerator = accelerator_list[method_name] # finally connect accelerator to specified method if accelerator is not None and accelerator[0] > 0: keyval = accelerator[0] modifier = accelerator[1] # create method name cache based on key combination label = gtk.accelerator_get_label(keyval, modifier) self._method_names[label] = method_name # connect accelerator self._accel_group.connect_group(keyval, modifier, 0, self._handle_activate)
def on_key_edited(self, renderer, path, keycode, mask, keyval, model): """Callback that handles key edition in cellrenderer. It makes some tests to validate the key, like looking for already in use keys and look for [A-Z][a-z][0-9] to avoid problems with these common keys. If all tests are ok, the value will be stored in gconf. """ giter = model.get_iter(path) gconf_path = model.get_value(giter, 0) oldkey = model.get_value(giter, 2) hotkey = KeyEntry(keycode, mask) key = gtk.accelerator_name(keycode, mask) keylabel = gtk.accelerator_get_label(keycode, mask) # we needn't to change anything, the user is trying to set the # same key that is already set. if oldkey == hotkey: return False # looking for already used keybindings def each_key(model, path, subiter): keyentry = model.get_value(subiter, 2) if keyentry and keyentry == hotkey: msg = _('The shortcut "%s" is already in use.') % keylabel raise ShowableError(_("Error setting keybinding."), msg, -1) model.foreach(each_key) # avoiding problems with common keys if (mask == 0 and keycode != 0) and ( (keycode >= ord("a") and keycode <= ord("z")) or (keycode >= ord("A") and keycode <= ord("Z")) or (keycode >= ord("0") and keycode <= ord("9")) ): dialog = gtk.MessageDialog( self.get_widget("config-window"), gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _( 'The shortcut "%s" cannot be used ' "because it will become impossible to " "type using this key.\n\n" "Please try with a key such as " "Control, Alt or Shift at the same " "time.\n" ) % key, ) dialog.run() dialog.destroy() return False # setting new value in ui giter = model.get_iter(path) model.set_value(giter, 2, hotkey) # setting the new value in gconf self.client.set_string(gconf_path, key)
def _catch_keypress(self, event, label): # Capture Hotkeys # tab_content = TabView() keyval = label.keyval name = gtk.gdk.keyval_name(keyval) mod = gtk.accelerator_get_label(keyval, label.state) if str(Config.get("default","go_back")) == str(mod): self._go_back_key() if str(Config.get("default", "go_fwd")) == str(mod): self._go_fwd_key() if str(Config.get("default", "go_new_tab")) == str(mod): self._go_new_tab_key() if str(Config.get("default", "go_home")) == str(mod): self._go_home_key() if str(Config.get("default", "go_search")) == str(mod): self._go_search_key() if str(Config.get("default", "zoom_in")) == str(mod): self._zoom_in_key() if str(Config.get("default", "zoom_out")) == str(mod): self._zoom_out_key() if str(Config.get("default", "exit_k")) == str(mod): self._exit_k() if str(Config.get("default", "bookmarks")) == str(mod): self._go_bookmarks_key() print "keys for Bookmark page pressed"
def _create_accelerators(self, primary=True): """Create accelerators from specified list""" list_ = (self._secondary, self._primary)[primary] # connect all methods in list for method_name in self._methods.keys(): if method_name in self._disabled: continue # skip if method is disabled # try to get saved key combination from manager accelerator = self._manager.get_accelerator(self._name, method_name, primary) # if we don't have saved key combination, use default if accelerator is None and list_.has_key(method_name): accelerator = list_[method_name] # finally connect accelerator to specified method if accelerator is not None: keyval = accelerator[0] modifier = accelerator[1] # create method name cache based on key combination label = gtk.accelerator_get_label(keyval, modifier) self._method_names[label] = method_name # connect accelerator self._accel_group.connect_group(keyval, modifier, 0, self._handle_activate)
def activate(self, leaf): text = leaf.object keys, orig_mods = gtk.accelerator_parse(text) m = { gtk.gdk.SHIFT_MASK: "Shift_L", gtk.gdk.CONTROL_MASK: "Control_L", gtk.gdk.SUPER_MASK: "Super_L", gtk.gdk.MOD1_MASK: "Alt_L", } mod_names = [] mods = orig_mods for mod in m: if mod & mods: mod_names.append(m[mod]) mods &= ~mod if mods != 0: raise OperationError(_("Keys not yet implemented: %s") % gtk.accelerator_get_label(keys, orig_mods)) key_arg = 'key %s' % (gtk.gdk.keyval_name(keys), ) mods_down = ['keydown ' + n for n in mod_names] mods_up = ['keyup ' + n for n in reversed(mod_names)] xte_paste_argv = ['xte', 'usleep 300000'] + \ mods_down + [key_arg] + mods_up if not utils.spawn_async(xte_paste_argv): raise CommandMissingError('xte')
def reload_global(self, client, connection_id, entry, data): """Unbind all global hotkeys and rebind the show_hide method. If more global hotkeys should be added, just connect the gconf key to the watch system and add. """ gkey = entry.get_key() key = entry.get_value().get_string() if key == 'disabled': return try: self.guake.hotkeys.unbind(self.globalhotkeys[gkey]) except KeyError: pass self.globalhotkeys[gkey] = key if not self.guake.hotkeys.bind(key, self.guake.show_hide): keyval, mask = gtk.accelerator_parse(key) label = gtk.accelerator_get_label(keyval, mask) filename = pixmapfile('guake-notification.png') guake.notifier.show_message( _('Guake Terminal'), _('A problem happened when binding <b>%s</b> key.\n' 'Please use Guake Preferences dialog to choose another ' 'key') % xml_escape(label), filename)
def on_key(self, widget, event): self.keys = event.keyval, event.state if not gtk.accelerator_valid(event.keyval, event.state): self.__label.set_markup( "<b>%s</b> - invalid accelerator!" % gtk.accelerator_get_label(event.keyval, event.state)) return action = self.accel_is_used(event.keyval, event.state) if action: self.__label.set_markup( "<b>%s</b> - accelerator used by action:\n \"%s\"!" % (gtk.accelerator_get_label(event.keyval, event.state), action)) return self.__dialog.response(gtk.RESPONSE_APPLY)
def activate_callback_term(self, widget, keyval, input, window): global Command combination = gtk.accelerator_get_label(keyval.keyval,keyval.state) if combination == "Ctrl+Mod2+Return" or combination == "Ctrl+Return": Command = 'x-terminal-emulator -T "Run" -e bash -c "' + input.get_text() + ' && syswait "' window.hide() gtk.main_quit() return
def get_accel_label(self): ''' converts the accelerator keyval and modifier mask into a string @return: a accelerator string ''' if self.state is None or self.keyval is None: return '' return accelerator_get_label(self.keyval, self.state)
def _on_button_properties_clicked(self, widget): self.popdown() self.enable_completion.set_active(self.get_auto_complete_enabled()) # Set the value of the label to the current accelerator keyval, mask = gtk.accelerator_parse(self.auto_completer.accelerator_string) self.accelerator_label.set_text(gtk.accelerator_get_label(keyval, mask)) self.visible_rows.set_value(self.get_max_pop_down_rows()) self.config_dialog.show_all()
def getAccelerator(self, widget): action = widget.get_action() if action: accelPath = action.get_accel_path() if accelPath: keyVal, modifier = gtk.accel_map_lookup_entry(accelPath) if keyVal: return gtk.accelerator_get_label(keyVal, modifier) return ""
def check_modifier(mod): """Dont allow weird modifiers""" _unallowed_modifier = ('Super', 'Hyper', 'Meta') if mod: labels = gtk.accelerator_get_label(0, mod) mod_list = labels.replace('+', ' ').split() for m in mod_list: if m in _unallowed_modifier: return False return True
def check_modifier(mod): """Dont allow weird modifiers""" _unallowed_modifier = ("Super", "Hyper", "Meta") if mod: labels = gtk.accelerator_get_label(0, mod) mod_list = labels.replace("+", " ").split() for m in mod_list: if m in _unallowed_modifier: return False return True
def try_bind_key(keystr): label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr)) ulabel = kupferstring.tounicode(label) if len(ulabel) == 1 and ulabel.isalnum(): return False target = keybindings.KEYRANGE_TRIGGERS[-1] - 1 succ = keybindings.bind_key(keystr, target) if succ: keybindings.bind_key(None, target) return succ
def _cellAccelEdit(self, cell, path, accel_key, accel_mods, code, model): """ Accelerator is modified """ self.show_input = gtk.accelerator_get_label(accel_key, accel_mods) self.new_task_binding = gtk.accelerator_name(accel_key, accel_mods) if check_invalidity(self.new_task_binding, accel_key, accel_mods): self._show_warning(gtk.Button(_("Warning")), self.show_input) return self.binding_backup = self.new_task_binding iter = model.get_iter(path) model.set_value(iter, 1, self.show_input) save_new_binding(self.new_task_binding, self.button.get_active())
def button_press_displayname(button, mods): """Converts a button number & modifier mask to a localized unicode string. """ button = int(button) mods = int(mods) if button <= 0: return None mods = gdk.ModifierType(mods) modif_label = gtk.accelerator_get_label(0, mods) #TRANSLATORS: abbreviated "Button <number>" for forms like "Ctrl+Alt+Btn1" return unicode(modif_label) + (_(u"Btn%d") % (button,))
def on_gkeybindings_row_activate(self, treeview, path, view_column): it = self.gkeybind_store.get_iter(path) keybind_id = self.gkeybind_store.get_value(it, 2) setctl = settings.GetSettingsController() curr_key = setctl.get_accelerator(keybind_id) keystr = getkey_dialog.ask_for_key(self._is_good_keystr, previous_key=curr_key) if keystr is not None: setctl.set_accelerator(keybind_id, keystr) label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr)) self.gkeybind_store.set_value(it, 1, label)
def button_press_displayname(button, mods): """Converts a button number & modifier mask to a localized unicode string. """ button = int(button) mods = int(mods) if button <= 0: return None mods = gdk.ModifierType(mods) modif_label = gtk.accelerator_get_label(0, mods) #TRANSLATORS: abbreviated "Button <number>" for forms like "Ctrl+Alt+Btn1" return unicode(modif_label) + (_(u"Btn%d") % (button, ))
def on_key_edited(self, renderer, path, keycode, mask, keyval, model): """Callback that handles key edition in cellrenderer. It makes some tests to validate the key, like looking for already in use keys and look for [A-Z][a-z][0-9] to avoid problems with these common keys. If all tests are ok, the value will be stored in gconf. """ giter = model.get_iter(path) gconf_path = model.get_value(giter, 0) oldkey = model.get_value(giter, 2) hotkey = KeyEntry(keycode, mask) key = gtk.accelerator_name(keycode, mask) keylabel = gtk.accelerator_get_label(keycode, mask) # we needn't to change anything, the user is trying to set the # same key that is already set. if oldkey == hotkey: return False # looking for already used keybindings def each_key(model, path, subiter): keyentry = model.get_value(subiter, 2) if keyentry and keyentry == hotkey: msg = _("The shortcut \"%s\" is already in use.") % keylabel raise ShowableError(_('Error setting keybinding.'), msg, -1) model.foreach(each_key) # avoiding problems with common keys if ((mask == 0 and keycode != 0) and ((keycode >= ord('a') and keycode <= ord('z')) or (keycode >= ord('A') and keycode <= ord('Z')) or (keycode >= ord('0') and keycode <= ord('9')))): dialog = gtk.MessageDialog( self.get_widget('config-window'), gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, _("The shortcut \"%s\" cannot be used " "because it will become impossible to " "type using this key.\n\n" "Please try with a key such as " "Control, Alt or Shift at the same " "time.\n") % key) dialog.run() dialog.destroy() return False # setting new value in ui giter = model.get_iter(path) model.set_value(giter, 2, hotkey) # setting the new value in gconf self.client.set_string(gconf_path, key)
def on_gkeybindings_row_activate(self, treeview, path, view_column): it = self.gkeybind_store.get_iter(path) keybind_id = self.gkeybind_store.get_value(it, 2) setctl = settings.GetSettingsController() curr_key = setctl.get_accelerator(keybind_id) keystr = getkey_dialog.ask_for_key(self._is_good_keystr, previous_key=curr_key, screen=treeview.get_screen()) if keystr is not None: setctl.set_accelerator(keybind_id, keystr) label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr)) self.gkeybind_store.set_value(it, 1, label)
def trigger_accelerator(self, keyval, modifier): """Manually trigger accelerator""" result = False modifier = modifier & gtk.accelerator_get_default_mod_mask() # filter out unneeded mods label = gtk.accelerator_get_label(keyval, modifier) # trigger accelerator only if we have method connected if self._method_names.has_key(label): result = self._handle_activate(self._accel_group, self._window, keyval, modifier) return result
def __accel_edited(self, widget, path, keyval, modifier, hwcode, primary): """Handle editing accelerator""" selected_iter = self._accels.get_iter(path) accelerator_label = gtk.accelerator_get_label(keyval, modifier) # check if new accelerator has collisions accelerator_manager = self._application.accelerator_manager collisions = accelerator_manager.check_collisions(keyval, modifier, GroupType.ALL_GROUPS) if len(collisions) > 0: # ask user what to do with collisions method_list = [] for group, method_name, colliding_primary in collisions: method_list.append(group.get_method_title(method_name)) methods = '\n'.join([method_name for method_name in method_list]) # show dialog dialog = gtk.MessageDialog( self._parent, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, _( 'Selected accelerator "{0}" is already being ' 'used. Would you still like to assign accelerator ' 'to this function? This will reset listed ' 'functions.\n\n' 'Collisions:\n' '{1}' ).format(accelerator_label, methods) ) dialog.set_default_response(gtk.RESPONSE_NO) result = dialog.run() dialog.destroy() if result == gtk.RESPONSE_YES: # reset other accelerators for group, method_name, colliding_primary in collisions: colliding_iter = self.__find_iter_by_method_name( group.get_name(), method_name ) if colliding_iter is not None: self.__change_accelerator(colliding_iter, 0, 0, colliding_primary) # save new accelerator self.__change_accelerator(selected_iter, keyval, modifier, primary) else: # no collisions detected self.__change_accelerator(selected_iter, keyval, modifier, primary)
def on_completion_config_dialog_key_release_event(widget, event): # We are listening for a new key if set_key_button.get_active(): state = event.state & gtk.accelerator_get_default_mod_mask() accelerator_mask = state.numerator # If e.g. only CTRL key is pressed. if not gtk.accelerator_valid(event.keyval, accelerator_mask): accelerator_mask = 0 self.auto_completer.accelerator_string = gtk.accelerator_name(event.keyval, accelerator_mask) self.accelerator_label.set_text(gtk.accelerator_get_label(event.keyval, accelerator_mask)) # Reset widgets set_key_button.set_active(False) set_widgets_sensitive(True)
def on_key(self, widget, event): self.keys = event.keyval, event.state if not gtk.accelerator_valid(event.keyval, event.state): self.__label.set_markup("<b>%s</b> - invalid accelerator!"%gtk.accelerator_get_label(event.keyval, event.state)) return action = self.accel_is_used(event.keyval, event.state) if action: self.__label.set_markup("<b>%s</b> - accelerator used by action:\n \"%s\"!"%(gtk.accelerator_get_label(event.keyval, event.state), action)) return self.__dialog.response(gtk.RESPONSE_APPLY)
def change_toggle(self, window, event): if self.modify_toggle != None: entry, toggle = self.modify_toggle keyval = event.keyval state = event.state keycombo = gtk.accelerator_get_label(keyval, state) new_toggle = gtk.accelerator_name(keyval, state) if not self._hotkeys[toggle] == new_toggle: self._hotkeys[toggle] = new_toggle entry.set_text(keycombo) self.save_conf()
def checkbox_toggle(self, checkbox, toggle, label, entry): if checkbox.get_active(): label.set_sensitive(True) entry.set_sensitive(True) self._hotkeys[toggle] = self._defaults[toggle] keyval, state = gtk.accelerator_parse(self._hotkeys[toggle]) keycombo = gtk.accelerator_get_label(keyval, state) entry.set_text(keycombo) self.save_conf() else: label.set_sensitive(False) entry.set_sensitive(False) self._hotkeys[toggle] = "DISABLED" self.save_conf()
def trigger_accelerator(self, keyval, modifier): """Manually trigger accelerator""" result = False modifier = modifier & gtk.accelerator_get_default_mod_mask( ) # filter out unneeded mods label = gtk.accelerator_get_label(keyval, modifier) # trigger accelerator only if we have method connected if label in self._method_names: result = self._handle_activate(self._accel_group, self._window, keyval, modifier) return result
def main_keypress(self, widget, event): keyval = event.keyval name = gtk.gdk.keyval_name(keyval) mod = gtk.accelerator_get_label(keyval, event.state) mod = mod.replace("+Mod2","") #print mod, name, keyval if mod == "Ctrl+O": self.xmms2_open_files() elif mod == "Ctrl+P": self.xmms2_open_directory() elif mod == "Ctrl+L": self.xmms2_clear() elif mod == "Ctrl+I": self.xmms.playback_current_id(self.handler_playback_current_id) elif mod == "Ctrl+J": if not self.insearch.get_visible(): self.insearch.set_visible(True) self.insearch.grab_focus() else: if len(self.insearch.get_text()) == 0: self.insearch.set_visible(False) else: self.insearch.grab_focus() elif mod == "Ctrl+A": self.jump_item() elif mod == "Ctrl++": self.volume_up() elif mod == "Ctrl+-": self.volume_down() elif mod == "Ctrl+Q": self.exit() elif mod == "Ctrl+Alt+P": self.show_config() elif mod == "Ctrl+T": self.testing() elif keyval == 65363: try: self.xmms.playback_seek_ms_rel(self.seek) except: print "Exced" elif keyval == 65361: try: self.xmms.playback_seek_ms_rel(self.seek*(-1)) except: print "Exced"
def _handle_activate(self, group, widget, keyval, modifier): """Handle accelerator activation""" label = gtk.accelerator_get_label(keyval, modifier) name = self._method_names[label] data = self._methods[name]['data'] callback_method = self._methods[name]['callback'] # call user method if data is None: result = callback_method(widget, label) else: result = callback_method(widget, data) return result
def populate_tree(self, path, key, mode, changed): """ Internal used method to fill tree. """ m = re.match("^<Actions>/(.+)/(.+)$", path) if not m: print "Warning: action \"%s\" doesn't match re!"%path return grp, act = m.group(1), m.group(2) # if new group -> create one if not grp in self.__model_iters: self.__model_iters[grp] = self.__model.append(None, ["<b>%s</b>"%grp, "", ""]) # assign action to group self.__model.append(self.__model_iters[grp], [act, gtk.accelerator_get_label(key,mode), path]) self.__my_accel_map[path] = (key, mode)
def get_accel_label(self): ''' converts the accelerator keyval and modifier mask into a string @return: a accelerator string ''' if self.state is None or self.keyval is None: return '' if self.keyval == 0 and self.state == gtk.gdk.SUPER_MASK: return 'Super' if 'LANGUAGE' in os.environ: old_lang = os.environ["LANGUAGE"] else: old_lang = '' os.environ["LANGUAGE"] = "en_US" #return markup_escape_text(gtk.accelerator_get_label(self.keyval, self.state)).replace("制表", "Tab").replace("打印", "Print") accel_label = markup_escape_text(gtk.accelerator_get_label(self.keyval, self.state)) os.environ["LANGUAGE"] = old_lang return accel_label
def get_accel_label(self): ''' converts the accelerator keyval and modifier mask into a string @return: a accelerator string ''' if self.state is None or self.keyval is None: return '' if self.keyval == 0 and self.state == gtk.gdk.SUPER_MASK: return 'Super' if 'LANGUAGE' in os.environ: old_lang = os.environ["LANGUAGE"] else: old_lang = '' os.environ["LANGUAGE"] = "en_US" #return markup_escape_text(gtk.accelerator_get_label(self.keyval, self.state)).replace("制表", "Tab").replace("打印", "Print") accel_label = markup_escape_text( gtk.accelerator_get_label(self.keyval, self.state)) os.environ["LANGUAGE"] = old_lang return accel_label
def button_press_displayname(button, mods): """Converts a button number & modifier mask to a localized unicode string. """ button = int(button) mods = int(mods) if button <= 0: return None mods = gdk.ModifierType(mods) modif_label = gtk.accelerator_get_label(0, mods) modif_label = unicode(modif_label) separator = "" if modif_label: separator = u"+" #TRANSLATORS: abbreviated "Button <number>" for forms like "Ctrl+Alt+Btn1" return _("{modifiers}{plus}Btn{button_number}").format( modifiers=modif_label, plus=separator, button_number=button, )
def populate_tree(self, path, key, mode, changed): """ Internal used method to fill tree. """ m = re.match("^<Actions>/(.+)/(.+)$", path) if not m: print "Warning: action \"%s\" doesn't match re!" % path return grp, act = m.group(1), m.group(2) # if new group -> create one if not grp in self.__model_iters: self.__model_iters[grp] = self.__model.append( None, ["<b>%s</b>" % grp, "", ""]) # assign action to group self.__model.append( self.__model_iters[grp], [act, gtk.accelerator_get_label(key, mode), path]) self.__my_accel_map[path] = (key, mode)
def make_keystr_arguments(self, keystr): keys, orig_mods = gtk.accelerator_parse(keystr) m = { gtk.gdk.SHIFT_MASK: "Shift_L", gtk.gdk.CONTROL_MASK: "Control_L", gtk.gdk.SUPER_MASK: "Super_L", gtk.gdk.MOD1_MASK: "Alt_L", } mod_names = [] mods = orig_mods for mod in m: if mod & mods: mod_names.append(m[mod]) mods &= ~mod if mods != 0: raise OperationError("Keys not yet implemented: %s" % gtk.accelerator_get_label(keys, orig_mods)) key_arg = 'key %s' % (gtk.gdk.keyval_name(keys), ) mods_down = ['keydown ' + n for n in mod_names] mods_up = ['keyup ' + n for n in reversed(mod_names)] return mods_down + [key_arg] + mods_up
def on_double_click(self, view, path, column): """ If a action was double-clicked. """ iter = self.__model.get_iter(path) if not self.__model[iter][2]: return True # show key-chooser-dialog dlg = KeyChooser() if dlg.run() == gtk.RESPONSE_DELETE_EVENT: return True # get keys: (key, modi) = dlg.keys # if backspace with no modifier -> delete accelerator: if key == 65288 and modi == 0: self.__model[iter][1] = "" self.__my_accel_map[self.__model[iter][2]] = (0, 0) return True # set keys to table (tree) self.__model[iter][1] = gtk.accelerator_get_label(key, modi) self.__my_accel_map[self.__model[iter][2]] = (key, modi)
def on_control_s_in_PlainTextview(self, textview, event, dictkey, builder): #print "on_control_s: ", self, textview, event, dictkey # die gedrueckte key / keycombi auslesen key = gtk.accelerator_get_label(event.keyval, event.state) # wenn die keycombi ctrl+s ist, dann speicher den textbuffer in die datei if key == 'Ctrl+S': # hole den filenamen dessen inhalt im buffer steckt und hole den timestamp der letzten modifikation als die datei eingelesen wurde filepath, lastmod = self.getOpenedFiles(dictkey) if os.path.exists(filepath): if os.path.getmtime(filepath) == lastmod: # hole den text aus dem textbuffer der 2 textviews textview = builder.get_object('env_plainTextview') textbuffer = textview.get_buffer() text1 = textbuffer.get_text( textbuffer.get_start_iter(), textbuffer.get_end_iter(), True ) textview = builder.get_object('value_plainTextview') textbuffer = textview.get_buffer() text2 = textbuffer.get_text( textbuffer.get_start_iter(), textbuffer.get_end_iter(), True ) # file hinter filepath oeffnen und inhalt des textbuffers reinschreiben outfile = open(filepath, 'w') if outfile: outfile.write(text1) outfile.write(text2) outfile.close() self.updateOpenedFiles(dictkey, filepath) # wenn die zahlen geaendert werden muss naturlich auch der plot geaendert werden self.updateViewPlot(filepath, builder) else: print '%s%s%s' % ('File: ', filepath, ' not found') else: print '%s%s%s' % ('File: ', filepath, ' has modified by another program') else: print '%s%s%s' % ('File: ', filepath, ' not found')
def on_keybindings_row_activate(self, treeview, path, view_column): def bind_key_func(target): def bind_key(keystr): return keybindings.bind_key(keystr, target) return bind_key it = self.keybind_store.get_iter(path) keybind_id = self.keybind_store.get_value(it, 2) setctl = settings.GetSettingsController() curr_key = setctl.get_global_keybinding(keybind_id) bind_func = bind_key_func(self.KEYBINDING_TARGETS[keybind_id]) keystr = getkey_dialog.ask_for_key(bind_func, curr_key, screen=treeview.get_screen()) if keystr == '': keybindings.bind_key(None, self.KEYBINDING_TARGETS[keybind_id]) setctl.set_global_keybinding(keybind_id, keystr) self.keybind_store.set_value(it, 1, '') elif keystr is not None: setctl.set_global_keybinding(keybind_id, keystr) label = gtk.accelerator_get_label(*gtk.accelerator_parse(keystr)) self.keybind_store.set_value(it, 1, label)
def button_press_displayname(button, mods, shorten=False): """Converts a button number & modifier mask to a localized unicode string. """ button = int(button) mods = int(mods) if button <= 0: return None mods = gdk.ModifierType(mods) modif_label = gtk.accelerator_get_label(0, mods) modif_label = unicode(modif_label) separator = "" if modif_label: separator = u"+" mouse_button_label = _("Button") if shorten: #TRANSLATORS: abbreviated "Button <number>" for forms like "Alt+Btn1" mouse_button_label = _("Btn") return "{modifiers}{plus}{btn}{button_number}".format( modifiers=modif_label, plus=separator, btn=mouse_button_label, button_number=button, )
def __init__(self): super(Guake, self).__init__(gladefile('guake.glade')) self.client = gconf.client_get_default() # setting global hotkey and showing a pretty notification =) guake.globalhotkeys.init() # Cannot use "getattr(gtk.Window().get_style(), "base")[int(gtk.STATE_SELECTED)]" # since theme has not been applied before first show_all self.selected_color = None self.isPromptQuitDialogOpened = False self.hidden = True self.forceHide = False # trayicon! try: import appindicator except ImportError: img = pixmapfile('guake-tray.png') self.tray_icon = gtk.status_icon_new_from_file(img) self.tray_icon.set_tooltip(_('Guake Terminal')) self.tray_icon.connect('popup-menu', self.show_menu) self.tray_icon.connect('activate', self.show_hide) else: self.tray_icon = appindicator.Indicator( _("guake-indicator"), _("guake-tray"), appindicator.CATEGORY_OTHER) self.tray_icon.set_icon("guake-tray") self.tray_icon.set_status(appindicator.STATUS_ACTIVE) menu = self.get_widget('tray-menu') show = gtk.MenuItem(_('Show')) show.set_sensitive(True) show.connect('activate', self.show_hide) show.show() menu.prepend(show) self.tray_icon.set_menu(menu) # adding images from a different path. ipath = pixmapfile('guake.png') self.get_widget('image1').set_from_file(ipath) ipath = pixmapfile('add_tab.png') self.get_widget('image2').set_from_file(ipath) # important widgets self.window = self.get_widget('window-root') self.mainframe = self.get_widget('mainframe') self.mainframe.remove(self.get_widget('notebook-teminals')) self.notebook = GuakeNotebook() self.notebook.set_name("notebook-teminals") self.notebook.set_property("tab_pos", "bottom") self.notebook.set_property("show_tabs", False) self.notebook.set_property("show_border", False) self.notebook.set_property("visible", True) self.notebook.set_property("has_focus", True) self.notebook.set_property("can_focus", True) self.notebook.set_property("is_focus", True) self.notebook.set_property("enable_popup", True) self.notebook.connect("switch_page", self.select_current_tab) self.mainframe.add(self.notebook) self.set_tab_position() self.tabs = self.get_widget('hbox-tabs') self.toolbar = self.get_widget('toolbar') self.mainframe = self.get_widget('mainframe') self.resizer = self.get_widget('resizer') # check and set ARGB for real transparency screen = self.window.get_screen() colormap = screen.get_rgba_colormap() if colormap is None: self.has_argb = False else: self.window.set_colormap(colormap) self.has_argb = self.window.get_screen().is_composited() def composited_changed(screen): self.has_argb = screen.is_composited() self.set_background_transparency( self.client.get_int(KEY('/style/background/transparency'))) self.set_background_image( self.client.get_string(KEY('/style/background/image'))) self.window.get_screen().connect("composited-changed", composited_changed) # It's intended to know which tab was selected to # close/rename. This attribute will be set in # self.show_tab_menu self.selected_tab = None # holds fullscreen status self.is_fullscreen = False # holds the timestamp of the losefocus event self.losefocus_time = 0 # holds the timestamp of the previous show/hide action self.prev_showhide_time = 0 # double click stuff def double_click(hbox, event): """Handles double clicks on tabs area and when receive one, calls add_tab. """ if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.add_tab() evtbox = self.get_widget('event-tabs') evtbox.connect('button-press-event', double_click) # Flag to prevent guake hide when window_losefocus is true and # user tries to use the context menu. self.showing_context_menu = False def hide_context_menu(menu): """Turn context menu flag off to make sure it is not being shown. """ self.showing_context_menu = False self.get_widget('context-menu').connect('hide', hide_context_menu) self.get_widget('tab-menu').connect('hide', hide_context_menu) self.window.connect('focus-out-event', self.on_window_losefocus) # Handling the delete-event of the main window to avoid # problems when closing it. def destroy(*args): self.hide() return True self.window.connect('delete-event', destroy) # Flag to completely disable losefocus hiding self.disable_losefocus_hiding = False # this line is important to resize the main window and make it # smaller. self.window.set_geometry_hints(min_width=1, min_height=1) # special trick to avoid the "lost guake on Ubuntu 'Show Desktop'" problem. # DOCK makes the window foundable after having being "lost" after "Show Desktop" self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DOCK) # Restore back to normal behavior self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL) # resizer stuff self.resizer.connect('motion-notify-event', self.on_resizer_drag) # adding the first tab on guake self.add_tab() # loading and setting up configuration stuff GConfHandler(self) GConfKeyHandler(self) self.hotkeys = guake.globalhotkeys.GlobalHotkey() self.load_config() key = self.client.get_string(GKEY('show_hide')) keyval, mask = gtk.accelerator_parse(key) label = gtk.accelerator_get_label(keyval, mask) filename = pixmapfile('guake-notification.png') if self.client.get_bool(KEY('/general/start_fullscreen')): self.fullscreen() if not self.hotkeys.bind(key, self.show_hide): guake.notifier.show_message( _('Guake!'), _('A problem happened when binding <b>%s</b> key.\n' 'Please use Guake Preferences dialog to choose another ' 'key') % xml_escape(label), filename) self.client.set_bool(KEY('/general/use_trayicon'), True) elif self.client.get_bool(KEY('/general/use_popup')): # Pop-up that shows that guake is working properly (if not # unset in the preferences windows) guake.notifier.show_message( _('Guake!'), _('Guake is now running,\n' 'press <b>%s</b> to use it.') % xml_escape(label), filename)
def update_accelerator_label(self, keyval, state): accel_label = gtk.accelerator_get_label(keyval, state) self.labelaccelerator.set_text(accel_label)
def get_trigger_display_text(self): display_text = None if self.trigger is not None: keyval, modifiers = self.trigger display_text = gtk.accelerator_get_label(keyval, modifiers or 0) return display_text or ''
def on_key(self, accelgroup, acceleratable, accel_key, accel_mods, user_param1 = None): cmd = gtk.accelerator_get_label(accel_key, accel_mods) self.on_menu_activate(cmd)