Exemplo n.º 1
0
    def save(self, filename=None):
        """
        Save this profile to disk
        """
        if self.read_only:
            raise Exception("Cannot write to read-only profile")
        logger.info("Saving macro profile %s, %s", self.id, self.name)
        if filename is None:
            filename = self.filename
        if self.window_name is None:
            self.window_name = ""
        if self.icon is None:
            self.icon = ""

        # Set the profile options
        self.parser.set("DEFAULT", "name", self.name)
        self.parser.set("DEFAULT", "version", str(self.version))
        self.parser.set("DEFAULT", "icon", self.icon)
        self.parser.set("DEFAULT", "window_name", self.window_name)
        if self.version == 1.0:
            self.parser.set(
                "DEFAULT", "base_profile",
                str(self.base_profile)
                if self.base_profile is not None else "-1")
        else:
            self.parser.set(
                "DEFAULT", "base_profile",
                str(self.base_profile)
                if self.base_profile is not None else "")
        self.parser.set("DEFAULT", "icon", self.icon)
        self.parser.set("DEFAULT", "background", self.background)
        self.parser.set("DEFAULT", "author", self.author)
        self.parser.set("DEFAULT", "activate_on_focus",
                        str(self.activate_on_focus))
        self.parser.set("DEFAULT", "plugins_mode", str(self.plugins_mode))
        self.parser.set("DEFAULT", "selected_plugins",
                        ",".join(self.selected_plugins))
        self.parser.set("DEFAULT", "send_delays", str(self.send_delays))
        self.parser.set("DEFAULT", "fixed_delays", str(self.fixed_delays))
        self.parser.set("DEFAULT", "press_delay", str(self.press_delay))
        self.parser.set("DEFAULT", "release_delay", str(self.release_delay))
        self.parser.set("DEFAULT", "models", ",".join(self.models))

        # Set the launch options
        if self.launch_pattern is not None:
            self.parser.set("LAUNCH", "pattern", self.launch_pattern)
            self.parser.set("LAUNCH", "monitor", ",".join(self.monitor))
            self.parser.set("LAUNCH", "activate_on_launch",
                            str(self.activate_on_launch))
        else:
            self._remove_if_exists("pattern", "LAUNCH")
            self._remove_if_exists("monitor", "LAUNCH")
            self._remove_if_exists("activate_on_launch", "LAUNCH")

        # Remove and re-add the bank sections
        for activate_on in [g15driver.KEY_STATE_UP, g15driver.KEY_STATE_HELD]:
            for i in range(1, 4):
                section_name = "m%d" % i
                if activate_on != g15driver.KEY_STATE_UP:
                    section_name = "%s-%s" % (section_name, activate_on)
                if not self.parser.has_section(section_name):
                    self.parser.add_section(section_name)
                col = self.mkey_color[i] if i in self.mkey_color else None
                if col:
                    self.parser.set(section_name, "backlight_color",
                                    g15convert.rgb_to_string(col))
                elif self.parser.has_option(section_name, "backlight_color"):
                    self.parser.remove_option(section_name, "backlight_color")

        # Add the macros
        for activate_on in [g15driver.KEY_STATE_UP, g15driver.KEY_STATE_HELD]:
            for i in range(1, 4):
                for macro in self.get_sorted_macros(activate_on, i):
                    if len(macro.keys) > 0:
                        macro._store()

        self._write(filename)
Exemplo n.º 2
0
 def save(self, filename = None):
     """
     Save this profile to disk
     """
     if self.read_only:
         raise Exception("Cannot write to read-only profile")
     logger.info("Saving macro profile %s, %s", self.id, self.name)
     if filename is None:
         filename = self.filename
     if self.window_name == None:
         self.window_name = ""
     if self.icon == None:
         self.icon = ""
     
     # Set the profile options
     self.parser.set("DEFAULT", "name", self.name)
     self.parser.set("DEFAULT", "version", str(self.version))
     self.parser.set("DEFAULT", "icon", self.icon)
     self.parser.set("DEFAULT", "window_name", self.window_name)
     if self.version == 1.0:
         self.parser.set("DEFAULT", "base_profile", str(self.base_profile) if self.base_profile is not None else "-1")
     else:   
         self.parser.set("DEFAULT", "base_profile", str(self.base_profile) if self.base_profile is not None else "")
     self.parser.set("DEFAULT", "icon", self.icon)
     self.parser.set("DEFAULT", "background", self.background)
     self.parser.set("DEFAULT", "author", self.author)
     self.parser.set("DEFAULT", "activate_on_focus", str(self.activate_on_focus))
     self.parser.set("DEFAULT", "plugins_mode", str(self.plugins_mode))
     self.parser.set("DEFAULT", "selected_plugins", ",".join(self.selected_plugins))
     self.parser.set("DEFAULT", "send_delays", str(self.send_delays))
     self.parser.set("DEFAULT", "fixed_delays", str(self.fixed_delays))
     self.parser.set("DEFAULT", "press_delay", str(self.press_delay))
     self.parser.set("DEFAULT", "release_delay", str(self.release_delay))
     self.parser.set("DEFAULT", "models", ",".join(self.models))
     
     # Set the launch options
     if self.launch_pattern is not None:
         self.parser.set("LAUNCH", "pattern", self.launch_pattern)
         self.parser.set("LAUNCH", "monitor", ",".join(self.monitor))
         self.parser.set("LAUNCH", "activate_on_launch", str(self.activate_on_launch))
     else:
         self._remove_if_exists("pattern", "LAUNCH")
         self._remove_if_exists("monitor", "LAUNCH")
         self._remove_if_exists("activate_on_launch", "LAUNCH")
     
     # Remove and re-add the bank sections
     for activate_on in [ g15driver.KEY_STATE_UP, g15driver.KEY_STATE_HELD ]:  
         for i in range(1, 4):
             section_name = "m%d" % i
             if activate_on != g15driver.KEY_STATE_UP:
                 section_name = "%s-%s" % ( section_name, activate_on ) 
             if not self.parser.has_section(section_name):
                 self.parser.add_section(section_name) 
             col = self.mkey_color[i] if i in self.mkey_color else None
             if col:
                 self.parser.set(section_name, "backlight_color", g15convert.rgb_to_string(col))
             elif self.parser.has_option(section_name, "backlight_color"):
                 self.parser.remove_option(section_name, "backlight_color")
             
     # Add the macros
     for activate_on in [ g15driver.KEY_STATE_UP, g15driver.KEY_STATE_HELD ]:  
         for i in range(1, 4):  
             for macro in self.get_sorted_macros(activate_on, i):
                 if len(macro.keys) > 0:
                     macro._store()
             
     self._write(filename)
Exemplo n.º 3
0
def rgb_to_string(rgb):
    return g15convert.rgb_to_string(rgb)