def on_find_response(self, response): # get find options find_text = unicode_gtk(self.find_xml.get_widget("text_entry").get_text()) replace_text = unicode_gtk(self.find_xml.get_widget("replace_entry").get_text()) case_sensitive = self.find_xml.get_widget("case_sensitive_button").get_active() search_forward = self.find_xml.get_widget("forward_button").get_active() self.find_text = find_text self.replace_text = replace_text next = (self.find_last_pos != -1) if response == "close": self.find_dialog.destroy() self.find_dialog = None elif response == "find": self.find_last_pos = self.editor.get_textview().find(find_text, case_sensitive, search_forward, next) elif response == "find_next": self.find_xml.get_widget("forward_button").set_active(True) self.find_last_pos = self.editor.get_textview().find(find_text, case_sensitive, True) elif response == "find_prev": self.find_xml.get_widget("backward_button").set_active(True) self.find_last_pos = self.editor.get_textview().find(find_text, case_sensitive, False) elif response == "replace": self.find_last_pos = self.editor.get_textview().replace(find_text, replace_text, case_sensitive, search_forward) elif response == "replace_all": self.editor.get_textview().replace_all(find_text, replace_text, case_sensitive, search_forward)
def save(self): """Save the loaded page""" if (self._page is not None and self._page.is_valid() and (SourceView or self._textview.is_modified())): try: # save text data buf = self._textview.get_buffer() text = unicode_gtk( buf.get_text(buf.get_start_iter(), buf.get_end_iter())) #out = safefile.open( # os.path.join(self._page.get_path(), # self._page.get_attr("payload_filename")), "w", # codec="utf-8") out = self._page.open_file( self._page.get_attr("payload_filename"), "w", "utf-8") out.write(text) out.close() # save meta data self._page.set_attr_timestamp("modified_time") self._page.save() except RichTextError, e: self.emit("error", e.msg, e) except NoteBookError, e: self.emit("error", e.msg, e)
def save(self): """Save the loaded page""" if self._page is not None and self._page.is_valid() and (SourceView or self._textview.is_modified()): try: # save text data buf = self._textview.get_buffer() text = unicode_gtk(buf.get_text(buf.get_start_iter(), buf.get_end_iter())) # out = safefile.open( # os.path.join(self._page.get_path(), # self._page.get_attr("payload_filename")), "w", # codec="utf-8") out = self._page.open_file(self._page.get_attr("payload_filename"), "w", "utf-8") out.write(text) out.close() # save meta data self._page.set_attr_timestamp("modified_time") self._page.save() except RichTextError, e: self.emit("error", e.msg, e) except NoteBookError, e: self.emit("error", e.msg, e)
def on_icon_open_set_button_clicked(self, widget): """Callback for browse open icon file""" filename = unicode_gtk(self.icon_open_entry.get_text()) filename = browse_file(self.dialog, _("Choose Open Icon"), filename) if filename: # set filename and preview self.set_icon("icon_open", filename)
def on_edit_attr(self, cellrenderertext, path, attr, new_text, validator=TextRendererValidator()): """Callback for completion of title editing""" # remember editing state self.editing_path = None new_text = unicode_gtk(new_text) # get node being edited node = self.model.get_value(self.model.get_iter(path), self._node_col) if node is None: return # determine value from new_text, if invalid, ignore it try: new_val = validator.parse(new_text) except: return # set new attr and catch errors try: node.set_attr(attr, new_val) except NoteBookError, e: self.emit("error", e.msg, e)
def on_export_notebook(self, window, notebook): """Callback from gui for exporting a notebook""" if notebook is None: return dialog = FileChooserDialog("Export Notebook", window, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Export", gtk.RESPONSE_OK), app=self.app, persistent_path="archive_notebook_path") basename = time.strftime( os.path.basename(notebook.get_path()) + "-%Y-%m-%d") path = self.app.get_default_path("archive_notebook_path") if path and os.path.exists(path): filename = notebooklib.get_unique_filename(path, basename, "", ".") else: filename = basename dialog.set_current_name(os.path.basename(filename)) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() self.export_notebook(notebook, filename, window=window) else: dialog.destroy()
def save(self): """Save the loaded page""" if self._page is not None and \ self._page.is_valid() and \ self._textview.is_modified(): try: # save text data buf = self._textview.get_buffer() text = unicode_gtk(buf.get_text(buf.get_start_iter(), buf.get_end_iter())) out = self._page.open_file( self._page.get_attr("payload_filename"), "w", "utf-8") out.write(text) out.close() # save meta data self._page.set_attr_timestamp("modified_time") self._page.save() except RichTextError as e: self.emit("error", e.msg, e) except NoteBookError as e: self.emit("error", e.msg, e) except Exception as e: self.emit("error", str(e), e)
def run(self): response = gtk.FileChooserDialog.run(self) if response == gtk.RESPONSE_OK and self._app and self._persistent_path: self._app.set_default_path(self._persistent_path, unicode_gtk(self.get_current_folder())) return response
def browse_file(parent, title, filename=None): """Callback for selecting file browser""" dialog = gtk.FileChooserDialog(title, parent, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(_("Cancel"), gtk.RESPONSE_CANCEL, _("Open"), gtk.RESPONSE_OK)) dialog.set_transient_for(parent) dialog.set_modal(True) # set the filename if it is fully specified if filename and os.path.isabs(filename): dialog.set_filename(filename) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) else: filename = None dialog.destroy() return filename
def on_export_notebook(self, window, notebook): """Callback from gui for exporting a notebook""" if notebook is None: return dialog = FileChooserDialog("Export Notebook", window, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Export", gtk.RESPONSE_OK), app=self.app, persistent_path="archive_notebook_path") basename = time.strftime(os.path.basename(notebook.get_path()) + "-%Y-%m-%d") path = self.app.get_default_path("archive_notebook_path") if path and os.path.exists(path): filename = notebooklib.get_unique_filename( path, basename, "", ".") else: filename = basename dialog.set_current_name(os.path.basename(filename)) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() self.export_notebook(notebook, filename, window=window) else: dialog.destroy()
def on_import_folder_tree(self, window, notebook): """Callback from gui for importing a folder tree""" # Ask the window for the currently selected nodes nodes = window.get_selected_nodes() print nodes if len(nodes) == 0: return node = nodes[0] dialog = FileChooserDialog( "Attach Folder", window, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Attach Folder", gtk.RESPONSE_OK)) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() self.import_folder_tree(node, filename, window=window) else: dialog.destroy()
def on_edit_attr(self, cellrenderertext, path, attr, new_text, validator=TextRendererValidator()): """Callback for completion of title editing""" # remember editing state self.editing_path = None new_text = unicode_gtk(new_text) # get node being edited node = self.model.get_value(self.model.get_iter(path), self._node_col) if node is None: return # determine value from new_text, if invalid, ignore it try: new_val = validator.parse(new_text) except: return # set new attr and catch errors try: node.set_attr(attr, new_val) except NoteBookError as e: self.emit("error", e.msg, e) # reselect node # need to get path again because sorting may have changed path = get_path_from_node(self.model, node, self.rich_model.get_node_column_pos()) if path is not None: self.set_cursor(path) gobject.idle_add(lambda: self.scroll_to_cell(path)) self.emit("edit-node", node, attr, new_val)
def browse_file(parent, title, filename=None): """Callback for selecting file browser""" dialog = gtk.FileChooserDialog( title, parent, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(_("Cancel"), gtk.RESPONSE_CANCEL, _("Open"), gtk.RESPONSE_OK)) dialog.set_transient_for(parent) dialog.set_modal(True) # set the filename if it is fully specified if filename and os.path.isabs(filename): dialog.set_filename(filename) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) else: filename = None dialog.destroy() return filename
def update_completion(self): text = unicode_gtk(self.url_text.get_text()) self._liststore.clear() if self.search_nodes and len(text) > 0: results = self.search_nodes(text)[:10] for nodeid, title in results: self._liststore.append([title, nodeid])
def save_options(self, app): # save date formatting for name in ["same_day", "same_month", "same_year", "diff_year"]: app.pref.set( "timestamp_formats", name, unicode_gtk( self.date_xml.get_widget("date_%s_entry" % name).get_text()))
def run(self): response = gtk.FileChooserDialog.run(self) if (response == gtk.RESPONSE_OK and self._app and self._persistent_path): self._app.set_default_path(self._persistent_path, unicode_gtk(self.get_current_folder())) return response
def save_options(self, app): # TODO: use a public interface # save external app options for key, entry in self.entries.iteritems(): ext_app = app.get_external_app(key) if ext_app: ext_app.prog = unicode_gtk(entry.get_text())
def on_select_changed(self, treeselect): if not self._cursor_move: model, sel = self._link_picker.get_selection().get_selected() if sel: icon, title, nodeid = model[sel] self.emit("pick-link", unicode_gtk(title), nodeid) self._cursor_move = False
def get_iconview_selection(self): """Return the currently selected icon""" for iconview, iconlist in zip(self.iconviews, self.iconlists): for path in iconview.get_selected_items(): it = iconlist.get_iter(path) icon = iconlist.get_value(it, 0) iconfile = unicode_gtk(iconlist.get_value(it, 1)) return iconview, icon, iconfile return None, None, None
def get_icon_filename(self, name, default=None): if name is None or self.theme is None: return default size = 16 info = self.theme.lookup_icon(name, size, 0) if info: return unicode_gtk(info.get_filename()) else: return default
def on_find_response(self, response): # get find options find_text = unicode_gtk( self.find_xml.get_widget("text_entry").get_text()) replace_text = unicode_gtk( self.find_xml.get_widget("replace_entry").get_text()) case_sensitive = self.find_xml.get_widget( "case_sensitive_button").get_active() search_forward = self.find_xml.get_widget( "forward_button").get_active() self.find_text = find_text self.replace_text = replace_text next = (self.find_last_pos != -1) if response == "close": self.find_dialog.destroy() self.find_dialog = None elif response == "find": self.find_last_pos = self.editor.get_textview().find( find_text, case_sensitive, search_forward, next) elif response == "find_next": self.find_xml.get_widget("forward_button").set_active(True) self.find_last_pos = self.editor.get_textview().find( find_text, case_sensitive, True) elif response == "find_prev": self.find_xml.get_widget("backward_button").set_active(True) self.find_last_pos = self.editor.get_textview().find( find_text, case_sensitive, False) elif response == "replace": self.find_last_pos = self.editor.get_textview().replace( find_text, replace_text, case_sensitive, search_forward) elif response == "replace_all": self.editor.get_textview().replace_all(find_text, replace_text, case_sensitive, search_forward)
def set_url(self): if self.textview is None: return url = unicode_gtk(self.url_text.get_text()) tag, start, end = self.textview.get_link() if start is not None: if url == "": self.textview.set_link(None, start, end) elif tag.get_href() != url: self.textview.set_link(url, start, end)
def on_archive_notebook(self, window, notebook): """Callback from gui for archiving a notebook""" if notebook is None: return dialog = FileChooserDialog( "Backup Notebook", window, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Backup", gtk.RESPONSE_OK), app=self.app, persistent_path="archive_notebook_path") path = self.app.get_default_path("archive_notebook_path") if os.path.exists(path): filename = notebooklib.get_unique_filename( path, os.path.basename(notebook.get_path()) + time.strftime("-%Y-%m-%d"), ".tar.gz", ".") else: filename = os.path.basename(notebook.get_path()) + \ time.strftime("-%Y-%m-%d") + u".tar.gz" dialog.set_current_name(os.path.basename(filename)) file_filter = gtk.FileFilter() file_filter.add_pattern("*.tar.gz") file_filter.set_name("Archives (*.tar.gz)") dialog.add_filter(file_filter) file_filter = gtk.FileFilter() file_filter.add_pattern("*") file_filter.set_name("All files (*.*)") dialog.add_filter(file_filter) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() if u"." not in filename: filename += u".tar.gz" window.set_status("Archiving...") return self.archive_notebook(notebook, filename, window) elif response == gtk.RESPONSE_CANCEL: dialog.destroy() return False
def save_options(self, app): # TODO: use a public interface # save external app options apps = app.pref.get("external_apps", default=[]) for app in apps: key = app.get("key", None) if key: entry = self.entries.get(key, None) if entry: app["prog"] = unicode_gtk(entry.get_text())
def save_options(self, app): if self.xml.get_widget("last_notebook_radio").get_active(): app.pref.set("use_last_notebook", True) elif self.xml.get_widget("default_notebook_radio").get_active(): app.pref.set("use_last_notebook", False) app.pref.set("default_notebooks", [unicode_gtk( self.xml.get_widget( "default_notebook_entry").get_text())]) else: app.pref.set("use_last_notebook", False) app.pref.set("default_notebooks", []) # save autosave app.pref.set("autosave", self.xml.get_widget("autosave_check").get_active()) try: app.pref.set( "autosave_time", int(self.xml.get_widget("autosave_entry").get_text()) * 1000) except: pass # use systray icon app.pref.set("window", "use_systray", self.xml.get_widget("systray_check").get_active()) app.pref.set("window", "skip_taskbar", self.xml.get_widget("skip_taskbar_check").get_active()) app.pref.set( "window", "minimize_on_start", self.xml.get_widget("minimize_on_start_check").get_active()) # window 'always above' app.pref.set( "window", "keep_above", self.xml.get_widget("window_keep_above_check").get_active()) # window 'stick to all desktops' app.pref.set( "window", "stick", self.xml.get_widget("window_stick_check").get_active()) app.pref.set( "use_fulltext_search", self.xml.get_widget("use_fulltext_check").get_active())
def backup(self, notebook_filename): dialog = FileChooserDialog( _("Choose Backup Notebook Name"), self.main_window, action=gtk.FILE_CHOOSER_ACTION_SAVE, #CREATE_FOLDER, buttons=(_("Cancel"), gtk.RESPONSE_CANCEL, _("Backup"), gtk.RESPONSE_OK), app=self.app, persistent_path="new_notebook_path") response = dialog.run() new_filename = dialog.get_filename() dialog.destroy() if response == gtk.RESPONSE_OK and new_filename: new_filename = unicode_gtk(new_filename) def func(task): try: shutil.copytree(notebook_filename, new_filename) except Exception as e: print(e, file=sys.stderr) print("'%s' '%s'" % (notebook_filename, new_filename), file=sys.stderr) raise task = tasklib.Task(func) dialog2 = dialog_wait.WaitDialog(self.dialog) dialog2.show(_("Backing Up Notebook"), _("Backing up old notebook..."), task, cancel=False) # handle errors if task.aborted(): ty, err, tb = task.exc_info() if err: self.main_window.error(_("Error occurred during backup."), err, tb) else: self.main_window.error(_("Backup canceled.")) return False return True
def on_key_press_event(self, widget, event): """Callback for key press events""" model, sel = self._link_picker.get_selection().get_selected() if event.keyval == gtk.keysyms.Down: # move selection down self._cursor_move = True if sel is None: self._link_picker.set_cursor((0,)) else: i = model.get_path(sel)[0] n = model.iter_n_children(None) if i < n - 1: self._link_picker.set_cursor((i+1,)) return True elif event.keyval == gtk.keysyms.Up: # move selection up self._cursor_move = True if sel is None: n = model.iter_n_children(None) self._link_picker.set_cursor((n-1,)) else: i = model.get_path(sel)[0] if i > 0: self._link_picker.set_cursor((i-1,)) return True elif event.keyval == gtk.keysyms.Return: # accept selection if sel: icon, title, nodeid = model[sel] self.emit("pick-link", unicode_gtk(title), nodeid) return True elif event.keyval == gtk.keysyms.Escape: # discard popup self.set_links([]) return False
def on_text2nodes(self, window): """Callback from gui for text2nodes""" # Assert focus is textview # Assert textview has selected text # Get current node # For each line of selected text create child page #nb = window.get_notebook() widget = self._widget_focus.get(window, None) if not isinstance(widget, gtk.TextView): keepnote.log_error("T2N: focus") return # For testing simply duplicate at end of page #eop = buf.get_end_iter() #buf.insert(eop, '\n>>>PAGE END\n') #return buf = widget.get_buffer() bounds = buf.get_selection_bounds() if not bounds: return txt = unicode_gtk(buf.get_text(bounds[0], bounds[1])) # Ask the window for the currently selected nodes nodes = window.get_selected_nodes() if len(nodes) == 0: return node = nodes[0] task = tasklib.Task() # For testing simply duplicate at end of page for title in txt.splitlines(): title = title.strip() if title != '': #eop = buf.get_end_iter() #buf.insert(eop, '\n>>>\n'+txt) self.make_page(node, title, '') task.finish()
def save_options(self, app): if self.xml.get_widget("last_notebook_radio").get_active(): app.pref.set("use_last_notebook", True) elif self.xml.get_widget("default_notebook_radio").get_active(): app.pref.set("use_last_notebook", False) app.pref.set("default_notebooks", [ unicode_gtk( self.xml.get_widget("default_notebook_entry").get_text()) ]) else: app.pref.set("use_last_notebook", False) app.pref.set("default_notebooks", []) # save autosave app.pref.set("autosave", self.xml.get_widget("autosave_check").get_active()) try: app.pref.set( "autosave_time", int(self.xml.get_widget("autosave_entry").get_text()) * 1000) except: pass # use systray icon app.pref.set("window", "use_systray", self.xml.get_widget("systray_check").get_active()) app.pref.set("window", "skip_taskbar", self.xml.get_widget("skip_taskbar_check").get_active()) app.pref.set( "window", "minimize_on_start", self.xml.get_widget("minimize_on_start_check").get_active()) # window 'always above' app.pref.set( "window", "keep_above", self.xml.get_widget("window_keep_above_check").get_active()) # window 'stick to all desktops' app.pref.set("window", "stick", self.xml.get_widget("window_stick_check").get_active()) app.pref.set("use_fulltext_search", self.xml.get_widget("use_fulltext_check").get_active())
def backup(self, notebook_filename): dialog = FileChooserDialog( _("Choose Backup Notebook Name"), self.main_window, action=gtk.FILE_CHOOSER_ACTION_SAVE, #CREATE_FOLDER, buttons=(_("Cancel"), gtk.RESPONSE_CANCEL, _("Backup"), gtk.RESPONSE_OK), app=self.app, persistent_path="new_notebook_path") response = dialog.run() new_filename = dialog.get_filename() dialog.destroy() if response == gtk.RESPONSE_OK and new_filename: new_filename = unicode_gtk(new_filename) def func(task): try: shutil.copytree(notebook_filename, new_filename) except Exception, e: print >>sys.stderr, e print >>sys.stderr, "'%s' '%s'" % (notebook_filename, new_filename) raise task = tasklib.Task(func) dialog2 = dialog_wait.WaitDialog(self.dialog) dialog2.show(_("Backing Up Notebook"), _("Backing up old notebook..."), task, cancel=False) # handle errors if task.aborted(): ty, err, tb = task.exc_info() if err: self.main_window.error(_("Error occurred during backup."), err, tb) else: self.main_window.error(_("Backup canceled.")) return False
def on_make_catalog(self, window, notebook, widget="focus"): """Callback from gui for making a catalog tree""" if notebook is None: return dialog = FileChooserDialog( "Make Catalog", window, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Make Catalog", gtk.RESPONSE_OK)) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() self.make_catalog(notebook, filename, window=window, widget=widget) else: dialog.destroy()
def on_edit_title(self, cellrenderertext, path, new_text): """Callback for completion of title editing""" # remember editing state self.editing = None new_text = unicode_gtk(new_text) # get node being edited node = self.model.get_value(self.model.get_iter(path), self._node_col) if node is None: return # do not allow empty names if new_text.strip() == "": return # set new title and catch errors if new_text != node.get_title(): try: node.rename(new_text) except NoteBookError, e: self.emit("error", e.msg, e)
def on_import_folder_tree(self, window, notebook): """Callback from gui for importing a folder tree""" # Ask the window for the currently selected nodes nodes = window.get_selected_nodes() if len(nodes) == 0: return node = nodes[0] dialog = FileChooserDialog( "Attach Folder", window, action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Attach Folder", gtk.RESPONSE_OK)) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): filename = unicode_gtk(dialog.get_filename()) dialog.destroy() self.import_folder_tree(node, filename, window=window) else: dialog.destroy()
def save_options(self, app): # save date formatting for name in ["same_day", "same_month", "same_year", "diff_year"]: app.pref.set("timestamp_formats", name, unicode_gtk( self.date_xml.get_widget("date_%s_entry" % name).get_text()))
def on_restore_notebook(self, window): """Callback from gui for restoring a notebook from an archive""" dialog = FileChooserDialog( "Chose Archive To Restore", window, action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=("Cancel", gtk.RESPONSE_CANCEL, "Restore", gtk.RESPONSE_OK), app=self.app, persistent_path="archive_notebook_path") file_filter = gtk.FileFilter() file_filter.add_pattern("*.tar.gz") file_filter.set_name("Archive (*.tar.gz)") dialog.add_filter(file_filter) file_filter = gtk.FileFilter() file_filter.add_pattern("*") file_filter.set_name("All files (*.*)") dialog.add_filter(file_filter) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): archive_filename = unicode_gtk(dialog.get_filename()) dialog.destroy() elif response == gtk.RESPONSE_CANCEL: dialog.destroy() return # choose new notebook name dialog = FileChooserDialog( "Choose New Notebook Name", window, action=gtk.FILE_CHOOSER_ACTION_SAVE, buttons=("Cancel", gtk.RESPONSE_CANCEL, "New", gtk.RESPONSE_OK), app=self.app, persistent_path="new_notebook_path") file_filter = gtk.FileFilter() file_filter.add_pattern("*.nbk") file_filter.set_name("Notebook (*.nbk)") dialog.add_filter(file_filter) file_filter = gtk.FileFilter() file_filter.add_pattern("*.tar.gz") file_filter.set_name("Archives (*.tar.gz)") dialog.add_filter(file_filter) file_filter = gtk.FileFilter() file_filter.add_pattern("*") file_filter.set_name("All files (*.*)") dialog.add_filter(file_filter) response = dialog.run() if response == gtk.RESPONSE_OK and dialog.get_filename(): notebook_filename = unicode_gtk(dialog.get_filename()) dialog.destroy() window.set_status("Restoring...") self.restore_notebook(archive_filename, notebook_filename, window) elif response == gtk.RESPONSE_CANCEL: dialog.destroy()
def func(model, path, it, user_data): icons.append(unicode_gtk(self.notebook_iconlist.get_value(it, 1)))
def show(self, node=None, window=None): # TODO: factor out main_window.get_notebook() calls self.main_window = window self.node = node self.xml = gtk.glade.XML( keepnote.gui.get_resource("rc", "keepnote.glade"), "node_icon_dialog", keepnote.GETTEXT_DOMAIN) self.dialog = self.xml.get_widget("node_icon_dialog") self.xml.signal_autoconnect(self) self.dialog.connect( "close", lambda w: self.dialog.response(gtk.RESPONSE_CANCEL)) self.dialog.set_transient_for(self.main_window) self.icon_entry = self.xml.get_widget("icon_entry") self.icon_open_entry = self.xml.get_widget("icon_open_entry") self.icon_image = self.xml.get_widget("icon_image") self.icon_open_image = self.xml.get_widget("icon_open_image") self.standard_iconview = self.xml.get_widget("standard_iconview") self.notebook_iconview = self.xml.get_widget("notebook_iconview") self.quick_iconview = self.xml.get_widget("quick_pick_iconview") self.standard_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.notebook_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.quick_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.iconviews = [ self.standard_iconview, self.notebook_iconview, self.quick_iconview ] self.iconlists = [ self.standard_iconlist, self.notebook_iconlist, self.quick_iconlist ] self.iconview_signals = {} for iconview in self.iconviews: self.iconview_signals[iconview] = \ iconview.connect("selection-changed", self.on_iconview_selection_changed) iconview.connect("item-activated", lambda w, it: self.on_set_icon_button_clicked(w)) if node: self.set_icon("icon", node.get_attr("icon", "")) self.set_icon("icon_open", node.get_attr("icon_open", "")) self.populate_iconview() # run dialog response = self.dialog.run() icon_file = None icon_open_file = None if response == gtk.RESPONSE_OK: # icon filenames icon_file = unicode_gtk(self.icon_entry.get_text()) icon_open_file = unicode_gtk(self.icon_open_entry.get_text()) if icon_file.strip() == u"": icon_file = u"" if icon_open_file.strip() == u"": icon_open_file = u"" self.dialog.destroy() return icon_file, icon_open_file
def show(self, node=None, window=None): # TODO: factor out main_window.get_notebook() calls self.main_window = window self.node = node self.xml = gtk.glade.XML( keepnote.gui.get_resource("rc", "keepnote.glade"), "node_icon_dialog", keepnote.GETTEXT_DOMAIN) self.dialog = self.xml.get_widget("node_icon_dialog") self.xml.signal_autoconnect(self) self.dialog.connect("close", lambda w: self.dialog.response(gtk.RESPONSE_CANCEL)) self.dialog.set_transient_for(self.main_window) self.icon_entry = self.xml.get_widget("icon_entry") self.icon_open_entry = self.xml.get_widget("icon_open_entry") self.icon_image = self.xml.get_widget("icon_image") self.icon_open_image = self.xml.get_widget("icon_open_image") self.standard_iconview = self.xml.get_widget("standard_iconview") self.notebook_iconview = self.xml.get_widget("notebook_iconview") self.quick_iconview = self.xml.get_widget("quick_pick_iconview") self.standard_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.notebook_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.quick_iconlist = gtk.ListStore(gtk.gdk.Pixbuf, str) self.iconviews = [ self.standard_iconview, self.notebook_iconview, self.quick_iconview] self.iconlists = [ self.standard_iconlist, self.notebook_iconlist, self.quick_iconlist] self.iconview_signals = {} for iconview in self.iconviews: self.iconview_signals[iconview] = \ iconview.connect("selection-changed", self.on_iconview_selection_changed) iconview.connect("item-activated", lambda w,it: self.on_set_icon_button_clicked(w)) if node: self.set_icon("icon", node.get_attr("icon", "")) self.set_icon("icon_open", node.get_attr("icon_open", "")) self.populate_iconview() # run dialog response = self.dialog.run() icon_file = None icon_open_file = None if response == gtk.RESPONSE_OK: # icon filenames icon_file = unicode_gtk(self.icon_entry.get_text()) icon_open_file = unicode_gtk(self.icon_open_entry.get_text()) if icon_file.strip() == u"": icon_file = u"" if icon_open_file.strip() == u"": icon_open_file = u"" self.dialog.destroy() return icon_file, icon_open_file