Пример #1
0
    def testAddCustomTool(self):
        config = ConfigManager()
        manager = CustomToolManager(config)
        mytool = {
            'Name': 'Add',
            'Comment': 'Test Add',
            'X-Zim-ExecTool': 'add %f',
            'X-Zim-ReadOnly': False,
            'X-Zim-ShowInToolBar': False,
            'X-Zim-ReplaceSelection': False,
        }

        self.assertIsNone(manager.get_tool('Add'))

        def add_tool(dialog):
            dialog.set_input(**mytool)
            dialog.assert_response_ok()

        dialog = CustomToolManagerDialog(None, config)
        with tests.DialogContext(add_tool):
            dialog.on_add()
            dialog.assert_response_ok()

        # XXX listview intialization fails in test ???
        #model = dialog.listview.get_model()
        #self.assertIn('Add', [r[CustomToolList.NAME_COL] for r in model])

        tool = manager.get_tool('Add')
        self.assertIsNotNone(tool)
        for key, value in list(mytool.items()):
            self.assertEqual(tool['Desktop Entry'][key], value)
Пример #2
0
	def runTest(self):
		plugin = InsertSymbolPlugin(ConfigManager())

		mainwindow = setUpMainWindow(self.setUpNotebook(content={'Test': ''}), path='Test')
		pageview = mainwindow.pageview
		textview = pageview.textview
		buffer = textview.get_buffer()

		plugin.extend(pageview)

		# 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

		# 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)
Пример #3
0
    def run(self):
        config = ConfigManager()
        preferences = config.get_config_dict(
            'preferences.conf')['TrayIconPlugin']
        preferences.setdefault('classic', False)

        set_global_trayicon(preferences['classic'])
Пример #4
0
    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)
Пример #5
0
    def testEditCustomTool(self):
        config = ConfigManager()
        manager = CustomToolManager(config)
        mytool = {
            'Name': 'Edit',
            'Comment': 'Test Edit',
            'X-Zim-ExecTool': 'edit %f',
        }
        manager.create(**mytool)
        self.assertIsNotNone(manager.get_tool('Edit'))

        def edit_tool(dialog):
            dialog.set_input(Comment='Editted Comment')
            dialog.assert_response_ok()

        dialog = CustomToolManagerDialog(None, config)
        #model = dialog.listview.get_model()
        #self.assertIn('Edit', [r[CustomToolList.NAME_COL] for r in model])
        with tests.DialogContext(edit_tool):
            dialog.listview.select_by_name('Edit')
            dialog.on_edit()
            dialog.assert_response_ok()

        tool = manager.get_tool('Edit')
        self.assertEqual(tool.comment, 'Editted Comment')
Пример #6
0
    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)
Пример #7
0
def get_notebook_list():
	'''Returns a list of known notebooks as a L{NotebookInfoList}

	This will load the list from the default X{notebooks.list} file
	'''
	config = ConfigManager() # XXX should be passed in
	file = config.get_config_file('notebooks.list')
	return NotebookInfoList(file)
Пример #8
0
class GoogletasksCommand(NotebookCommand, GtkCommand):
    """Class to handle "zim --plugin googletasks" """
    arguments = ('[NOTEBOOK]',)

    preferences = ConfigManager().get_config_dict('preferences.conf')['GoogletasksPlugin'].dump()

    def run(self):
        ntb_name = self.get_notebook_argument()[0] or self.get_default_or_only_notebook()
        ntb, _ = build_notebook(ntb_name)
        GoogletasksController(notebook=ntb, preferences=GoogletasksCommand.preferences).fetch()  # add new lines
Пример #9
0
    def _run_new_window(self, notebook, page):
        from gi.repository import GObject

        from zim.gui.mainwindow import MainWindow
        from zim.config import ConfigManager
        from zim.plugins import PluginManager

        config = ConfigManager()
        preferences = config.preferences['General']
        preferences.setdefault('plugins', [
            'pageindex',
            'pathbar',
            'journal',
            'insertsymbol',
            'printtobrowser',
            'versioncontrol',
        ])

        # Upgrade plugin list
        preferences.setdefault('plugins_list_version', 'none')
        if preferences['plugins_list_version'] != '0.68':
            preferences['plugins'].extend(['pageindex', 'pathbar'])
            if 'calendar' in preferences['plugins']:
                preferences['plugins'].remove('calendar')
                preferences['plugins'].append('journal')
                config.preferences['JournalPlugin'] = config.preferences[
                    'CalendarPlugin']
            preferences['plugins_list_version'] = '0.68'

        pluginmanager = PluginManager(config)
        pluginmanager.extend(notebook)

        window = MainWindow(notebook,
                            config,
                            page=page,
                            **self.get_options('geometry', 'fullscreen'))
        pluginmanager.extend(window)
        pluginmanager.extend(window.pageview)
        window.__pluginmanager__ = pluginmanager  # HACK to allow dialogs to find it
        window.present()

        if not window.notebook.index.is_uptodate:
            window._uiactions.reload_index(update_only=True)  # XXX
        else:
            # Start a lightweight background check of the index
            # put a small delay to ensure window is shown before we start
            def start_background_check():
                notebook.index.start_background_check(notebook)
                return False  # only run once

            GObject.timeout_add(500, start_background_check)

        return window
