def do_response_ok(self): if not self.imagefile \ or self.textview.get_buffer().get_modified(): self.generate_image() if not (self.imagefile and self.imagefile.exists()): dialog = QuestionDialog(self, _('An error occured while generating the image.\nDo you want to save the source text anyway?')) # T: Question prompt when e.g. equation editor encountered an error genrating the image to insert if not dialog.run(): return False if self._existing_file: textfile = self._existing_file else: page = self.ui.page dir = self.ui.notebook.get_attachments_dir(page) textfile = dir.new_file(self.generator.basename) imgfile = self._stitch_fileextension(textfile, self.imagefile.basename) textfile.write( self.get_text() ) self.imagefile.rename(imgfile) if self._existing_file: self.ui.reload_page() else: pageview = self.ui.mainwindow.pageview pageview.insert_image(imgfile, type=self.generator.type, interactive=False) if self.logfile and self.logfile.exists(): self.logfile.remove() return True
def do_response_ok(self): buffer = self.textview.get_buffer() if buffer.get_modified(): self.update_image() if not (self.image_file and self.image_file.exists()): dialog = QuestionDialog(self, _('An error occurred while generating the image.\nDo you want to save the source text anyway?')) # T: Question prompt when e.g. equation editor encountered an error generating the image to insert if not dialog.run(): return False self.result = (self.get_text(), self.image_file) return True
def do_response_ok(self): path = self.form['page'] if not path: return False try: page = self.notebook.get_page(path) # can raise PageNotFoundError except PageNotAvailableError as error: self.hide() # Same code in MainWindow.open_page() if QuestionDialog(self, ( _('File exists, do you want to import?'), # T: short question on open-page if file exists _('The file "%s" exists but is not a wiki page.\nDo you want to import it?') % error.file.basename # T: longer question on open-page if file exists )).run(): from zim.import_files import import_file page = import_file(error.file, self.notebook, path) else: return False # user cancelled template = None else: if page.exists(): raise PageExistsError(path) template = get_template('wiki', self.form['template']) tree = self.notebook.eval_new_page_template(page, template) page.set_parsetree(tree) self.notebook.store_page(page) pageview = self.navigation.open_page(page) if pageview and template: pageview.set_cursor_pos(-1) # HACK set position to end of template return True
def delete_page(self, path=None): '''Delete a page by either trashing it, or permanent deletion after confirmation of a L{TrashPageDialog} or L{DeletePageDialog}. @param path: a L{Path} object, or C{None} for the current selected page ''' # Difficulty here is that we want to avoid unnecessary prompts. # So ideally we want to know whether trash is supported, but we only # know for sure when we try. Thus we risk prompting twice: once for # trash and once for deletion if trash fails. path = path or self.page assert path is not None if not self.ensure_index_uptodate(): return # TODO: if page is placeholder, present different dialog ? # explain no file is deleted, only links can be removed, which is not reversable if self.notebook.config['Notebook']['disable_trash']: return DeletePageDialog(self.widget, self.notebook, path).run() else: # Try to trash - if fail, go to delete anyway error = TrashPageDialog(self.widget, self.notebook, path).run() if error: if QuestionDialog( self.widget, _("Trash failed, do you want to permanently delete instead ?") # T: question in "delete page" action ).run(): return DeletePageDialog(self.widget, self.notebook, path).run()
def __init__(self): QuestionDialog.__init__(self, _("Enable Version Control?"), # T: Question dialog _("Version control is currently not enabled for this notebook.\n" "Do you want to enable it?" ) # T: Detailed question ) self.combobox = gtk.combo_box_new_text() for option in (VCS.BZR, VCS.GIT, VCS.HG): if VCS.check_dependencies(option): self.combobox.append_text(option) self.combobox.set_active(0) hbox = gtk.HBox(spacing=5) hbox.pack_end(self.combobox, False) hbox.pack_end(gtk.Label(_('Backend') + ':'), False) # T: option to chose versioncontrol backend self.vbox.pack_start(hbox, False) hbox.show_all()
def do_response_ok(self): if not self.imagefile \ or self.textview.get_buffer().get_modified(): self.generate_image() if not (self.imagefile and self.imagefile.exists()): dialog = QuestionDialog( self, _('An error occurred while generating the image.\nDo you want to save the source text anyway?' )) # T: Question prompt when e.g. equation editor encountered an error generating the image to insert if not dialog.run(): return False if self._existing_file: textfile = self._existing_file else: page = self.app_window.ui.page # XXX dir = self.app_window.ui.notebook.get_attachments_dir(page) # XXX textfile = dir.new_file(self.generator.scriptname) textfile.write(self.generator.process_input(self.get_text())) imgfile = self._stitch_fileextension(textfile, self.generator.imagename) if self.imagefile and self.imagefile.exists(): self.imagefile.rename(imgfile) elif imgfile.exists(): imgfile.remove() if self._existing_file: self.app_window.ui.reload_page() # XXX else: pageview = self.app_window.pageview pageview.insert_image(imgfile, type=self.generator.object_type, interactive=False, force=True) if self.logfile and self.logfile.exists(): self.logfile.remove() return True
def delete_file(widget, file): '''Delete a file @param widget: parent for new dialogs, C{Gtk.Widget} or C{None} @param file: a L{File} object @raises FileNotFoundError: if C{file} does not exist ''' logger.debug('delete_file(%s)', file) file = localFileOrFolder(file) assert isinstance(file, LocalFile) and not isinstance(file, LocalFolder) if not file.exists(): raise FileNotFoundError(file) dialog = QuestionDialog(widget, _('Are you sure you want to delete the file \'%s\'?') % file.basename) # T: text in confirmation dialog on deleting a file if dialog.run(): TrashHelper().trash(file)
def get_file(self): file = File(self.uistate['output_file']) if file.exists(): ok = QuestionDialog(self, ( _('File exists'), # T: message heading _('This file already exists.\n' 'Do you want to overwrite it?') # T: detailed message, answers are Yes and No )).run() if not ok: return None return file
def do_response(self, id): if id == Gtk.ResponseType.DELETE_EVENT: if self.textview.get_buffer().get_modified(): ok = QuestionDialog(self, _('Discard note?')).run() # T: confirm closing quick note dialog if ok: Dialog.do_response(self, id) # else pass else: Dialog.do_response(self, id) else: Dialog.do_response(self, id)
def get_folder(self): dir = Dir(self.uistate['output_folder']) if dir.exists() and len(dir.list()) > 0: ok = QuestionDialog(self, ( _('Folder exists: %s') % dir.path, # T: message heading _('Folder already exists and has content, ' 'exporting to this folder may overwrite ' 'existing files. ' 'Do you want to continue?') # T: detailed message, answers are Yes and No )).run() if not ok: return None return dir
def __init__(self, parent): QuestionDialog.__init__( self, parent, ( _("Enable Version Control?"), # T: Question dialog _("Version control is currently not enabled for this notebook.\n" "Do you want to enable it?") # T: Detailed question )) self.combobox = Gtk.ComboBoxText() for option in (VCS.BZR, VCS.GIT, VCS.HG, VCS.FOSSIL): if VCS.check_dependencies(option): self.combobox.append_text(option) self.combobox.set_active(0) hbox = Gtk.Box(spacing=5) hbox.add(Gtk.Label(_('Backend') + ':')) hbox.add(self.combobox) # T: option to chose versioncontrol backend hbox.set_halign(Gtk.Align.CENTER) self.vbox.pack_start(hbox, False, False, 0) hbox.show_all()
def restore_version(self): file = self._get_file() path = self.page_entry.get_path() version = self.versionlist.get_versions()[0] assert not file is None if QuestionDialog(self, ( _('Restore page to saved version?'), # T: Confirmation question _('Do you want to restore page: %(page)s\n' 'to saved version: %(version)s ?\n\n' 'All changes since the last saved version will be lost !') % {'page': path.name, 'version': str(version)} # T: Detailed question, "%(page)s" is replaced by the page, "%(version)s" by the version id ) ).run(): self.vcs.revert(file=file, version=version) self.ui.reload_page() # XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
def open_folder_prompt_create(widget, folder): '''Open a folder and prompts to create it if it doesn't exist yet. @param widget: parent for new dialogs, C{Gtk.Widget} or C{None} @param folder: a L{Folder} object ''' try: open_folder(widget, folder) except FileNotFoundError: if QuestionDialog(widget, ( _('Create folder?'), # T: Heading in a question dialog for creating a folder _('The folder "%s" does not yet exist.\nDo you want to create it now?') % folder.basename # T: Text in a question dialog for creating a folder, %s will be the folder base name )).run(): folder.touch() open_folder(widget, folder)
class ExportDialog(Assistant): def __init__(self, ui): Assistant.__init__( self, ui, _('Export'), # T: dialog title help=':Help:Export', defaultwindowsize=(400, 325)) self.append_page(InputPage(self)) self.append_page(FormatPage(self)) self.append_page(OutputPage(self)) def do_response_ok(self): #~ import pprint #~ pprint.pprint(self.uistate) #~ return True options = {} for k in ('format', 'template', 'index_page'): if self.uistate[k] and not self.uistate[k].isspace(): options[k] = self.uistate[k] options['format'] = \ zim.formats.canonical_name(options['format']) if options['template'] == '__file__': options['template'] = self.uistate['template_file'] if self.uistate['document_root_url'] == 'url': options['document_root_url'] = self.uistate['document_root_url'] try: exporter = Exporter(self.ui.notebook, **options) except Exception, error: ErrorDialog(self, error).run() return False index = self.ui.notebook.index if index.updating: with ProgressBarDialog( self, _('Updating index' )) as dialog: # T: Title of progressbar dialog index.ensure_update(callback=lambda p: dialog.pulse(p.name)) if dialog.cancelled: return False if self.uistate['selection'] == 'all': dir = Dir(self.uistate['output_folder']) if dir.exists() and len(dir.list()) > 0: ok = QuestionDialog( self, ( _('Folder exists: %s') % dir.path, # T: message heading _('Folder already exists and has content, ' 'exporting to this folder may overwrite ' 'existing files. ' 'Do you want to continue?' ) # T: detailed message, answers are Yes and No )).run() if not ok: return False with ProgressBarDialog( self, _('Exporting notebook' )) as dialog: # T: Title for progressbar window exporter.export_all(dir, callback=lambda p: dialog.pulse(p.name)) elif self.uistate['selection'] == 'selection': pass # TODO elif self.uistate['selection'] == 'page': file = File(self.uistate['output_file']) if file.exists(): ok = QuestionDialog( self, ( _('File exists'), # T: message heading _('This file already exists.\n' 'Do you want to overwrite it?' ) # T: detailed message, answers are Yes and No )).run() if not ok: return False page = self.ui.notebook.get_page(self.uistate['selected_page']) exporter.export_page(file.dir, page, filename=file.basename) return True
def run(self): if QuestionDialog.run(self): return self.combobox.get_active_text() else: return None
def open_page(self, path, anchor=None): '''Method to open a page in the mainwindow, and menu action for the "jump to" menu item. Fails silently when saving current page failed (which is usually the result of pressing "cancel" in the error dialog shown when saving fails). Check return value for success if you want to be sure. @param path: a L{path} for the page to open. @param anchor: name of an anchor (optional) @raises PageNotFound: if C{path} can not be opened @emits: page-changed @returns: C{True} for success ''' assert isinstance(path, Path) try: page = self.notebook.get_page(path) # can raise except PageNotAvailableError as error: # Same code in NewPageDialog if QuestionDialog( self, ( _('File exists, do you want to import?' ), # T: short question on open-page if file exists _('The file "%s" exists but is not a wiki page.\nDo you want to import it?' ) % error.file. basename # T: longer question on open-page if file exists )).run(): from zim.import_files import import_file page = import_file(error.file, self.notebook, path) else: return # user cancelled if self.page and id(self.page) == id(page): if anchor: self.pageview.navigate_to_anchor(anchor) return elif self.page: self.pageview.save_changes( ) # XXX - should connect to signal instead of call here self.notebook.wait_for_store_page_async( ) # XXX - should not be needed - hide in notebook/page class - how? if self.page.modified: return False # Assume SavePageErrorDialog was shown and cancelled old_cursor = self.pageview.get_cursor_pos() old_scroll = self.pageview.get_scroll_pos() self.history.set_state(self.page, old_cursor, old_scroll) self.save_uistate() logger.info('Open page: %s (%s)', page, path) self.page = page self._uiactions.page = page self.notebook.index.touch_current_page_placeholder(path) paths = [page] + list(page.parents()) self.notebook.index.check_async(self.notebook, paths, recursive=False) if isinstance(path, HistoryPath): self.history.set_current(path) cursor = path.cursor # can still be None else: self.history.append(page) cursor = None if cursor is None and self.preferences['always_use_last_cursor_pos']: cursor, x = self.history.get_state(page) self.pageview.set_page(page, cursor) if anchor: self.pageview.navigate_to_anchor(anchor) self.emit('page-changed', page) self.pageview.grab_focus()
def run(self): active = self.combobox.get_active_text() if active and QuestionDialog.run(self): return active else: return None