def create_window(self, filename=None, template=None): """Creates a new strip and stores its configuration in the directory path.""" if filename is None: f, filename = tempfile.mkstemp('.strip', '', STRIPS_DIR, True) os.close(f) settings = Settings(filename) if template: settings.update(template) settings['cache-file'] = filename.rsplit('.', 1)[0] + '.cache' window = comics_view.ComicsViewer(self, settings, self.visible) self.windows.append(window) window.connect('removed', self.on_window_removed) window.connect('updated', self.on_window_updated) settings.save()
def toggle_feed(self, feed_name, visible): """Toggles a comic.""" if feed_name not in self.feeds.feeds: return if not visible: windows = [w for w in self.windows if w.feed_name == feed_name] if not windows: return for window in windows: window.close() window.destroy() else: template = Settings() template['feed_name'] = feed_name self.create_window(template=template)
def on_add_assistant_apply(self, widget): try: os.mkdir(USER_FEEDS_DIR) except Exception: pass if self.from_list: model, paths = self.sys_list.get_selection().get_selected_rows() for path in paths: self.name = model.get_value(model.get_iter(path), 0) src = model.get_value(model.get_iter(path), 1) filename = USER_FEEDS_DIR + src[len(SYS_FEEDS_DIR):] with open(src, 'r') as fp: src_content = fp.read() try: with open(filename, 'r') as fp: f = fp.read() except IOError: f = None if f: if cmp(src_content, f) == 0: continue msg = _("Overwrite comic \"%s\"?") % self.name sec = _( "This comic is already installed with different settings.") dialog = gtk.MessageDialog(parent=self.assistant, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_WARNING, message_format=msg) dialog.format_secondary_markup(sec) if path != paths[-1]: dialog.add_buttons( gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.add_buttons(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_NO: continue if response != gtk.RESPONSE_YES: return with open(filename, 'w') as fp: fp.write(src_content) self.feeds.add_feed(filename) self.feeds.update() self.__parent.toggle_feed(self.name, True) else: self.name = self.ui.get_object('name_entry').get_text() f, filename = tempfile.mkstemp('.feed', '', USER_FEEDS_DIR, True) os.close(f) settings = Settings(filename) settings.description = 'Automatically generated by comics' settings[NAME] = self.name settings[URL] = self.url settings[IMG_INDEX] = self.image[0] + 1 settings.comments[IMG_INDEX] = \ 'The index of the image in the HTML-code' if self.feed.__module__.startswith('feed.plugins.'): settings[PLUGIN] = self.feed.__module__[13:] settings.save() self.feeds.add_feed(filename) self.feeds.update() self.__parent.toggle_feed(self.name, True)
def on_add_assistant_apply(self, widget): try: os.mkdir(USER_FEEDS_DIR) except Exception: pass if self.from_list: model, paths = self.sys_list.get_selection().get_selected_rows() for path in paths: self.name = model.get_value(model.get_iter(path), 0) src = model.get_value(model.get_iter(path), 1) filename = USER_FEEDS_DIR + src[len(SYS_FEEDS_DIR):] with open(src, 'r') as fp: src_content = fp.read() try: with open(filename, 'r') as fp: f = fp.read() except IOError: f = None if f: if cmp(src_content, f) == 0: continue msg = _("Overwrite comic \"%s\"?") % self.name sec = _( "This comic is already installed with different settings." ) dialog = gtk.MessageDialog( parent=self.assistant, flags=gtk.DIALOG_DESTROY_WITH_PARENT, type=gtk.MESSAGE_WARNING, message_format=msg) dialog.format_secondary_markup(sec) if path != paths[-1]: dialog.add_buttons(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) dialog.add_buttons(gtk.STOCK_NO, gtk.RESPONSE_NO, gtk.STOCK_YES, gtk.RESPONSE_YES) response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_NO: continue if response != gtk.RESPONSE_YES: return with open(filename, 'w') as fp: fp.write(src_content) self.feeds.add_feed(filename) self.feeds.update() self.__parent.toggle_feed(self.name, True) else: self.name = self.ui.get_object('name_entry').get_text() f, filename = tempfile.mkstemp('.feed', '', USER_FEEDS_DIR, True) os.close(f) settings = Settings(filename) settings.description = 'Automatically generated by comics' settings[NAME] = self.name settings[URL] = self.url settings[IMG_INDEX] = self.image[0] + 1 settings.comments[IMG_INDEX] = \ 'The index of the image in the HTML-code' if self.feed.__module__.startswith('feed.plugins.'): settings[PLUGIN] = self.feed.__module__[13:] settings.save() self.feeds.add_feed(filename) self.feeds.update() self.__parent.toggle_feed(self.name, True)