Exemple #1
0
    def set_reset_line(self, command=None):

        if command is None:
            command = self.computer.RESET_ALL_LIGHTS_ON

        if command == self.computer.RESET_ALL_LIGHTS_ON:
            legend = "reset, command=RESET_ALL_LIGHTS_ON\n"

        elif command == self.computer.RESET_ALL_LIGHTS_OFF:
            legend = "reset, command=RESET_ALL_LIGHTS_OFF\n"

        elif command == self.computer.RESET_TOUCH_CONTROLS:
            legend = "reset, command=RESET_TOUCH_CONTROLS\n"

        else:
            legend = "reset, command=UNKNOWN COMMAND !!\n"
            print_error("Wrong command={}".format(command))

        self._save_line()

        cmd = copy(self._void)
        cmd[0] = self.computer.START_BYTE
        cmd[1] = self.computer.COMMAND_RESET
        cmd[2] = command

        self.append(Request(legend, cmd))
Exemple #2
0
    def reload_address(self, display_the_error=True):
        """
            It tries to make a connection with the Daemon
            and it returns True or False.
        """

        if not self.ping() and os.path.exists(self._paths.DAEMON_PYRO_PATH):

            with open(self._paths.DAEMON_PYRO_PATH,
                      mode='rt',
                      encoding='utf-8') as f:
                address = f.readline().strip()

            try:
                pyro = Pyro4.Proxy(address)
                pyro.ping()

                self._address = address
                self._pyro = pyro

                return True

            except Exception:

                if display_the_error:
                    print_error(format_exc())

                self._address = False
                self._pyro = False
                return False
        else:
            self._address = False
            self._pyro = False
            return False
Exemple #3
0
    def __init__(self, driver=Driver()):

        if not driver.has_device():
            print_error("The computer is not supported.")
            self._driver = None
        else:
            self._driver = driver
            self._constructor = Constructor(self._driver.computer)
Exemple #4
0
 def take_over(self):
     try:
         self._device.set_configuration()
     except:
         self._device.detach_kernel_driver(0)
         try:
             self._device.set_configuration()
         except Exception:
             print_error(format_exc())
             sys.exit(1)
Exemple #5
0
def main():

    if not AKBL_CONECTION.ping():
        print_error("Failed to start the Indicator because the daemon is off.")
        exit(1)

    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    GObject.threads_init()
    Gdk.threads_init()
    _ = ConnectIndicator()
    Gtk.main()
Exemple #6
0
def main():

    if not AKBLConnection.ping():
        print_error("Failed to start the GUI because the daemon is off.")
        exit(1)

    GObject.threads_init()
    Gdk.threads_init()

    _ = GUI()
    Gtk.main()
Exemple #7
0
def get_computer_by_path(file_path):

    print_debug("Reading {}".format(file_path))

    computer = Computer()
    computer.configuration_path = file_path

    config = ConfigParser()
    config.optionxform = str

    try:
        config.read(file_path)
    except Exception:
        print_error("Corrupted file: {}\n\n{}".format(file_path))
        traceback.print_exc()
        return None

    for key in config["COMMON"]:
        if hasattr(computer, key):

            value = config["COMMON"][key]

            if value != "":
                if key in ("NAME", "DEFAULT_MODE"):
                    setattr(computer, key, value)
                else:
                    setattr(computer, key, int(value))

    for section in config.sections():
        if section.startswith("REGION"):

            try:
                region = Region(config[section]["ID"],
                                config[section]["DESCRIPTION"],
                                int(config[section]["BLOCK"]),
                                int(config[section]["SUPPORTED_COMMANDS"]),
                                config[section]["CAN_BLINK"] == "True",
                                config[section]["CAN_MORPH"] == "True",
                                config[section]["CAN_LIGHT"] == "True")

                computer.add_region(region)

            except Exception:
                print_error("Corrupted region: {} in {}.\n\n".format(
                    section, file_path))
                traceback.print_exc()

    return computer
Exemple #8
0
 def write_constructor(self, constructor):
     
     print_debug('\n'.join(str(request) for request in constructor))
     
     try:
         for command in constructor:
             status = self._device.ctrl_transfer(self.__send_request_type, 
                                                 self.__send_request, 
                                                 self.__send_value, 
                                                 self.__send_index, 
                                                 command)
             
             print_debug("command output={}".format(status))
             
     except Exception:
         print_error(format_exc())
Exemple #9
0
 def read_device(self, constructor):
     
     try:
         msg = self._device.ctrl_transfer(self.__read_request_type, 
                                          self.__read_request, 
                                          self.__read_value, 
                                          self.__read_index, 
                                          len(constructor.get_first_command()))
         
 
     except Exception:
         print_error(format_exc())
         return False
     
     
     print_debug("msg={}".format(msg)) 
     return msg
