Beispiel #1
0
 def update_choiceprofile(self):
     """Reload profile list into the choice box."""
     self.list_of_profiles = list_profiles()
     self.profnames = []
     for prof in self.list_of_profiles:
         self.profnames.append(prof.name)
     self.profnames.append("Create a new profile")
     self.choice_profiles.SetItems(self.profnames)
Beispiel #2
0
    def __init__(self, frame):
        self.g_settings = GeneralSettingsData()

        self.frame = frame
        super(TaskBarIcon, self).__init__()
        self.set_icon(TRAY_ICON)
        # self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
        self.Bind(wx.adv.EVT_TASKBAR_LEFT_DCLICK, self.configure_wallpapers)
        # Initialize display data
        # get_display_data()
        wpproc.refresh_display_data()
        # profile initialization
        self.job_lock = Lock()
        self.repeating_timer = None
        self.pause_item = None
        self.is_paused = False
        # if sp_logging.DEBUG:
        # sp_logging.G_LOGGER.info("START Listing profiles for menu.")
        self.list_of_profiles = list_profiles()
        # if sp_logging.DEBUG:
        # sp_logging.G_LOGGER.info("END Listing profiles for menu.")
        # Should now return an object if a previous profile was written or
        # None if no previous data was found
        if STARTUP_PROFILE:
            self.active_profile = open_profile(STARTUP_PROFILE)
        else:
            self.active_profile = read_active_profile()
        if self.active_profile:
            wpproc.G_ACTIVE_PROFILE = self.active_profile.name
        self.start_prev_profile(self.active_profile)
        # if self.active_profile is None:
        #     sp_logging.G_LOGGER.info("Starting up the first profile found.")
        #     self.start_profile(wx.EVT_MENU, self.list_of_profiles[0])

        # self.hk = None
        # self.hk2 = None
        if self.g_settings.use_hotkeys is True:
            try:
                # import keyboard # https://github.com/boppreh/keyboard
                # This import is here to have the module in the class scope
                from system_hotkey import SystemHotkey
                self.hk = SystemHotkey(check_queue_interval=0.05)
                self.hk2 = SystemHotkey(consumer=self.profile_consumer,
                                        check_queue_interval=0.05)
                self.seen_binding = set()
                self.register_hotkeys()
            except ImportError as excep:
                sp_logging.G_LOGGER.info(
                    "WARNING: Could not import keyboard hotkey hook library, \
hotkeys will not work. Exception: %s", excep)
        if self.g_settings.show_help is True:
            config_frame = ConfigFrame(self)
            help_frame = HelpFrame()
Beispiel #3
0
 def reload_profiles(self, event):
     """Reloads profiles from disk."""
     self.list_of_profiles = list_profiles()
