コード例 #1
0
ファイル: g15macroeditor.py プロジェクト: tanktarta/gnome15
    def _toggle_key(self, widget, key, macro):
        """
        Event handler invoked when one of the macro key buttons is pressed.
        """
        keys = list(macro.keys)

        if key in keys:
            keys.remove(key)
        else:
            if not self.adjusting and not self.__allow_combination.get_active(
            ):
                for button in self.__key_buttons:
                    if button != widget:
                        self.adjusting = True
                        try:
                            button.set_active(False)
                        finally:
                            self.adjusting = False
                for ikey in keys:
                    if ikey != key:
                        keys.remove(ikey)
            keys.append(key)

        if not self.selected_profile.are_keys_in_use(
                self.editing_macro.activate_on,
                self.memory_number,
                keys,
                exclude=[self.editing_macro]):
            if self.__macro_name_field.get_text(
            ) == "" or self.__macro_name_field.get_text().startswith("Macro "):
                new_name = " ".join(g15driver.get_key_names(keys))
                self.editing_macro.name = _("Macro %s") % new_name
                self.__macro_name_field.set_text(self.editing_macro.name)
            macro.set_keys(keys)

        self.__set_button_style(widget)

        if not self.adjusting:
            self.__check_macro(keys)
            self.__save_macro(self.editing_macro)
コード例 #2
0
ファイル: g15macroeditor.py プロジェクト: FPar/gnome15
 def _toggle_key(self, widget, key, macro):
     """
     Event handler invoked when one of the macro key buttons is pressed.
     """
     keys = list(macro.keys) 
             
     if key in keys:
         keys.remove(key)
     else:            
         if not self.adjusting and not self.__allow_combination.get_active():
             for button in self.__key_buttons:
                 if button != widget:
                     self.adjusting = True
                     try :
                         button.set_active(False)
                     finally:
                         self.adjusting = False
             for ikey in keys:
                 if ikey != key:
                     keys.remove(ikey)
         keys.append(key)
         
     if not self.selected_profile.are_keys_in_use(self.editing_macro.activate_on, 
                                                  self.memory_number, keys, 
                                                  exclude=[self.editing_macro]):
         if self.__macro_name_field.get_text() == "" or self.__macro_name_field.get_text().startswith("Macro "):
             new_name = " ".join(g15driver.get_key_names(keys))
             self.editing_macro.name = _("Macro %s") % new_name
             self.__macro_name_field.set_text(self.editing_macro.name)
         macro.set_keys(keys)
         
     self.__set_button_style(widget)
     
     if not self.adjusting:
         self.__check_macro(keys)
         self.__save_macro(self.editing_macro)