Exemple #10
0
    def _command(self, command, *args):
        """
            Send a command to the daemon and return a tuple containing (boolean, response).
            The boolean indicates weather the command was succesfull or not, and the response
            contains the information returned by the command.
        """
        if command in ('set_profile', 'set_lights', 'switch_lights',
                       'reload_configurations'):
            args = [self._user] + list(args)

        if not self._address:
            self.reload_address()

        if self._address:
            try:
                response = getattr(self._pyro, command)(*args)
                return response

            except Exception:

                try:
                    #
                    # I ignore why this has to be inside an exception. Its like if there was a problem printing format_exc().
                    # The bug happens when repducing the following scenario:
                    #    1) There is a launched indicator.
                    #    2) The software is re-installed.
                    #    3) The user tries to close the indicator by usig the "Exit" button.
                    #

                    if len(args) > 0:
                        print_error("Command={}, arguments=[{}]\n{}\n".format(
                            command, ','.join((str(arg) for arg in args)),
                            str(format_exc())))
                    else:
                        print_error("Command={}\n{}\n".format(
                            command, str(format_exc())))

                except Exception:
                    pass

                return False

        else:
            print_warning("The daemon is off.")
            return False
Exemple #11
0
    def reload_configurations(self, user, indicator=True, set_default=True):

        if user != self._user:
            self._user = user
            self._paths = Paths(user)
            self._ccp.set_configuration_path(self._paths.CONFIGURATION_PATH)

        Theme.LOAD_profiles(self._computer, self._paths.PROFILES_PATH)

        if set_default:
            _, profile_name = Theme.GET_last_configuration()
            self._theme = Theme.get_theme_by_name(profile_name)

        if self._indicator_pyro and indicator:
            try:
                self._indicator_pyro.load_profiles(Theme.AVAILABLE_THEMES.keys(), self._theme.name, self._lights_state)
            except Exception:
                print_error(format_exc())
Exemple #12
0
    def _iluminate_keyboard(self):

        # Find the last theme that has been used
        #
        os.utime(self._theme.path, None)

        # Iluminate the computer lights
        #

        self._controller.erase_config()

        for save, block in self._COMPUTER_BLOCKS_TO_SAVE:

            self._controller.add_block_line(save=save, block=block)
            self._controller.add_reset_line(self._computer.RESET_ALL_LIGHTS_ON)
            self._controller.add_speed_line(self._theme.get_speed())

            for area in self._theme.get_areas():
                for zone in area.get_zones():
                    self._controller.add_color_line(zone.get_hex_id(),
                                                    zone.get_mode(),
                                                    zone.get_left_color(),
                                                    zone.get_right_color())

                self._controller.end_colors_line()

            self._controller.end_block_line()

        self._controller.apply_config()

        # Update the Indicator
        #
        if self._indicator_pyro:
            self._indicator_send_code(100)
            try:
                self._indicator_pyro.load_profiles(
                    theme_factory._AVAILABLE_THEMES.keys(), self._theme.name,
                    self._lights_state)
            except Exception:
                print_error(format_exc())

        # Update the Daemon variables
        #
        self._lights_state = True
Exemple #13
0
    def reload_configurations(self, user, indicator=True, set_default=True):

        if user != self._user:
            self._user = user
            self._paths = Paths(user)
            self._ccp.set_configuration_path(self._paths._configuration_file)

        theme_factory.LOAD_profiles(self._computer, self._paths._profiles_dir)

        if set_default:
            _, profile_name = theme_factory.GET_last_configuration()
            self._theme = theme_factory.get_theme_by_name(profile_name)

        if self._indicator_pyro and indicator:
            try:
                self._indicator_pyro.load_profiles(
                    theme_factory._AVAILABLE_THEMES.keys(), self._theme.name,
                    self._lights_state)
            except Exception:
                print_error(format_exc())
Exemple #14
0
    def ILUMINATE_keyboard(self):

        Gdk.threads_enter()
        self.label_user_message.set_text(TEXT_APPLYING_CONFIGURATION)
        Gdk.threads_leave()

        # This is to make the program recognize the last profile that has been
        # used
        try:
            # Patch (#12)
            os.utime(self.theme.path, None)
        except Exception:
            print_error('It was not possible to os.utime the profile path: \n{}\n{}'.format(self.theme.path), format_exc())

        AKBLConnection._command('reload_configurations')

        AKBLConnection.set_lights(True)

        Gdk.threads_enter()
        self.label_user_message.set_text('')
        Gdk.threads_leave()
Exemple #15
0
 def _indicator_send_code(self, val):
     if self._indicator_pyro:
         try:
             self._indicator_pyro.set_code(val)
         except Exception:
             print_error(format_exc())