Beispiel #4
0
    def register_hotkeys(self):
        """Registers system-wide hotkeys for profiles and application interaction."""
        if self.g_settings.use_hotkeys is True:
            try:
                # import keyboard # https://github.com/boppreh/keyboard
                # This import allows access to the specific errors in this method.
                from system_hotkey import (SystemHotkey, SystemHotkeyError,
                                           SystemRegisterError,
                                           UnregisterError, InvalidKeyError)
            except ImportError as import_e:
                sp_logging.G_LOGGER.info(
                    "WARNING: Could not import keyboard hotkey hook library, \
hotkeys will not work. Exception: %s", import_e)
            if "system_hotkey" in sys.modules:
                try:
                    # Keyboard bindings: https://github.com/boppreh/keyboard
                    #
                    # Alternative KB bindings for X11 systems and Windows:
                    # system_hotkey https://github.com/timeyyy/system_hotkey
                    # seen_binding = set()
                    # self.hk = SystemHotkey(check_queue_interval=0.05)
                    # self.hk2 = SystemHotkey(
                    #     consumer=self.profile_consumer,
                    #     check_queue_interval=0.05)

                    # Unregister previous hotkeys
                    if self.seen_binding:
                        for binding in self.seen_binding:
                            try:
                                self.hk.unregister(binding)
                                if sp_logging.DEBUG:
                                    sp_logging.G_LOGGER.info(
                                        "Unreg hotkey %s", binding)
                            except (SystemHotkeyError, UnregisterError,
                                    InvalidKeyError):
                                try:
                                    self.hk2.unregister(binding)
                                    if sp_logging.DEBUG:
                                        sp_logging.G_LOGGER.info(
                                            "Unreg hotkey %s", binding)
                                except (SystemHotkeyError, UnregisterError,
                                        InvalidKeyError):
                                    if sp_logging.DEBUG:
                                        sp_logging.G_LOGGER.info(
                                            "Could not unreg hotkey '%s'",
                                            binding)
                        self.seen_binding = set()

                    # register general bindings
                    if self.g_settings.hk_binding_next not in self.seen_binding:
                        try:
                            self.hk.register(self.g_settings.hk_binding_next,
                                             callback=lambda x: self.
                                             next_wallpaper(wx.EVT_MENU),
                                             overwrite=False)
                            self.seen_binding.add(
                                self.g_settings.hk_binding_next)
                        except (SystemHotkeyError, SystemRegisterError,
                                InvalidKeyError):
                            msg = "Error: could not register hotkey {}. \
Check that it is formatted properly and valid keys.".format(
                                self.g_settings.hk_binding_next)
                            sp_logging.G_LOGGER.info(msg)
                            sp_logging.G_LOGGER.info(sys.exc_info()[0])
                            show_message_dialog(msg, "Error")
                    if self.g_settings.hk_binding_pause not in self.seen_binding:
                        try:
                            self.hk.register(self.g_settings.hk_binding_pause,
                                             callback=lambda x: self.
                                             pause_timer(wx.EVT_MENU),
                                             overwrite=False)
                            self.seen_binding.add(
                                self.g_settings.hk_binding_pause)
                        except (SystemHotkeyError, SystemRegisterError,
                                InvalidKeyError):
                            msg = "Error: could not register hotkey {}. \
Check that it is formatted properly and valid keys.".format(
                                self.g_settings.hk_binding_pause)
                            sp_logging.G_LOGGER.info(msg)
                            sp_logging.G_LOGGER.info(sys.exc_info()[0])
                            show_message_dialog(msg, "Error")
                    # try:
                    # self.hk.register(('control', 'super', 'shift', 'q'),
                    #  callback=lambda x: self.on_exit(wx.EVT_MENU))
                    # except (SystemHotkeyError, SystemRegisterError, InvalidKeyError):
                    # pass

                    # register profile specific bindings
                    self.list_of_profiles = list_profiles()
                    for profile in self.list_of_profiles:
                        if sp_logging.DEBUG:
                            sp_logging.G_LOGGER.info(
                                "Registering binding: \
                                %s for profile: %s", profile.hk_binding,
                                profile.name)
                        if (profile.hk_binding is not None and
                                profile.hk_binding not in self.seen_binding):
                            try:
                                self.hk2.register(profile.hk_binding,
                                                  profile,
                                                  overwrite=False)
                                self.seen_binding.add(profile.hk_binding)
                            except (SystemHotkeyError, SystemRegisterError,
                                    InvalidKeyError):
                                msg = "Error: could not register hotkey {}. \
Check that it is formatted properly and valid keys.".format(profile.hk_binding)
                                sp_logging.G_LOGGER.info(msg)
                                sp_logging.G_LOGGER.info(sys.exc_info()[0])
                                show_message_dialog(msg, "Error")
                        elif profile.hk_binding in self.seen_binding:
                            msg = "Could not register hotkey: '{}' for profile: '{}'.\n\
It is already registered for another action.".format(profile.hk_binding,
                                                     profile.name)
                            sp_logging.G_LOGGER.info(msg)
                            show_message_dialog(msg, "Error")
                except (SystemHotkeyError, SystemRegisterError,
                        UnregisterError, InvalidKeyError):
                    if sp_logging.DEBUG:
                        sp_logging.G_LOGGER.info(
                            "Coulnd't register hotkeys, exception:")
                        sp_logging.G_LOGGER.info(sys.exc_info()[0])
