def __init__(self, notebook, config=None, template='Default'): '''Constructor @param notebook: a L{Notebook} object @param config: optional C{ConfigManager} object @param template: html template for zim pages ''' assert isinstance(notebook, Notebook) self.notebook = notebook self.config = config or ConfigManager(profile=notebook.profile) self.output = None if isinstance(template, basestring): from zim.templates import get_template self.template = get_template('html', template) if not self.template: raise AssertionError, 'Could not find html template: %s' % template else: self.template = template self.linker = WWWLinker(self.notebook) self.template.set_linker(self.linker) self.plugins = PluginManager(self.config) self.plugins.extend(notebook.index) self.plugins.extend(notebook) self.plugins.extend(self)
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 testTemplate(self): pluginklass = zim.plugins.get_plugin_class('calendar') plugin = pluginklass() notebook = tests.new_notebook() template = get_template('wiki', 'Journal') zim.datetimetz.FIRST_DAY_OF_WEEK = \ zim.datetimetz.MONDAY plugin.preferences['namespace'] = Path('Calendar') for path in ( 'Calendar:2012', 'Calendar:2012:04:27', 'Calendar:2012:Week 17', 'Calendar:2012:04', ): page = notebook.get_page(Path(path)) lines = template.process(notebook, page) text = ''.join(lines) #~ print text self.assertTrue(not 'Created' in text) # No fall back if 'Week' in path: days = [l for l in lines if l.startswith('=== ')] self.assertEqual(len(days), 7)
def __init__(self, notebook, config=None, template='Default'): '''Constructor @param notebook: a L{Notebook} object @param config: optional C{ConfigManager} object @param template: html template for zim pages ''' assert isinstance(notebook, Notebook) self.notebook = notebook self.config = config or ConfigManager(profile=notebook.profile) self.output = None if template is None: template = 'Default' if isinstance(template, basestring): from zim.templates import get_template self.template = get_template('html', template) if not self.template: raise AssertionError('Could not find html template: %s' % template) else: self.template = template self.linker_factory = partial(WWWLinker, self.notebook, self.template.resources_dir) self.dumper_factory = get_format('html').Dumper # XXX self.plugins = PluginManager(self.config) self.plugins.extend(notebook) self.plugins.extend(self)
def __init__(self, notebook, format, template=None, index_page=None, document_root_url=None): '''Constructor. The 'notebook' is the source for pages to be exported. (The export target is given as an argument to export_all() or export().) The 'format' and 'template' arguments determine the output format. If 'index_page' is given a page index is generated and 'document_root_url' is used to prefix any file links that start with '/'. ''' self.notebook = notebook self.index_page = index_page self.document_root_url = document_root_url self.linker = StaticLinker(format, notebook, document_root_url=document_root_url) if isinstance(format, basestring): self.format = get_format(format) else: self.format = format if template and isinstance(template, basestring): self.template = get_template(format, template) else: self.template = template if self.template: self.template.set_linker(self.linker)
def __init__(self, notebook, template='Default', auth_creds=None): '''Constructor @param notebook: a L{Notebook} object @param template: html template for zim pages @param auth_creds: credentials for HTTP-authentication ''' assert isinstance(notebook, Notebook) self.notebook = notebook self.auth_creds = auth_creds self.output = None if template is None: template = 'Default' if isinstance(template, str): from zim.templates import get_template self.template = get_template('html', template) if not self.template: raise AssertionError('Could not find html template: %s' % template) else: self.template = template self.linker_factory = partial(WWWLinker, self.notebook, self.template.resources_dir) self.dumper_factory = get_format('html').Dumper # XXX
def __init__(self, plugin): ImageGeneratorClass.__init__(self, plugin) self.template = get_template('plugins', 'scoreeditor.ly') self.scorefile = TmpFile(self.scriptname) self.cur_lilypond_version = _get_lilypond_version() self.include_header = plugin.preferences['include_header'] self.include_footer = plugin.preferences['include_footer']
def __init__(self, ui, pageview, table=None, edit=False): if not edit: Dialog.__init__(self, ui, _('Insert Table'), # T: Dialog title button=(_('_Insert'), 'gtk-ok'), # T: Button label buttons=gtk.BUTTONS_OK_CANCEL) else: Dialog.__init__(self, ui, _('Edit Table'), # T: Dialog title button=(_('_Edit'), 'gtk-ok'), # T: Button label buttons=gtk.BUTTONS_OK_CANCEL) self.edit = edit self.table = table self.pageview = pageview self.rownames = gtk.ListStore(int, gobject.TYPE_STRING) self.columnNames = gtk.ListStore(int, str) self.template = get_template('plugins', 'equationeditor.tex') self.texfile = TmpFile(self.scriptname) self.rowIds = [1,2] self.colIds = [1,2] if table is not None: self.init_table(table=self.table) else: self.init_table()
def get_template(self, path): '''Returns a template object for path. Typically used to set initial content for a new page. ''' from zim.templates import get_template template = self.namespace_properties[path].get('template', '_New') logger.debug('Found template \'%s\' for %s', template, path) return get_template('wiki', template)
def build_mhtml_file_exporter(file, template, **opts): '''Returns an L{Exporter} that is suitable for exporting a set of pages to a single mhtml file ''' from zim.export.exporters.mhtml import MHTMLExporter template = get_template('html', template) return MHTMLExporter(file, template, **opts)
def build_single_file_exporter(file, format, template, namespace=None, **opts): '''Returns an L{Exporter} that is suitable for exporting a set of pages to a single file ''' from zim.export.layouts import SingleFileLayout from zim.export.exporters.files import SingleFileExporter template = get_template(format, template) layout = SingleFileLayout(file) return SingleFileExporter(layout, template, format, **opts)
def __init__(self, notebook=None, template='Default', **opts): NotebookInterface.__init__(self, **opts) self.output = None if isinstance(template, basestring): from zim.templates import get_template template = get_template('html', template) self.template = template self.linker = None self.load_plugins() if not notebook is None: self.open_notebook(notebook)
def build_single_file_exporter(file, format, template, namespace=None, **opts): '''Returns an L{Exporter} that is suitable for exporting a set of pages to a single file ''' from zim.export.layouts import SingleFileLayout from zim.export.exporters.files import SingleFileExporter template = get_template(format, template) ext = get_format(format).info['extension'] layout = SingleFileLayout(file) return SingleFileExporter(layout, template, format, **opts)
def build_notebook_exporter(dir, format, template, **opts): '''Returns an L{Exporter} that is suitable for exporting a whole notebook to a folder with one file per page ''' from zim.export.layouts import MultiFileLayout from zim.export.exporters.files import MultiFileExporter template = get_template(format, template) ext = get_format(format).info['extension'] layout = MultiFileLayout(dir, ext) return MultiFileExporter(layout, template, format, **opts)
def build_page_exporter(file, format, template, page, **opts): '''Returns an L{Exporter} that is suitable for exporting a page with subpages to a file and a folder (e.g. "page.html" with "page_files/") ''' from zim.export.layouts import FileLayout from zim.export.exporters.files import MultiFileExporter template = get_template(format, template) ext = get_format(format).info['extension'] layout = FileLayout(file, page, ext) return MultiFileExporter(layout, template, format, **opts)
def __init__(self, ui, pageview): Dialog.__init__( self, ui, _('Insert Reference'), # T: Dialog title button=(_('_Insert'), 'gtk-ok') # T: Button label ) self.pageview = pageview self.template = get_template('plugins', 'equationeditor.tex') self.init_dialog()
def __init__(self, notebook, format, template=None, index_page=None, document_root_url=None): '''Constructor. Takes all input parameters on how to format the exported content. @param notebook: the L{Notebook} object @param format: the output format as string, or formatting module object @param template: the template name as string, or a L{Template} object, if C{None} no template is used @param index_page: path name for the index page, if C{None} no index page is generated @param document_root_url: prefix for links that link to the document root (e.g. URL for the document root on some server). If C{None} document root files are considered the same as other files. @todo: check why index_page is a string and not a Path object ''' self.notebook = notebook self.document_root_url = document_root_url self.linker = StaticLinker(format, notebook, document_root_url=document_root_url) if index_page: self.index_page = notebook.cleanup_pathname(index_page) else: self.index_page = None if isinstance(format, basestring): self.format = get_format(format) else: self.format = format if template and not isinstance(template, Template): self.template = get_template(format, template) else: self.template = template if self.template: self.template.set_linker(self.linker)
def __init__(self, notebook=None, template='Default', **opts): '''Constructor @param notebook: notebook location @param template: html template for zim pages @param opts: options for L{NotebookInterface.__init__()} ''' NotebookInterface.__init__(self, **opts) self.output = None if isinstance(template, basestring): from zim.templates import get_template template = get_template('html', template) self.template = template self.linker = None self.load_plugins() if not notebook is None: self.open_notebook(notebook)
def do_response_ok(self): path = self.form['page'] if not path: return False page = self.notebook.get_page(path) # can raise PageNotFoundError 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 is not None: pageview.set_cursor_pos(-1) # HACK set position to end of template return True
def testListTemplates(self): '''Assert list templates still works with resource folders present''' import shutil from zim.config import XDG_DATA_HOME from zim.templates import list_templates, get_template # Make sure our template with resources is first in line datahome = XDG_DATA_HOME.subdir('zim/templates/') assert not datahome.exists() shutil.copytree(self.data, datahome.path) for name, basename in list_templates('html'): if name == 'Default': self.assertEqual(basename, 'Default.html') template = get_template('html', 'Default') self.assertEqual(template.file, datahome.file('html/Default.html').path) self.assertEqual(template.resources_dir, datahome.subdir('html/Default')) self.assertTrue(template.resources_dir.exists())
def __init__(self, plugin, attachment_folder=None): ImageGeneratorClass.__init__(self, plugin) self.template = get_template('plugins', 'gnuploteditor.gnu') self.attachment_folder = attachment_folder self.plotscriptfile = TmpFile(self.scriptname)
def _init_inputs(self, namespace, basename, append, text, template_options, custom=None): if template_options is None: template_options = {} else: template_options = template_options.copy() if namespace is not None and basename is not None: page = namespace + ':' + basename else: page = namespace or basename self.form.add_inputs(( ('page', 'page', _('Page')), ('namespace', 'namespace', _('Page section')), # T: text entry field ('new_page', 'bool', _('Create a new page for each note') ), # T: checkbox in Quick Note dialog ('basename', 'string', _('Title')) # T: text entry field )) self.form.update({ 'page': page, 'namespace': namespace, 'new_page': True, 'basename': basename, }) self.uistate.setdefault('open_page', True) self.uistate.setdefault('new_page', True) if basename: self.uistate['new_page'] = True # Be consistent with input # Set up the inputs and set page/ namespace to switch on # toggling the checkbox self.form.widgets['page'].set_no_show_all(True) self.form.widgets['namespace'].set_no_show_all(True) if append is None: self.form['new_page'] = bool(self.uistate['new_page']) else: self.form['new_page'] = not append def switch_input(*a): if self.form['new_page']: self.form.widgets['page'].hide() self.form.widgets['namespace'].show() self.form.widgets['basename'].set_sensitive(True) else: self.form.widgets['page'].show() self.form.widgets['namespace'].hide() self.form.widgets['basename'].set_sensitive(False) switch_input() self.form.widgets['new_page'].connect('toggled', switch_input) self.open_page_check = Gtk.CheckButton.new_with_mnemonic( _('Open _Page')) # T: Option in quicknote dialog # Don't use "O" as accelerator here to avoid conflict with "Ok" self.open_page_check.set_active(self.uistate['open_page']) self.action_area.pack_start(self.open_page_check, False, True, 0) self.action_area.set_child_secondary(self.open_page_check, True) # Add the main textview and hook up the basename field to # sync with first line of the textview window, textview = ScrolledTextView() self.textview = textview self.textview.set_editable(True) self.vbox.pack_start(window, True, True, 0) self.form.widgets['basename'].connect('changed', self.on_title_changed) self.textview.get_buffer().connect('changed', self.on_text_changed) # Initialize text from template template = get_template('plugins', 'quicknote.txt') template_options['text'] = text or '' template_options.setdefault('url', '') lines = [] template.process(lines, template_options) buffer = self.textview.get_buffer() buffer.set_text(''.join(lines)) begin, end = buffer.get_bounds() buffer.place_cursor(begin) buffer.set_modified(False) self.connect('delete-event', self.do_delete_event)
def __init__(self, plugin, notebook, page): ImageGeneratorClass.__init__(self, plugin, notebook, page) self.template = get_template('plugins', 'gnu_r_editor.r') self.plotscriptfile = TmpFile('gnu_r_plot.r')
def __init__(self, plugin): ImageGeneratorClass.__init__(self, plugin) self.template = get_template('plugins', 'equationeditor.tex') self.texfile = TmpFile(self.scriptname)
def __init__(self, plugin): ImageGeneratorClass.__init__(self, plugin) self.template = get_template('plugins', 'gnu_r_editor.r') self.plotscriptfile = TmpFile(self.scriptname)
def __init__(self, plugin, notebook, page): ImageGeneratorClass.__init__(self, plugin, notebook, page) self.template = get_template('plugins', 'equationeditor.tex') self.texfile = TmpFile('equation.tex')
def __init__(self, plugin, notebook, page): ImageGeneratorClass.__init__(self, plugin, notebook, page) self.template = get_template('plugins', 'gnuploteditor.gnu') self.attachment_folder = notebook.get_attachments_dir(page) self.plotscriptfile = TmpFile('gnuplot.gnu')
def _init_inputs(self, namespace, basename, append, text, template_options, custom=None): if template_options is None: template_options = {} else: template_options = template_options.copy() if namespace is not None and basename is not None: page = namespace + ':' + basename else: page = namespace or basename self.form.add_inputs( ( ('page', 'page', _('Page')), ('namespace', 'namespace', _('Page section')), # T: text entry field ('new_page', 'bool', _('Create a new page for each note')), # T: checkbox in Quick Note dialog ('basename', 'string', _('Title')) # T: text entry field ) ) self.form.update({ 'page': page, 'namespace': namespace, 'new_page': True, 'basename': basename, } ) self.uistate.setdefault('open_page', True) self.uistate.setdefault('new_page', True) if basename: self.uistate['new_page'] = True # Be consistent with input # Set up the inputs and set page/ namespace to switch on # toggling the checkbox self.form.widgets['page'].set_no_show_all(True) self.form.widgets['namespace'].set_no_show_all(True) if append is None: self.form['new_page'] = bool(self.uistate['new_page']) else: self.form['new_page'] = not append def switch_input(*a): if self.form['new_page']: self.form.widgets['page'].hide() self.form.widgets['namespace'].show() self.form.widgets['basename'].set_sensitive(True) else: self.form.widgets['page'].show() self.form.widgets['namespace'].hide() self.form.widgets['basename'].set_sensitive(False) switch_input() self.form.widgets['new_page'].connect('toggled', switch_input) self.open_page = gtk.CheckButton(_('Open _Page')) # T: Option in quicknote dialog # Don't use "O" as accelerator here to avoid conflict with "Ok" self.open_page.set_active(self.uistate['open_page']) self.action_area.pack_start(self.open_page, False) self.action_area.set_child_secondary(self.open_page, True) # Add the main textview and hook up the basename field to # sync with first line of the textview window, textview = ScrolledTextView() self.textview = textview self.textview.set_editable(True) self.vbox.add(window) self.form.widgets['basename'].connect('changed', self.on_title_changed) self.textview.get_buffer().connect('changed', self.on_text_changed) # Initialize text from template template = get_template('plugins', 'quicknote.txt') template_options['text'] = text or '' template_options.setdefault('url', '') lines = [] template.process(lines, template_options) buffer = self.textview.get_buffer() buffer.set_text(''.join(lines)) begin, end = buffer.get_bounds() buffer.place_cursor(begin) buffer.set_modified(False) self.connect('delete-event', self.do_delete_event)