Exemple #1
0
 def category_remove(self, category):
     self.cat_widgets[category].destroy()
     del self.cat_widgets[category]
     self.menu_categories.delete(category)
     LATESTS.remove_section(category)
     cst.save_feeds()
     cst.save_latests()
Exemple #2
0
 def feed_manage(self):
     dialog = Manager(self)
     self.wait_window(dialog)
     self.update_idletasks()
     cst.save_latests()
     if dialog.change_made:
         cst.save_feeds()
         self.feed_update()
Exemple #3
0
 def _check_end_update(self):
     b = [t.is_alive() for t in self.threads.values() if t is not None]
     if sum(b):
         self._check_end_update_id = self.after(1000,
                                                self._check_end_update)
     else:
         cst.save_feeds()
         for widget in self.cat_widgets.values():
             widget.sort()
         self._update_id = self.after(
             CONFIG.getint("General", "update_delay"), self.feed_update)
Exemple #4
0
    def feed_rename(self, old_name, new_name):
        options = {
            opt: FEEDS.get(old_name, opt)
            for opt in FEEDS.options(old_name)
        }
        FEEDS.remove_section(old_name)
        try:
            # check if feed's title already exists
            FEEDS.add_section(new_name)
        except configparser.DuplicateSectionError:
            i = 2
            duplicate = True
            while duplicate:
                # increment i until new_name~#i does not already exist
                try:
                    FEEDS.add_section("{}~#{}".format(new_name, i))
                except configparser.DuplicateSectionError:
                    i += 1
                else:
                    duplicate = False
                    name = "{}~#{}".format(new_name, i)
        else:
            name = new_name
        logging.info("Renamed feed '%s' to '%s'", old_name, name)
        for opt, val in options.items():
            FEEDS.set(name, opt, val)
        self._check_result_init_id[name] = self._check_result_init_id.pop(
            old_name, '')
        self._check_result_update_id[name] = self._check_result_update_id.pop(
            old_name, '')
        self.threads[name] = self.threads.pop(old_name, None)
        self.queues[name] = self.queues.pop(old_name)
        self.feed_widgets[name] = self.feed_widgets.pop(old_name)
        self.feed_widgets[name].rename_feed(name)
        self.cat_widgets['All'].rename_feed(old_name, name)
        category = FEEDS.get(name, 'category', fallback='')
        if category != '':
            self.cat_widgets[category].rename_feed(old_name, name)
        self.menu_feeds.delete(old_name)
        self.menu_feeds.add_checkbutton(
            label=name, command=lambda: self.toggle_feed_widget(name))
        trace_info = cst.info_trace(self.feed_widgets[name].variable)
        if trace_info:
            cst.remove_trace(self.feed_widgets[name].variable, 'write',
                             trace_info[0][1])
        cst.add_trace(self.feed_widgets[name].variable, 'write',
                      lambda *args: self.feed_widget_trace(name))
        self.menu_feeds.set_item_value(name,
                                       self.feed_widgets[name].variable.get())

        cst.save_feeds()
        return name
Exemple #5
0
 def feed_set_active(self, title, active):
     FEEDS.set(title, 'active', str(active))
     cst.save_feeds()
     cat = FEEDS.get(title, 'category', fallback='')
     if active:
         self.menu_feeds.enable_item(title)
         if FEEDS.getboolean(title, 'visible'):
             self.feed_widgets[title].deiconify()
         if cat != '':
             self.cat_widgets[cat].show_feed(title)
         self.cat_widgets['All'].show_feed(title)
         self._feed_update(title)
     else:
         self.menu_feeds.disable_item(title)
         self.feed_widgets[title].withdraw()
         if cat != '':
             self.cat_widgets[cat].hide_feed(title)
         self.cat_widgets['All'].hide_feed(title)
Exemple #6
0
            s = Style(root)
            s.theme_use("clam")
            logging.error("%s is already running", APP_NAME)
            showerror(
                _("Error"),
                _("{app_name} is already running, if not delete ~/.feedagregator/feedagregator.pid."
                  ).format(app_name=APP_NAME))
            sys.exit()
        else:
            # it is an old pid file
            os.remove(PIDFILE)
    else:
        # it is an old pid file
        os.remove(PIDFILE)

open(PIDFILE, 'w').write(pid)

try:
    app = App()
    app.mainloop()
except Exception as e:
    logging.exception(str(type(e)))
    showerror(_("Error"), str(type(e)), traceback.format_exc(), True)
finally:
    save_config()
    save_feeds()
    save_latests()
    os.unlink(PIDFILE)
    logging.info('Closing %s', APP_NAME)
    logging.shutdown()