コード例 #3
0
ファイル: g15macroeditor.py プロジェクト: tanktarta/gnome15
    def set_macro(self, macro):
        """
        Set the macro to edit. Note, set_driver must have been called first
        so it knows which macro keys are available for use for the model
        in question.
        
        Keyword arguments:
        macro        --    macro to edit
        """
        if self.__driver is None:
            raise Exception("No driver set. Cannot set macro")

        self.adjusting = True
        try:
            self.editing_macro = macro
            self.selected_profile = macro.profile
            self.memory_number = macro.memory
            self.__widget_tree.get_object("KeyBox").set_sensitive(
                not self.selected_profile.read_only)
            keys_frame = self.__widget_tree.get_object("KeysFrame")
            self.__allow_combination.set_active(
                len(self.editing_macro.keys) > 1)

            # Build the G-Key selection widget
            if self.__rows:
                keys_frame.remove(self.__rows)
            self.__rows = gtk.VBox()
            self.__rows.set_spacing(4)
            self.__key_buttons = []
            for row in self.__driver.get_key_layout():
                hbox = gtk.HBox()
                hbox.set_spacing(4)
                for key in row:
                    key_name = g15driver.get_key_names([key])
                    g_button = gtk.ToggleButton(" ".join(key_name))
                    g_button.key = key
                    key_active = key in self.editing_macro.keys
                    g_button.set_active(key_active)
                    self.__set_button_style(g_button)
                    g_button.connect("toggled", self._toggle_key, key,
                                     self.editing_macro)
                    self.__key_buttons.append(g_button)
                    hbox.pack_start(g_button, True, True)
                self.__rows.pack_start(hbox, False, False)
            keys_frame.add(self.__rows)
            keys_frame.show_all()

            # Set the activation mode
            for index, (activate_on_id, activate_on_name) in enumerate(
                    self.__activate_on_combo.get_model()):
                if activate_on_id == self.editing_macro.activate_on:
                    self.__activate_on_combo.set_active(index)

            # Set the repeat mode
            for index, (repeat_mode_id, repeat_mode_name) in enumerate(
                    self.__repeat_mode_combo.get_model()):
                if repeat_mode_id == self.editing_macro.repeat_mode:
                    self.__repeat_mode_combo.set_active(index)

            # Set the type of macro
            for index, (macro_type,
                        macro_type_name) in enumerate(self.__map_type_model):
                if macro_type == self.editing_macro.type:
                    self.__mapped_key_type_combo.set_active(index)
            self.__set_available_options()

            # Set the other details
            for index, row in enumerate(self.__map_type_model):
                if row[0] == self.editing_macro.type:
                    self.__mapped_key_type_combo.set_active(index)
                    break
            self.__load_keys()
            if self.editing_macro.type in [
                    g15profile.MACRO_MOUSE, g15profile.MACRO_JOYSTICK,
                    g15profile.MACRO_DIGITAL_JOYSTICK,
                    g15profile.MACRO_KEYBOARD
            ]:
                for index, row in enumerate(self.__mapped_key_model):
                    if self.__mapped_key_model[index][
                            0] == self.editing_macro.macro:
                        self.__select_tree_row(self.__uinput_tree, index)
                        break
            elif self.editing_macro.type == g15profile.MACRO_ACTION:
                for index, row in enumerate(self.__action_model):
                    if self.__action_model[index][
                            0] == self.editing_macro.macro:
                        self.__select_tree_row(self.__action_tree, index)
                        break

            self.__text_buffer = gtk.TextBuffer()
            self.__text_buffer.connect("changed", self._macro_script_changed)
            self.__macro_script.set_buffer(self.__text_buffer)

            self.__turbo_rate.get_adjustment().set_value(
                self.editing_macro.repeat_delay)
            self.__memory_bank_label.set_text("M%d" % self.memory_number)
            self.__macro_name_field.set_text(self.editing_macro.name)
            self.__override_default_repeat.set_active(
                self.editing_macro.repeat_delay != -1)

            if self.editing_macro.type == g15profile.MACRO_SIMPLE:
                self.__simple_macro.set_text(self.editing_macro.macro)
            else:
                self.__simple_macro.set_text("")
            if self.editing_macro.type == g15profile.MACRO_COMMAND:
                cmd = self.editing_macro.macro
                background = False
                if cmd.endswith("&"):
                    cmd = cmd[:-1]
                    background = True
                elif cmd == "":
                    background = True
                self.__command.set_text(cmd)
                self.__run_in_background.set_active(background)
            else:
                self.__run_in_background.set_active(False)
                self.__command.set_text("")
            if self.editing_macro.type == g15profile.MACRO_SCRIPT:
                self.__text_buffer.set_text(self.editing_macro.macro)
            else:
                self.__text_buffer.set_text("")

            self.__check_macro(self.editing_macro.keys)
            self.__macro_name_field.grab_focus()

        finally:
            self.adjusting = False
        self.editing_macro.name = self.__macro_name_field.get_text()
        self.__set_available_options()