Пример #10
0
    def run(self):
        from zim.config import ConfigManager
        import zim.notebook

        notebook_info = self.get_default_or_only_notebook()
        if not notebook_info:
            logger.error("No notebooks?")
            return
        notebook, _junk = zim.notebook.build_notebook(notebook_info)
        config_manager = ConfigManager()
        config_dict = config_manager.get_config_dict('preferences.conf')
        preferences = config_dict['GnomeShellSearch']
        preferences.setdefault('search_all', True)
        Provider(notebook, preferences['search_all']).main()
Пример #11
0
def mount_notebook(filepath):
	from zim.config import ConfigManager, String

	config = ConfigManager() # XXX should be passed in
	configdict = config.get_config_dict('automount.conf')

	groups = sorted([k for k in configdict.keys() if k.startswith('Path')])
	for group in groups:
		path = group[4:].strip() # len('Path') = 4
		dir = Dir(path)
		if filepath.path == dir.path or filepath.ischild(dir):
			configdict[group].define(mount=String(None))
			handler = ApplicationMountPointHandler(dir, **configdict[group])
			if handler(filepath):
				break
Пример #12
0
    def setUp(self):
        clear_customtools()

        notebook = self.setUpNotebook(content=('test', ))
        page = notebook.get_page(Path('test'))

        self.uimanager = Gtk.UIManager()
        group = Gtk.ActionGroup('test')
        group.add_actions([('tools_menu', None, '_Tools')])
        self.uimanager.insert_action_group(group)

        self.pageview = StubPageView(notebook, page)
        self.config = ConfigManager()
        self.customtoolsui = CustomToolManagerUI(self.uimanager, self.config,
                                                 self.pageview)
Пример #13
0
    def run(self):
        start_server_if_not_running()

        config = ConfigManager()
        preferences = config.get_config_dict(
            'preferences.conf')['TrayIconPlugin']
        preferences.setdefault('classic', False)

        if appindicator and not preferences['classic']:
            obj = RemoteObject('zim.plugins.trayicon.AppIndicatorTrayIcon')
        else:
            obj = RemoteObject('zim.plugins.trayicon.DaemonTrayIcon')

        server = ServerProxy()
        if not server.has_object(obj):
            server.init_object(obj)
Пример #14
0
    def __init__(self,
                 window,
                 notebook=None,
                 page=None,
                 namespace=None,
                 basename=None,
                 append=None,
                 text=None,
                 template_options=None,
                 attachments=None):
        assert page is None, 'TODO'

        manager = ConfigManager()  # FIXME should be passed in
        self.config = manager.get_config_dict('quicknote.conf')
        self.uistate = self.config['QuickNoteDialog']

        Dialog.__init__(self, window, _('Quick Note'))
        self._updating_title = False
        self._title_set_manually = not basename is None
        self.attachments = attachments

        if notebook and not isinstance(notebook, str):
            notebook = notebook.uri

        self.uistate.setdefault('lastnotebook', None, str)
        if self.uistate['lastnotebook']:
            notebook = notebook or self.uistate['lastnotebook']
            self.config['Namespaces'].setdefault(notebook, None, str)
            namespace = namespace or self.config['Namespaces'][notebook]

        self.form = InputForm()
        self.vbox.pack_start(self.form, False, True, 0)

        # TODO dropdown could use an option "Other..."
        label = Gtk.Label(label=_('Notebook') + ': ')
        label.set_alignment(0.0, 0.5)
        self.form.attach(label, 0, 1, 0, 1, xoptions=Gtk.AttachOptions.FILL)
        # T: Field to select Notebook from drop down list
        self.notebookcombobox = NotebookComboBox(current=notebook)
        self.notebookcombobox.connect('changed', self.on_notebook_changed)
        self.form.attach(self.notebookcombobox, 1, 2, 0, 1)

        self._init_inputs(namespace, basename, append, text, template_options)

        self.uistate['lastnotebook'] = notebook
        self._set_autocomplete(notebook)
Пример #15
0
    def run(self):
        from zim.export.selections import AllPages, SinglePage, SubPages
        from zim.plugins import PluginManager
        from zim.config import ConfigManager

        notebook, page = self.build_notebook()

        # load plugins, needed so the the proper export functions would work from CLI
        config = ConfigManager(profile=notebook.profile)
        plugins = PluginManager(config)
        plugins.extend(notebook.index)
        plugins.extend(notebook)

        if page and self.opts.get('recursive'):
            selection = SubPages(notebook, page)
        elif page:
            selection = SinglePage(notebook, page)
        else:
            selection = AllPages(notebook)

        exporter = self.get_exporter(page)
        exporter.export(selection)
Пример #16
0
	def __init__(self):
		self.config = ConfigManager() # XXX should be passed in
		self.names = []
		self.tools = {}
		self._read_list()
