def runTest(self): plugin = PluginManager.load_plugin('inlinecalculator') notebook = self.setUpNotebook() pageview = setUpPageView(notebook) extension = find_extension(pageview, InlineCalculatorPageViewExtension) buffer = pageview.textview.get_buffer() def get_text(): start, end = buffer.get_bounds() return start.get_text(end) # Simple case buffer.set_text('1 + 1 =\n') buffer.place_cursor(buffer.get_iter_at_offset(7)) extension.eval_math() self.assertEqual(get_text(), '1 + 1 = 2\n') # Looks back to previous line buffer.set_text('1 + 1 =\n\n') buffer.place_cursor(buffer.get_iter_at_offset(8)) extension.eval_math() self.assertEqual(get_text(), '1 + 1 = 2\n\n') # Multi-line example buffer.set_text('1\n2\n3\n--- +\n') buffer.place_cursor(buffer.get_iter_at_offset(6)) extension.eval_math() self.assertEqual(get_text(), '1\n2\n3\n--- +\n6\n')
def setUp(self): self.plugin = PluginManager.load_plugin('pageindex') self.window = setUpMainWindow( self.setUpNotebook(content=tests.FULL_NOTEBOOK)) self.extension = find_extension(self.window.pageview, PageIndexNotebookViewExtension) assert self.extension is not None
def testTaskListTreeView(self): plugin = PluginManager.load_plugin('tasklist') notebook = self.setUpNotebook(content=tests.FULL_NOTEBOOK) notebook.index.check_and_update() from zim.plugins.tasklist.gui import TaskListTreeView view = TasksView.new_from_index(notebook.index) opener = tests.MockObject() treeview = TaskListTreeView(view, opener, task_labels=['TODO', 'FIXME']) menu = treeview.get_popup() # Check these do not cause errors - how to verify state ? tests.gtk_activate_menu_item(menu, _("Expand _All")) tests.gtk_activate_menu_item(menu, _("_Collapse All")) # Copy tasklist -> csv from zim.gui.clipboard import Clipboard tests.gtk_activate_menu_item(menu, _('_Copy')) text = Clipboard.get_text() lines = text.splitlines() self.assertTrue(len(lines) > 10) self.assertTrue(len(lines[0].split(',')) > 3) self.assertFalse(any('<span' in l for l in lines)) # make sure encoding is removed # Test tags tags = treeview.get_tags() for tag in ('home', 'FIXME', '__no_tags__', 'tags'): self.assertIn(tag, tags) self.assertGreater(tags[tag], 0)
def testPageViewExtensions(self): plugin = PluginManager.load_plugin('tableofcontents') notebook = self.setUpNotebook() mainwindow = setUpMainWindow(notebook) plugin.preferences['floating'] = True ## floating ext = list(plugin.extensions) self.assertEqual(len(ext), 1) self.assertIsInstance(ext[0], ToCPageViewExtension) self.assertIsInstance(ext[0].tocwidget, FloatingToC) plugin.preferences.changed() # make sure no errors are triggered plugin.preferences['show_h1'] = True plugin.preferences['show_h1'] = False plugin.preferences['pane'] = RIGHT_PANE plugin.preferences['pane'] = LEFT_PANE ### embedded plugin.preferences['floating'] = False self.assertIsInstance(ext[0].tocwidget, SidePaneToC) plugin.preferences.changed() # make sure no errors are triggered plugin.preferences['show_h1'] = True plugin.preferences['show_h1'] = False plugin.preferences['pane'] = RIGHT_PANE plugin.preferences['pane'] = LEFT_PANE plugin.preferences['floating'] = True # switch back
def testObjectTypes(self): PluginManager.load_plugin(self.plugin) notebook = self.setUpNotebook() page = notebook.get_page(Path('Test')) for name in self.object_types: otype = PluginManager.insertedobjects[name] attrib, data = otype.new_object() model = otype.model_from_data(notebook, page, attrib, data) self.assertIsNotNone(model) widget = otype.create_widget(model) self.assertIsNotNone(widget) attrib, data = otype.data_from_model(model) self.assertIsNotNone(otype.label) if isinstance(model, BackwardImageGeneratorObjectType): self.assertIsNotNone(otype.scriptname) self.assertIsNotNone(otype.imagefile_extension)
def testMainWindowExtensions(self): plugin = PluginManager.load_plugin('journal') notebook = self.setUpNotebook() mainwindow = setUpMainWindow(notebook) plugin.preferences.changed() # make sure no errors are triggered ext = find_extension(mainwindow.pageview, JournalPageViewExtension) ext.go_page_today() self.assertTrue(mainwindow.page.name.startswith('Journal:'))
def runTest(self): plugin = PluginManager.load_plugin('pathbar') window = setUpMainWindow(self.setUpNotebook()) extension = find_extension(window, PathBarMainWindowExtension) for ptype in PATHBAR_TYPES: extension.set_pathbar(ptype) pathbar = window._zim_window_central_vbox.get_children()[0] if ptype == PATHBAR_NONE: self.assertNotIsInstance(pathbar, PathBar) else: self.assertIsInstance(pathbar, extension._klasses[ptype])
def testNotebookExtension(self): plugin = PluginManager.load_plugin('journal') notebook = self.setUpNotebook() ext = find_extension(notebook, JournalNotebookExtension) self.assertIsNotNone(ext) page = Path('Foo') link = notebook.suggest_link(page, '2014-01-06') self.assertEqual(link.name, 'Journal:2014:01:06') link = notebook.suggest_link(page, 'foo') self.assertIsNone(link)
def testIndexing(self): '''Check indexing of tasklist plugin''' plugin = PluginManager.load_plugin('tasklist') notebook = self.setUpNotebook(content=tests.FULL_NOTEBOOK) # Test indexing based on index signals notebook.index.check_and_update() view = TasksView.new_from_index(notebook.index) for tasks in ( list(view.list_open_tasks()), list(view.list_open_tasks_flatlist()), ): self.assertTrue(len(tasks) > 5) for task in tasks: path = view.get_path(task) self.assertTrue(not path is None)
def testGenerator(self): plugin = PluginManager.load_plugin(self.plugin) notebook = self.setUpNotebook() page = notebook.get_page(Path('Test')) generator_classes = list(plugin.discover_classes(ImageGeneratorClass)) assert len(generator_classes) == 1 generator_class = generator_classes[0] for name in self.object_types: if name.startswith('image+'): backward_otype = PluginManager.insertedobjects[name] break else: backward_otype = None # Input OK generator = generator_class(plugin, notebook, page) generator.cleanup() # ensure files did not yet exist imagefile, logfile = generator.generate_image(self.validinput) if imagefile.path.endswith('.png'): assertIsPNG(imagefile) # else: TODO other types if backward_otype: self.assertTrue( imagefile.basename.endswith( backward_otype.imagefile_extension)) self.assertTrue(imagefile.exists()) if logfile is not None: self.assertTrue(logfile.exists()) # Cleanup generator.cleanup() self.assertFalse(imagefile.exists()) if logfile is not None: self.assertFalse(logfile.exists()) # Input NOK if self.invalidinput is not None: generator = generator_class(plugin, notebook, page) imagefile, logfile = generator.generate_image(self.invalidinput) self.assertIsNone(imagefile) if logfile is not None: self.assertTrue(logfile.exists())
def runTest(self, adapterclass): with tests.LoggingFilter(logger='zim.plugins.spell'): # Hide exceptions window = setUpMainWindow(self.setUpNotebook(content=('Test', 'Foo', 'Bar'))) plugin = PluginManager.load_plugin('spell') ext = find_extension(window.pageview, zim.plugins.spell.SpellPageViewExtension) self.assertIs(ext._adapter_cls, adapterclass) # ensure switching library worked ext.toggle_spellcheck() ext.toggle_spellcheck() ext.toggle_spellcheck() window.open_page(Path('Foo')) window.open_page(Path('Bar')) ext.toggle_spellcheck() window.open_page(Path('Foo')) window.open_page(Path('Bar'))
def testTemplate(self): plugin = PluginManager.load_plugin('journal') notebook = self.setUpNotebook() dumper = get_dumper('wiki') zim.datetimetz.FIRST_DAY_OF_WEEK = \ zim.datetimetz.MONDAY for path in ( Path('Journal:2012'), Path('Journal:2012:04:27'), Path('Journal:2012:Week 17'), Path('Journal:2012:04'), ): tree = notebook.get_template(path) lines = dumper.dump(tree) #~ print lines self.assertTrue(not 'Created' in ''.join(lines)) # No fall back if 'Week' in path.name: days = [l for l in lines if l.startswith('=== ')] self.assertEqual(len(days), 7)
def runTest(self): plugin = PluginManager.load_plugin('versioncontrol') dir = get_tmp_dir('versioncontrol_TestMainWindowExtension') notebook = self.setUpNotebook( mock=tests.MOCK_ALWAYS_REAL, content=('Test',), folder=LocalFolder(dir.path) ) mainwindow = setUpMainWindow(notebook) notebook_ext = find_extension(notebook, NotebookExtension) window_ext = find_extension(mainwindow, VersionControlMainWindowExtension) op = ongoing_operation(notebook) assert op is None # check no opperation ongoing ## init & save version self.assertIsNone(notebook_ext.vcs) def init(dialog): self.assertIsInstance(dialog, VersionControlInitDialog) choice = dialog.combobox.get_active_text() self.assertTrue(choice and not choice.isspace()) dialog.assert_response_ok() with tests.DialogContext(init, SaveVersionDialog): window_ext.save_version() self.assertIsNotNone(notebook_ext.vcs) self.assertFalse(notebook_ext.vcs.is_modified()) ## save version again page = notebook.get_page(Path('Foo')) page.parse('wiki', 'foo!') notebook.store_page(page) self.assertTrue(notebook_ext.vcs.is_modified()) with tests.DialogContext(SaveVersionDialog): window_ext.save_version() self.assertFalse(notebook_ext.vcs.is_modified()) ## show versions with tests.DialogContext(VersionsDialog): window_ext.show_versions() ## auto-save plugin.preferences['autosave'] = True page = notebook.get_page(Path('Fooooo')) page.parse('wiki', 'foo!') notebook.store_page(page) self.assertTrue(notebook_ext.vcs.is_modified()) mainwindow.emit('close') self.assertFalse(notebook_ext.vcs.is_modified()) tests.gtk_process_events() assert ongoing_operation(notebook) is None
def setUp(self): PluginManager.load_plugin('equationeditor')
def setUp(self): PluginManager.load_plugin('tableeditor') self.assertIn('table', PluginManager.insertedobjects)
def testDetectsNewExtensions(self): n_children = len(self.extension.toolbar.get_children()) PluginManager.load_plugin('arithmetic') self.assertEqual(len(self.extension.toolbar.get_children()), n_children + 1)
def setUp(self): self.plugin = PluginManager.load_plugin('toolbar') self.window = setUpMainWindow(self.setUpNotebook()) self.extension = find_extension(self.window.pageview, ToolBarMainWindowExtension)
def setUp(self): PluginManager.load_plugin('tableeditor')
def setUp(self): PluginManager.load_plugin('tableeditor') self.otype = PluginManager.insertedobjects['table']
def runTest(self): plugin = PluginManager.load_plugin('pageindex') window = setUpMainWindow(self.setUpNotebook()) extension = find_extension(window.pageview, PageIndexPageViewExtension) self.assertIsNotNone(extension)
def runTest(self): plugin = PluginManager.load_plugin('insertsymbol') mainwindow = setUpMainWindow(self.setUpNotebook(content={'Test': '\n'}), path='Test') pageview = mainwindow.pageview textview = pageview.textview buffer = textview.get_buffer() # Widget needs to be realized pageview.realize() textview.realize() # insert on end-of-word with space press(textview, '\\alpha ') start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, ALPHA + ' \n') # Check undo - first undo replace, then the insert space pageview.undo() start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, '\\alpha \n') pageview.undo() start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, '\\alpha\n') # no trailing space # insert on end-of-word with ; buffer.clear() press(textview, r'\alpha;') start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, ALPHA) # no trailing space # no insert in code or pre section buffer.clear() pageview.toggle_format(VERBATIM) press(textview, r'\alpha ') start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, r'\alpha ') # no replace # no insert in code or pre section at end-of-line buffer.clear() pageview.toggle_format(VERBATIM) press(textview, '\\alpha\n') start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, '\\alpha\n') # no replace # test dialog def check_dialog(dialog): self.assertIsInstance(dialog, InsertSymbolDialog) dialog.iconview.item_activated(Gtk.TreePath((9,))) # path for 10th item in symbol list dialog.iconview.item_activated(Gtk.TreePath((10,))) # path for 11th item in symbol list dialog.iconview.item_activated(Gtk.TreePath((11,))) # path for 12th item in symbol list dialog.assert_response_ok() buffer.clear() pageview_ext = find_extension(pageview, InsertSymbolPageViewExtension) with tests.DialogContext(check_dialog): pageview_ext.insert_symbol() start, end = buffer.get_bounds() text = start.get_text(end) self.assertEqual(text, EACUTE + ECIRC + EGRAVE)
class PreferencesDialog(Dialog): def __init__(self, widget, default_tab=None, select_plugin=None): Dialog.__init__(self, widget, _('Preferences')) # T: Dialog title self.preferences = ConfigManager.preferences # warning for locale _pref_enc = locale.getpreferredencoding() if _pref_enc in ('ascii', 'us-ascii', 'ANSI_X3.4-1968'): self.vbox.pack_start(localeWarningBar(_pref_enc), True, True, 0) # saves a list of loaded plugins to be used later self.plugins = PluginManager() self.p_save_loaded = list(self.plugins) # Dynamic tabs gtknotebook = Gtk.Notebook() self.vbox.pack_start(gtknotebook, True, True, 0) self.forms = {} ############################### needs rewrite to make defintion more robust for category in ('Interface', 'Editing'): vbox = Gtk.VBox() index = gtknotebook.append_page(vbox, Gtk.Label(label=_(category))) # From GTK Doc: Note that due to historical reasons, GtkNotebook refuses # to switch to a page unless the child widget is visible. vbox.show() if category == default_tab: gtknotebook.set_current_page(index) fields = [] values = {} sections = {} for section, preferences in ( ('GtkInterface', interface_preferences), ('PageView', pageview_preferences) ): for p in [p for p in preferences if p[2] == category]: # key, type, category, label, default, (check) if len(p) == 5: key, type, cat, label, default = p self.preferences[section].setdefault(key, default) fields.append((key, type, label)) else: key, type, cat, label, default, check = p self.preferences[section].setdefault(key, default, check) fields.append((key, type, label, check)) values[key] = self.preferences[section][key] sections[key] = section form = InputForm(fields, values) form.preferences_sections = sections vbox.pack_start(form, False, True, 0) self.forms[category] = form if category == 'Interface': self._add_font_selection(form) # Styles tab #~ gtknotebook.append_page(StylesTab(self), Gtk.Label(label=_('Styles'))) # Keybindings tab gtknotebook.append_page(KeyBindingsTab(self), Gtk.Label(label=_('Key bindings'))) # T: Heading in preferences dialog # Plugins tab self.plugins_tab = PluginsTab(self, self.plugins) plugins_tab_index = gtknotebook.append_page(self.plugins_tab, Gtk.Label(label=_('Plugins'))) # T: Heading in preferences dialog self.plugins_tab.show() #~ print default_tab, index if default_tab == "Plugins": gtknotebook.set_current_page(plugins_tab_index) if not select_plugin is None: self.plugins_tab.select_plugin(select_plugin) # Applications tab gtknotebook.append_page(ApplicationsTab(self), Gtk.Label(label=_('Applications'))) # T: Heading in preferences dialog def _add_font_selection(self, table): # need to hardcode this, cannot register it as a preference table.add_inputs(( ('use_custom_font', 'bool', _('Use a custom font')), # T: option in preferences dialog )) table.preferences_sections['use_custom_font'] = 'GtkInterface' self.fontbutton = Gtk.FontButton() self.fontbutton.set_use_font(True) # preview in button self.fontbutton.set_sensitive(False) text_style = ConfigManager.get_config_dict('style.conf') try: font = text_style['TextView']['font'] if font: self.fontbutton.set_font_name(font) self.fontbutton.set_sensitive(True) table['use_custom_font'] = True except KeyError: pass table.widgets['use_custom_font'].connect('toggled', lambda o: self.fontbutton.set_sensitive(o.get_active())) self.fontbutton.set_size_request(100, -1) input_table_factory(((None, self.fontbutton),), table) def do_response_ok(self): # Get dynamic tabs newpreferences = {} for form in list(self.forms.values()): for key, value in list(form.items()): section = form.preferences_sections[key] if not section in newpreferences: newpreferences[section] = {} newpreferences[section][key] = value # Set font - special case, consider it a HACK customfont = newpreferences['GtkInterface'].pop('use_custom_font') if customfont: font = self.fontbutton.get_font_name() else: font = None text_style = ConfigManager.get_config_dict('style.conf') text_style['TextView'].define(font=String(None)) text_style['TextView']['font'] = font # with self.preferences.block_signals('changed'): # note we do not block signal on section dicts for section in newpreferences: self.preferences[section].update(newpreferences[section]) self.preferences.emit('changed') # delayed emission return True def do_response_cancel(self): # Obtain an updated list of loaded plugins now_loaded = list(self.plugins) # Restore previous situation if the user changed something # in this dialog session with self.preferences.block_signals('changed'): for name in self.plugins.list_installed_plugins(): if name in self.p_save_loaded and name not in now_loaded: try: self.plugins.load_plugin(name) except: logger.exception('Could not restore plugin: %s', name) elif name not in self.p_save_loaded and name in now_loaded: self.plugins.remove_plugin(name) self.preferences.emit('changed') # delayed emission return True
def setUp(self): PluginManager.load_plugin('sourceview')