Exemple #7
0
 def _check_result_init(self, title):
     if self.threads[title].is_alive():
         self._check_result_init_id[title] = self.after(
             1000, self._check_result_init, title)
     else:
         t, latest, updated, data = self.queues[title].get()
         if not t:
             if cst.internet_on():
                 run([
                     "notify-send", "-i", "dialog-error",
                     _("Error"),
                     _('{url} is not a valid feed.').format(
                         url=FEEDS.get(title, 'url'))
                 ])
                 logging.error('%s is not a valid feed.',
                               FEEDS.get(title, 'url'))
             else:
                 if self._notify_no_internet:
                     run([
                         "notify-send", "-i", "dialog-error",
                         _("Error"),
                         _('No Internet connection.')
                     ])
                     logging.warning('No Internet connection')
                     self._notify_no_internet = False
                     self._internet_id = self.after(30000,
                                                    self.test_connection)
                 after_ids = [
                     self._update_id, self._check_add_id,
                     self._check_end_update_id, self._update_id
                 ]
                 after_ids.extend(self._check_result_update_id.values())
                 after_ids.extend(self._check_result_init_id.values())
                 for after_id in after_ids:
                     try:
                         self.after_cancel(after_id)
                     except ValueError:
                         pass
         else:
             date = datetime.strptime(updated, '%Y-%m-%d %H:%M')
             if (date > datetime.strptime(FEEDS.get(title, 'updated'),
                                          '%Y-%m-%d %H:%M')
                     or not FEEDS.has_option(title, 'data')):
                 if CONFIG.getboolean("General",
                                      "notifications",
                                      fallback=True):
                     run([
                         "notify-send", "-i", cst.IM_ICON_SVG, title,
                         cst.html2text(latest)
                     ])
                 FEEDS.set(title, 'updated', updated)
                 category = FEEDS.get(title, 'category', fallback='')
                 self.cat_widgets['All'].update_display(
                     title, latest, updated)
                 if category != '':
                     self.cat_widgets[category].update_display(
                         title, latest, updated)
                 logging.info("Updated feed '%s'", title)
                 self.feed_widgets[title].clear()
                 for entry_title, date, summary, link in data:
                     self.feed_widgets[title].entry_add(
                         entry_title, date, summary, link, -1)
                 logging.info("Populated widget for feed '%s'", title)
                 self.feed_widgets[title].event_generate('<Configure>')
                 self.feed_widgets[title].sort_by_date()
                 try:
                     filename = FEEDS.get(title, 'data')
                 except configparser.NoOptionError:
                     filename = cst.new_data_file()
                     FEEDS.set(title, 'data', filename)
                     cst.save_feeds()
                 cst.save_data(filename, latest, data)
             else:
                 logging.info("Feed '%s' is up-to-date", title)
Exemple #8
0
 def _check_result_add(self, thread, queue, url, manager_queue=None):
     if thread.is_alive():
         self._check_add_id = self.after(1000, self._check_result_add,
                                         thread, queue, url, manager_queue)
     else:
         title, latest, date, data = queue.get(False)
         if title:
             try:
                 # check if feed's title already exists
                 FEEDS.add_section(title)
             except configparser.DuplicateSectionError:
                 i = 2
                 duplicate = True
                 while duplicate:
                     # increment i until title~#i does not already exist
                     try:
                         FEEDS.add_section("{}~#{}".format(title, i))
                     except configparser.DuplicateSectionError:
                         i += 1
                     else:
                         duplicate = False
                         name = "{}~#{}".format(title, i)
             else:
                 name = title
             if manager_queue is not None:
                 manager_queue.put(name)
             logging.info("Added feed '%s' %s", name, url)
             if CONFIG.getboolean("General", "notifications",
                                  fallback=True):
                 run([
                     "notify-send", "-i", cst.IM_ICON_SVG, name,
                     cst.html2text(latest)
                 ])
             self.cat_widgets['All'].entry_add(name, date, latest, url)
             filename = cst.new_data_file()
             cst.save_data(filename, latest, data)
             FEEDS.set(name, 'url', url)
             FEEDS.set(name, 'updated', date)
             FEEDS.set(name, 'data', filename)
             FEEDS.set(name, 'visible', 'True')
             FEEDS.set(name, 'geometry', '')
             FEEDS.set(name, 'position', 'normal')
             FEEDS.set(name, 'category', '')
             FEEDS.set(name, 'sort_is_reversed', 'False')
             FEEDS.set(name, 'active', 'True')
             cst.save_feeds()
             self.queues[name] = queue
             self.feed_widgets[name] = FeedWidget(self, name)
             self.menu_feeds.add_checkbutton(
                 label=name, command=lambda: self.toggle_feed_widget(name))
             cst.add_trace(self.feed_widgets[name].variable, 'write',
                           lambda *args: self.feed_widget_trace(name))
             self.feed_widgets[name].variable.set(True)
             for entry_title, date, summary, link in data:
                 self.feed_widgets[name].entry_add(entry_title, date,
                                                   summary, link, -1)
         else:
             if manager_queue is not None:
                 manager_queue.put('')
             if cst.internet_on():
                 logging.error('%s is not a valid feed.', url)
                 showerror(_('Error'),
                           _('{url} is not a valid feed.').format(url=url))
             else:
                 logging.warning('No Internet connection.')
                 showerror(_('Error'), _('No Internet connection.'))
Exemple #9
0
 def feed_widget_trace(self, title):
     value = self.feed_widgets[title].variable.get()
     self.menu_feeds.set_item_value(title, value)
     FEEDS.set(title, 'visible', str(value))
     cst.save_feeds()