Пример #17
0
    def runTest(self):
        plugin = InsertSymbolPlugin(ConfigManager())

        pageview = setUpPageView()
        textview = pageview.view
        buffer = textview.get_buffer()
        pageview.undostack = UndoStackManager(buffer)

        mainwindow = tests.MockObject()
        mainwindow.pageview = pageview
        mainwindow.ui = tests.MockObject()  # XXX
        mainwindow.ui.uimanager = tests.MockObject()  # XXX
        mainwindow.ui.uistate = SectionedConfigDict()

        plugin.extend(mainwindow, 'MainWindow')

        print '\n!! Two GtkWarnings expected here for gdk display !!'
        # Need a window to get the widget realized
        window = gtk.Window()
        window.add(pageview)
        pageview.realize()
        textview.realize()

        # insert on end-of-word with space
        press(textview, r'\alpha ')
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, ALPHA + ' ')

        # Check undo - first undo replace, then the insert space
        pageview.undo()
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, r'\alpha ')
        pageview.undo()
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, r'\alpha')  # no trailing space

        # insert on end-of-word with ;
        buffer.clear()
        press(textview, r'\alpha;')
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, ALPHA)  # no trailing space

        # no insert in code or pre section
        buffer.clear()
        pageview.toggle_format(VERBATIM)
        press(textview, r'\alpha ')
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, r'\alpha ')  # no replace

        # test dialog
        def check_dialog(dialog):
            self.assertIsInstance(dialog, InsertSymbolDialog)
            dialog.iconview.item_activated(
                (9, ))  # path for 10th item in symbol list
            dialog.iconview.item_activated(
                (10, ))  # path for 11th item in symbol list
            dialog.iconview.item_activated(
                (11, ))  # path for 12th item in symbol list
            dialog.assert_response_ok()

        buffer.clear()
        mainwindow_ext = plugin.get_extension(MainWindowExtension)
        with tests.DialogContext(check_dialog):
            mainwindow_ext.insert_symbol()
        text = buffer.get_text(*buffer.get_bounds())
        self.assertEqual(text, EACUTE + ECIRC + EGRAVE)
Пример #18
0
    def testManager(self):
        '''Test CustomToolManager API'''
        # initialize the list
        manager = CustomToolManager(ConfigManager())
        self.assertEqual(list(manager), [])
        self.assertEqual(list(manager._names), [])

        # add a tool
        properties = {
            'Name': 'Foo',
            'Comment': 'Test 1 2 3',
            'Icon': '',
            'X-Zim-ExecTool': 'foo %t "quoted"',
            'X-Zim-ReadOnly': False,
            'X-Zim-ShowInToolBar': True,
        }
        tool = manager.create(**properties)
        self.assertEqual(list(manager), [tool])
        self.assertEqual(list(manager._names), ['foo-usercreated'])

        self.assertTrue(tool.isvalid)
        self.assertEqual(tool.name, 'Foo')
        self.assertEqual(tool.comment, 'Test 1 2 3')
        self.assertFalse(tool.isreadonly)
        self.assertTrue(tool.showintoolbar)
        self.assertTrue(tool.get_pixbuf(Gtk.IconSize.MENU))
        self.assertEqual(tool.showincontextmenu, 'Text')  # Auto generated

        # test file saved correctly
        #~ from pprint import pprint
        #~ pprint(tool)
        lines = tool.dump()
        self.assertTrue(len(lines) > 5)
        lines = tool.file.readlines()
        self.assertTrue(len(lines) > 5)

        # refresh list
        manager = CustomToolManager(ConfigManager())
        self.assertEqual(list(manager), [tool])
        self.assertEqual(list(manager._names), ['foo-usercreated'])

        # add a second tool
        tool1 = tool
        properties = {
            'Name': 'Foo',
            'Comment': 'Test 1 2 3',
            'Icon': None,
            'X-Zim-ExecTool': 'foo %f',
            'X-Zim-ReadOnly': False,
            'X-Zim-ShowInToolBar': True,
        }
        tool = manager.create(**properties)
        self.assertEqual(list(manager), [tool1, tool])
        self.assertEqual(list(manager._names),
                         ['foo-usercreated', 'foo-usercreated-1'])

        self.assertTrue(tool.isvalid)
        self.assertEqual(tool.name, 'Foo')
        self.assertEqual(tool.comment, 'Test 1 2 3')
        self.assertFalse(tool.isreadonly)
        self.assertTrue(tool.showintoolbar)
        self.assertTrue(tool.get_pixbuf(Gtk.IconSize.MENU))
        self.assertEqual(tool.showincontextmenu, 'Page')  # Auto generated

        # switch order
        i = manager.index(tool)
        self.assertTrue(i == 1)
        manager.reorder(tool, 0)
        i = manager.index(tool)
        self.assertTrue(i == 0)
        self.assertEqual(list(manager._names),
                         ['foo-usercreated-1', 'foo-usercreated'])

        # delete
        file = tool1.file
        self.assertTrue(file.exists())
        manager.delete(tool1)
        self.assertEqual(list(manager._names), ['foo-usercreated-1'])
        self.assertFalse(file.exists())
Пример #19
0
 def setUp(self):
     config = ConfigManager()
     list = config.get_config_file('notebooks.list')
     file = list.file
     if file.exists():
         file.remove()