コード例 #4
0
ファイル: g15macroeditor.py プロジェクト: FPar/gnome15
 def set_macro(self, macro):
     """
     Set the macro to edit. Note, set_driver must have been called first
     so it knows which macro keys are available for use for the model
     in question.
     
     Keyword arguments:
     macro        --    macro to edit
     """
     if self.__driver is None:
         raise Exception("No driver set. Cannot set macro")
     
     self.adjusting = True
     try:
         self.editing_macro = macro
         self.selected_profile = macro.profile
         self.memory_number = macro.memory
         self.__widget_tree.get_object("KeyBox").set_sensitive(not self.selected_profile.read_only)
         keys_frame = self.__widget_tree.get_object("KeysFrame")
         self.__allow_combination.set_active(len(self.editing_macro.keys) > 1)
         
         # Build the G-Key selection widget
         if self.__rows:
             keys_frame.remove(self.__rows)
         self.__rows = gtk.VBox()
         self.__rows.set_spacing(4)
         self.__key_buttons = []
         for row in self.__driver.get_key_layout():
             hbox = gtk.HBox()
             hbox.set_spacing(4)
             for key in row:
                 key_name = g15driver.get_key_names([ key ])
                 g_button = gtk.ToggleButton(" ".join(key_name))
                 g_button.key = key
                 key_active = key in self.editing_macro.keys
                 g_button.set_active(key_active)
                 self.__set_button_style(g_button)
                 g_button.connect("toggled", self._toggle_key, key, self.editing_macro)
                 self.__key_buttons.append(g_button)
                 hbox.pack_start(g_button, True, True)
             self.__rows.pack_start(hbox, False, False)
         keys_frame.add(self.__rows)     
         keys_frame.show_all()
         
         # Set the activation mode
         for index, (activate_on_id, activate_on_name) in enumerate(self.__activate_on_combo.get_model()):
             if activate_on_id == self.editing_macro.activate_on:
                 self.__activate_on_combo.set_active(index)
                     
         # Set the repeat mode
         for index, (repeat_mode_id, repeat_mode_name) in enumerate(self.__repeat_mode_combo.get_model()):
             if repeat_mode_id == self.editing_macro.repeat_mode:
                 self.__repeat_mode_combo.set_active(index)
         
         # Set the type of macro
         for index, (macro_type, macro_type_name) in enumerate(self.__map_type_model):
             if macro_type == self.editing_macro.type:
                 self.__mapped_key_type_combo.set_active(index) 
         self.__set_available_options()
             
         # Set the other details 
         for index, row in enumerate(self.__map_type_model):
             if row[0] == self.editing_macro.type:                
                 self.__mapped_key_type_combo.set_active(index)
                 break
         self.__load_keys()
         if self.editing_macro.type in [ g15profile.MACRO_MOUSE, g15profile.MACRO_JOYSTICK, g15profile.MACRO_DIGITAL_JOYSTICK, g15profile.MACRO_KEYBOARD ]:
             for index, row in enumerate(self.__mapped_key_model):
                 if self.__mapped_key_model[index][0] == self.editing_macro.macro: 
                     self.__select_tree_row(self.__uinput_tree, index)
                     break
         elif self.editing_macro.type == g15profile.MACRO_ACTION:
             for index, row in enumerate(self.__action_model):
                 if self.__action_model[index][0] == self.editing_macro.macro: 
                     self.__select_tree_row(self.__action_tree, index)
                     break
             
         self.__text_buffer = gtk.TextBuffer()        
         self.__text_buffer.connect("changed", self._macro_script_changed)    
         self.__macro_script.set_buffer(self.__text_buffer)
             
         self.__turbo_rate.get_adjustment().set_value(self.editing_macro.repeat_delay)
         self.__memory_bank_label.set_text("M%d" % self.memory_number)
         self.__macro_name_field.set_text(self.editing_macro.name)
         self.__override_default_repeat.set_active(self.editing_macro.repeat_delay != -1)
         
         if self.editing_macro.type == g15profile.MACRO_SIMPLE:
             self.__simple_macro.set_text(self.editing_macro.macro)
         else:
             self.__simple_macro.set_text("")
         if self.editing_macro.type == g15profile.MACRO_COMMAND:
             cmd = self.editing_macro.macro
             background = False
             if cmd.endswith("&"):
                 cmd = cmd[:-1]
                 background = True
             elif cmd == "":
                 background = True
             self.__command.set_text(cmd)
             self.__run_in_background.set_active(background)
         else:
             self.__run_in_background.set_active(False)
             self.__command.set_text("")
         if self.editing_macro.type == g15profile.MACRO_SCRIPT:
             self.__text_buffer.set_text(self.editing_macro.macro)
         else:            
             self.__text_buffer.set_text("")
             
         self.__check_macro(self.editing_macro.keys)
         self.__macro_name_field.grab_focus()
         
     finally:
         self.adjusting = False
     self.editing_macro.name = self.__macro_name_field.get_text()
     self.__set_available_options()
コード例 #5
0
def get_key_names(keys):
    return g15driver.get_key_names(keys)