def __init__(self, options={}): self.__main_gui = None self.__notifier = notify2.Notification('dnfdragora', '', 'dnfdragora') self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings : settings = {} if 'settings' in self.__config.systemSettings.keys() : settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys() : self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys() : settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys() : self.__updateInterval = int(settings['interval for checking updates']) # if missing gets the default icon from our folder (same as dnfdragora) icon_path = '/usr/share/dnfdragora/images/' if 'icon-path' in options.keys() : icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' theme_icon_pathname = self.__get_theme_icon_pathname() or icon_path print("Icon: %s"%(theme_icon_pathname)) #empty icon as last chance self.__icon = Image.Image() try: if theme_icon_pathname.endswith('.svg'): with open(theme_icon_pathname, 'rb') as svg: self.__icon = self.__svg_to_Image(svg.read()) else: self.__icon = Image.open(theme_icon_pathname) except Exception as e: print(e) print("Cannot open theme icon using default one %s"%(icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown) ) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def __init__(self, options={}): self.__main_gui = None self.__notifier = notify2.Notification('dnfdragora', '', 'dnfdragora') self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' issue_82_workaround_icon_path = icon_path try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() issue_82_workaround_test = Image.open( icon_path ) #Apperantly PIL (or Pillow?) doesn't support svg icons. If the filetype isn't supported an exception will be thrown except: icon_path = issue_82_workaround_icon_path # Use backup icon path. print("icon %s" % (icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def __init__(self, options={}): self.__main_gui = None self.__notifier = sh.Command("/usr/bin/notify-send") self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.png' try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() except: pass print("icon %s" % (icon_path)) self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def __init__(self): self.__main_gui = None self.__notifier = sh.Command("/usr/bin/notify-send") self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 if self.__config.systemSettings: settings = {} if 'settings' in self.__config.systemSettings.keys(): settings = self.__config.systemSettings['settings'] if 'update_interval' in settings.keys(): self.__updateInterval = int(settings['update_interval']) if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) icon_path = '/usr/share/icons/hicolor/128x128/apps/dnfdragora.png' try: self.__backend = dnfdaemon.client.Client() except dnfdaemon.client.DaemonError as error: print(_('Error starting dnfdaemon service: [%s]'), str(error)) sys.exit(1) try: from gi.repository import Gtk icon_theme = Gtk.IconTheme.get_default() icon_path = icon_theme.lookup_icon("dnfdragora", 128, 0).get_filename() except: pass self.__icon = Image.open(icon_path) self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__get_updates_forced), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, self.__icon, self.__name, self.__menu)
def __init__(self, options={}): self.__main_gui = None self.__config = config.AppConfig('dnfdragora') self.__updateInterval = 180 self.__update_count = -1 self.__log_enabled = False self.__log_directory = None self.__level_debug = False self.__hide_menu = True if self.__config.userPreferences: if 'settings' in self.__config.userPreferences.keys(): settings = self.__config.userPreferences['settings'] if 'interval for checking updates' in settings.keys(): self.__updateInterval = int( settings['interval for checking updates']) self.__hide_menu = settings['hide_update_menu'] if 'hide_update_menu' in settings.keys() \ else False #### Logging if 'log' in settings.keys(): log = settings['log'] if 'enabled' in log.keys(): self.__log_enabled = log['enabled'] if self.__log_enabled: if 'directory' in log.keys(): self.__log_directory = log['directory'] if 'level_debug' in log.keys(): self.__level_debug = log['level_debug'] if self.__log_enabled: if self.__log_directory: log_filename = os.path.join(self.__log_directory, "dnfdragora-updater.log") if self.__level_debug: misc.logger_setup(log_filename, loglvl=logging.DEBUG) else: misc.logger_setup(log_filename) print("Logging into %s, debug mode is %s" % (self.__log_directory, ("enabled" if self.__level_debug else "disabled"))) logger.info("dnfdragora-updater started") else: print("Logging disabled") # if missing gets the default icon from our folder (same as dnfdragora) icon_path = '/usr/share/dnfdragora/images/' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora.svg' if (os.path.exists( icon_path + 'dnfdragora.svg')) else icon_path + 'dnfdragora.png' else: icon_path = icon_path + '/dnfdragora.svg' if (os.path.exists( icon_path + '/dnfdragora.svg')) else icon_path + '/dnfdragora.png' theme_icon_pathname = icon_path if 'icon-path' in options.keys( ) else self.__get_theme_icon_pathname() or icon_path logger.debug("Icon: %s" % (theme_icon_pathname)) #empty icon as last chance self.__icon = Image.Image() try: if theme_icon_pathname.endswith('.svg'): with open(theme_icon_pathname, 'rb') as svg: self.__icon = self.__svg_to_Image(svg.read()) else: self.__icon = Image.open(theme_icon_pathname) except Exception as e: logger.error(e) logger.error("Cannot open theme icon using default one %s" % (icon_path)) self.__icon = Image.open(icon_path) # resetting icon_path to default value icon_path = '/usr/share/dnfdragora/images/' if 'icon-path' in options.keys(): icon_path = options['icon-path'] if icon_path.endswith('/'): icon_path = icon_path + 'dnfdragora-update.svg' if ( os.path.exists(icon_path + 'dnfdragora-update.svg') ) else icon_path + 'dnfdragora-update.png' else: icon_path = icon_path + '/dnfdragora-update.svg' if ( os.path.exists(icon_path + '/dnfdragora-update.svg') ) else icon_path + '/dnfdragora-update.png' theme_icon_pathname = icon_path if 'icon-path' in options.keys( ) else self.__get_theme_icon_pathname( name="dnfdragora-update") or icon_path self.__icon_update = Image.Image() try: if theme_icon_pathname.endswith('.svg'): with open(theme_icon_pathname, 'rb') as svg: self.__icon_update = self.__svg_to_Image(svg.read()) else: self.__icon_update = Image.open(theme_icon_pathname) except Exception as e: logger.error(e) logger.error("Cannot open theme icon using default one %s" % (icon_path)) self.__icon_update = Image.open(icon_path) try: self.__backend = dnfd_client.Client() except dnfdaemon.client.DaemonError as error: logger.error( _('Error starting dnfdaemon service: [%s]') % (str(error))) return except Exception as e: logger.error( _('Error starting dnfdaemon service: [%s]') % (str(e))) return self.__running = True self.__updater = threading.Thread(target=self.__update_loop) self.__scheduler = sched.scheduler(time.time, time.sleep) self.__getUpdatesRequested = False self.__menu = Menu( MenuItem(_('Update'), self.__run_update), MenuItem(_('Open dnfdragora dialog'), self.__run_dnfdragora), MenuItem(_('Check for updates'), self.__check_updates), MenuItem(_('Exit'), self.__shutdown)) self.__name = 'dnfdragora-updater' self.__tray = Tray(self.__name, icon=self.__icon, title=self.__name, menu=self.__menu)