Beispiel #5
0
    def __init__(self, parent, parent_tray_obj):
        wx.Panel.__init__(self, parent)
        self.frame = parent
        self.parent_tray_obj = parent_tray_obj
        self.sizer_main = wx.BoxSizer(wx.HORIZONTAL)
        self.sizer_left = wx.BoxSizer(wx.VERTICAL)  # buttons and prof sel
        self.sizer_right = wx.BoxSizer(wx.VERTICAL)  # option fields
        self.sizer_paths = wx.BoxSizer(wx.VERTICAL)
        self.sizer_paths_buttons = wx.BoxSizer(wx.HORIZONTAL)

        self.paths_controls = []

        self.list_of_profiles = list_profiles()
        self.profnames = []
        for prof in self.list_of_profiles:
            self.profnames.append(prof.name)
        self.profnames.append("Create a new profile")
        self.choice_profiles = wx.Choice(self,
                                         -1,
                                         name="ProfileChoice",
                                         choices=self.profnames)
        self.choice_profiles.Bind(wx.EVT_CHOICE, self.onSelect)
        self.sizer_grid_options = wx.GridSizer(5, 4, 5, 5)
        pnl = self
        st_name = wx.StaticText(pnl, -1, "Name")
        st_span = wx.StaticText(pnl, -1, "Spanmode")
        st_slide = wx.StaticText(pnl, -1, "Slideshow")
        st_sort = wx.StaticText(pnl, -1, "Sort")
        st_del = wx.StaticText(pnl, -1, "Delay (600) [sec]")
        st_off = wx.StaticText(pnl, -1, "Offsets (w1,h1;w2,h2) [px]")
        st_in = wx.StaticText(pnl, -1, "Diagonal inches (24.0;13.3) [in]")
        # st_ppi = wx.StaticText(pnl, -1, "PPIs")
        st_bez = wx.StaticText(pnl, -1, "Bezels (10.1;9.5) [mm]")
        st_hk = wx.StaticText(pnl, -1, "Hotkey (control+alt+w)")

        tc_width = 160
        self.tc_name = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.ch_span = wx.Choice(pnl,
                                 -1,
                                 name="SpanChoice",
                                 size=(tc_width, -1),
                                 choices=["Single", "Multi"])
        self.ch_sort = wx.Choice(pnl,
                                 -1,
                                 name="SortChoice",
                                 size=(tc_width, -1),
                                 choices=["Shuffle", "Alphabetical"])
        self.tc_delay = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.tc_offsets = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.tc_inches = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        # self.tc_ppis = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.tc_bez = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.tc_hotkey = wx.TextCtrl(pnl, -1, size=(tc_width, -1))
        self.cb_slideshow = wx.CheckBox(pnl, -1,
                                        "")  # Put the title in the left column
        self.sizer_grid_options.AddMany([
            (st_name, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_name, 0, wx.ALIGN_LEFT | wx.ALL),
            (st_span, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.ch_span, 0, wx.ALIGN_LEFT),
            (st_slide, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.cb_slideshow, 0,
             wx.ALIGN_LEFT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (st_sort, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.ch_sort, 0, wx.ALIGN_LEFT),
            (st_del, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_delay, 0, wx.ALIGN_LEFT),
            (st_off, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_offsets, 0, wx.ALIGN_LEFT),
            (st_in, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_inches, 0, wx.ALIGN_LEFT),
            # (st_ppi, 0, wx.ALIGN_RIGHT),
            # (self.tc_ppis, 0, wx.ALIGN_LEFT),
            (st_bez, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_bez, 0, wx.ALIGN_LEFT),
            (st_hk, 0, wx.ALIGN_RIGHT | wx.ALL | wx.ALIGN_CENTER_VERTICAL),
            (self.tc_hotkey, 0, wx.ALIGN_LEFT),
        ])

        # Paths display
        self.paths_widget_default = self.create_paths_widget()
        self.sizer_paths.Add(self.paths_widget_default, 0, wx.CENTER | wx.ALL,
                             5)

        # Left column buttons
        self.button_apply = wx.Button(self, label="Apply")
        self.button_new = wx.Button(self, label="New")
        self.button_delete = wx.Button(self, label="Delete")
        self.button_save = wx.Button(self, label="Save")
        self.button_align_test = wx.Button(self, label="Align Test")
        self.button_help = wx.Button(self, label="Help")
        self.button_close = wx.Button(self, label="Close")

        self.button_apply.Bind(wx.EVT_BUTTON, self.onApply)
        self.button_new.Bind(wx.EVT_BUTTON, self.onCreateNewProfile)
        self.button_delete.Bind(wx.EVT_BUTTON, self.onDeleteProfile)
        self.button_save.Bind(wx.EVT_BUTTON, self.onSave)
        self.button_align_test.Bind(wx.EVT_BUTTON, self.onAlignTest)
        self.button_help.Bind(wx.EVT_BUTTON, self.onHelp)
        self.button_close.Bind(wx.EVT_BUTTON, self.onClose)

        # Right column buttons
        self.button_add_paths = wx.Button(self, label="Add path")
        self.button_remove_paths = wx.Button(self, label="Remove path")

        self.button_add_paths.Bind(wx.EVT_BUTTON, self.onAddDisplay)
        self.button_remove_paths.Bind(wx.EVT_BUTTON, self.onRemoveDisplay)

        self.sizer_paths_buttons.Add(self.button_add_paths, 0,
                                     wx.CENTER | wx.ALL, 5)
        self.sizer_paths_buttons.Add(self.button_remove_paths, 0,
                                     wx.CENTER | wx.ALL, 5)

        # Left add items
        self.sizer_left.Add(self.choice_profiles, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_apply, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_new, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_delete, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_save, 0, wx.CENTER | wx.ALL, 5)
        # self.sizer_left.Add(self.button_settings, 0, wx.CENTER|wx.ALL, 5)
        self.sizer_left.Add(self.button_align_test, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_help, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_left.Add(self.button_close, 0, wx.CENTER | wx.ALL, 5)

        # Right add items
        self.sizer_right.Add(self.sizer_grid_options, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_right.Add(self.sizer_paths, 0, wx.CENTER | wx.ALL, 5)
        self.sizer_right.Add(self.sizer_paths_buttons, 0, wx.CENTER | wx.ALL,
                             5)

        # Collect items at main sizer
        self.sizer_main.Add(self.sizer_left, 0, wx.CENTER | wx.EXPAND)
        self.sizer_main.Add(self.sizer_right, 0, wx.CENTER | wx.EXPAND)

        self.SetSizer(self.sizer_main)
        self.sizer_main.Fit(parent)