Beispiel #1
0
	def runTest(self):
		'''Test proper linking of files in export'''
		notebook = tests.new_notebook(fakedir='/source/dir/')

		linker = StaticLinker('html', notebook)
		linker.set_usebase(True) # normally set by html format module
		linker.set_path(Path('foo:bar')) # normally set by exporter
		linker.set_base(Dir('/source/dir/foo')) # normally set by exporter

		self.assertEqual(linker.link_page('+dus'), './bar/dus.html')
		self.assertEqual(linker.link_page('dus'), './dus.html')
		self.assertEqual(linker.link_file('./dus.pdf'), './bar/dus.pdf')
		self.assertEqual(linker.link_file('../dus.pdf'), './dus.pdf')
		self.assertEqual(linker.link_file('../../dus.pdf'), '../dus.pdf')

		## setup environment for interwiki link
		if os.name == 'nt':
			uri = 'file:///C:/foo'
		else:
			uri = 'file:///foo'

		list = get_notebook_list()
		list.append(NotebookInfo(uri, interwiki='foo'))
		list.write()
		##

		href = interwiki_link('foo?Ideas:Task List')
		self.assertIsNotNone(href)
		self.assertEqual(linker.link('foo?Ideas:Task List'), uri + '/Ideas/Task_List.txt')
Beispiel #2
0
    def list_all_notebooks(self):
        '''Returns a list of all notebooks known in the current context

		This method mixes notebooks from L{list_open_notebooks()} with
		input from L{get_notebook_list()}. Open notebooks will have
		the C{active} attribute set.

		@returns: a list of L{NotebookInfo} objects
		'''
        uris = set()
        notebooks = [info for info in get_notebook_list()]
        for info in self.list_open_notebooks():
            if info in notebooks:
                # info from notebook list is updated already
                i = notebooks.index(info)
                notebooks[i].active = True
            else:
                info.update()
                info.active = True
                notebooks.append(info)

        for info in notebooks:
            if not info.active:
                info.active = False  # None -> False

        return notebooks
Beispiel #3
0
    def runTest(self):
        '''Test proper linking of files in export'''
        notebook = tests.new_notebook(fakedir='/source/dir/')

        linker = StaticLinker('html', notebook)
        linker.set_usebase(True)  # normally set by html format module
        linker.set_path(Path('foo:bar'))  # normally set by exporter
        linker.set_base(Dir('/source/dir/foo'))  # normally set by exporter

        self.assertEqual(linker.link_page('+dus'), './bar/dus.html')
        self.assertEqual(linker.link_page('dus'), './dus.html')
        self.assertEqual(linker.link_file('./dus.pdf'), './bar/dus.pdf')
        self.assertEqual(linker.link_file('../dus.pdf'), './dus.pdf')
        self.assertEqual(linker.link_file('../../dus.pdf'), '../dus.pdf')

        ## setup environment for interwiki link
        if os.name == 'nt':
            uri = 'file:///C:/foo'
        else:
            uri = 'file:///foo'

        list = get_notebook_list()
        list.append(NotebookInfo(uri, interwiki='foo'))
        list.write()
        ##

        href = interwiki_link('foo?Ideas:Task List')
        self.assertIsNotNone(href)
        self.assertEqual(linker.link('foo?Ideas:Task List'),
                         uri + '/Ideas/Task_List.txt')
Beispiel #4
0
    def list_all_notebooks(self):
        '''Returns a list of all notebooks known in the current context

        This method mixes notebooks from L{list_open_notebooks()} with
        input from L{get_notebook_list()}. Open notebooks will have
        the C{active} attribute set.

        @returns: a list of L{NotebookInfo} objects
        '''
        uris = set()
        notebooks = [info for info in get_notebook_list()]
        for info in self.list_open_notebooks():
            if info in notebooks:
                # info from notebook list is updated already
                i = notebooks.index(info)
                notebooks[i].active = True
            else:
                info.update()
                info.active = True
                notebooks.append(info)

        for info in notebooks:
            if not info.active:
                info.active = False # None -> False

        return notebooks
Beispiel #5
0
	def get_default_or_only_notebook(self):
		'''Helper to get a default notebook'''
		notebooks = get_notebook_list()
		if notebooks.default:
			return notebooks.default.uri
		elif len(notebooks) == 1:
			return notebooks[0].uri
		else:
			return None
Beispiel #6
0
Datei: main.py Projekt: gdw2/zim
	def get_default_or_only_notebook(self):
		'''Helper to get a default notebook'''
		notebooks = get_notebook_list()
		if notebooks.default:
			return notebooks.default.uri
		elif len(notebooks) == 1:
			return notebooks[0].uri
		else:
			return None
Beispiel #7
0
def _get_default_or_only_notebook():
    # Helper used below to decide a good default to open
    from zim.notebook import get_notebook_list

    notebooks = get_notebook_list()
    if notebooks.default:
        return notebooks.default.uri
    elif len(notebooks) == 1:
        return notebooks[0].uri
    else:
        return None
Beispiel #8
0
    def get_default_or_only_notebook(self):
        '''Helper to get a default notebook'''
        notebooks = get_notebook_list()
        if notebooks.default:
            uri = notebooks.default.uri
        elif len(notebooks) == 1:
            uri = notebooks[0].uri
        else:
            return None

        return resolve_notebook(uri, pwd=self.pwd)  # None if not found
Beispiel #9
0
    def runTest(self):
        dir = Dir(self.get_tmp_name())
        notebook = tests.new_notebook(fakedir=dir.subdir('notebook'))
        for name in (
                'foo',
                'bar',
                'foo:bar',
        ):
            p = notebook.get_page(Path(name))
            p.parse('wiki', "test 123")
            notebook.store_page(p)

        layout = MultiFileLayout(dir.subdir('layout'), 'html')
        source = Path('foo:bar')
        output = layout.page_file(source)

        linker = ExportLinker(notebook,
                              layout,
                              source=source,
                              output=output,
                              usebase=True)

        self.assertEqual(linker.link('+dus'), './bar/dus.html')
        self.assertEqual(linker.link('dus'), './dus.html')
        self.assertEqual(linker.link('./dus.pdf'), './bar/dus.pdf')
        self.assertEqual(linker.link('../dus.pdf'), './dus.pdf')
        self.assertEqual(linker.link('../../dus.pdf'), '../dus.pdf')
        self.assertEqual(linker.link('/dus.pdf'), File('/dus.pdf').uri)

        # TODO:
        # 	img
        # 	icon
        # 	resource
        # 	resolve_source_file
        # 	page_object
        # 	file_object
        #
        #	document_root_url

        ## setup environment for interwiki link
        if os.name == 'nt':
            uri = 'file:///C:/foo'
        else:
            uri = 'file:///foo'

        list = get_notebook_list()
        list.append(NotebookInfo(uri, interwiki='foo'))
        list.write()
        ##

        href = interwiki_link('foo?Ideas:Task List')
        self.assertIsNotNone(href)
        self.assertEqual(linker.link('foo?Ideas:Task List'),
                         uri + '/Ideas/Task_List.txt')
Beispiel #10
0
    def runTest(self):
        notebook = self.setUpNotebook(content=(
            'foo',
            'bar',
            'foo:bar',
        ))
        dir = Dir(notebook.folder.parent().folder('layout').path)

        layout = MultiFileLayout(dir.subdir('layout'), 'html')
        source = Path('foo:bar')
        output = layout.page_file(source)

        linker = ExportLinker(notebook,
                              layout,
                              source=source,
                              output=output,
                              usebase=True)

        self.assertEqual(linker.link('+dus'), './bar/dus.html')
        self.assertEqual(linker.link('dus'), './dus.html')
        self.assertEqual(linker.link('./dus.pdf'), './bar/dus.pdf')
        self.assertEqual(linker.link('../dus.pdf'), './dus.pdf')
        self.assertEqual(linker.link('../../dus.pdf'), '../dus.pdf')

        extpath = 'C:\\dus.pdf' if os.name == 'nt' else '/duf.pdf'
        self.assertEqual(linker.link(extpath), FilePath(extpath).uri)

        # TODO:
        # 	img
        # 	icon
        # 	resource
        # 	resolve_source_file
        # 	page_object
        # 	file_object
        #
        #	document_root_url

        ## setup environment for interwiki link
        if os.name == 'nt':
            uri = 'file:///C:/foo'
        else:
            uri = 'file:///foo'

        list = get_notebook_list()
        list.append(NotebookInfo(uri, interwiki='foo'))
        list.write()
        ##

        href = interwiki_link('foo?Ideas:Task List')
        self.assertIsNotNone(href)
        self.assertEqual(linker.link('foo?Ideas:Task List'),
                         uri + '/Ideas/Task_List.txt')
Beispiel #11
0
 def do_activate(self):
     open_notebooks = list(self.list_open_notebooks())
     if len(open_notebooks) == 0:
         # No open notebooks, open default or prompt full list
         notebooks = get_notebook_list()
         if notebooks.default:
             self.do_activate_notebook(notebooks.default)
         else:
             self.do_popup_menu_notebooks(notebooks)
     elif len(open_notebooks) == 1:
         # Only one open notebook - present it
         self.do_activate_notebook(open_notebooks[0].uri)
     else:
         # Let the user choose from the open notebooks
         self.do_popup_menu_notebooks(open_notebooks)
Beispiel #12
0
 def do_activate(self):
     open_notebooks = list(self.list_open_notebooks())
     if len(open_notebooks) == 0:
         # No open notebooks, open default or prompt full list
         notebooks = get_notebook_list()
         if notebooks.default:
             self.do_activate_notebook(notebooks.default.uri)
         else:
             self.do_popup_menu_notebooks(notebooks)
     elif len(open_notebooks) == 1:
         # Only one open notebook - present it
         self.do_activate_notebook(open_notebooks[0].uri)
     else:
         # Let the user choose from the open notebooks
         self.do_popup_menu_notebooks(open_notebooks)
	def __init__(self, notebooklist=None):
		'''Constructor. If "notebooklist" is None, the default list as
		provided by zim.notebook.get_notebook_list() is used.
		'''
		gtk.ListStore.__init__(self, bool, str, str) # OPEN_COL, NAME_COL, PATH_COL

		if notebooklist is None:
			self.notebooklist = get_notebook_list()
		else:
			self.notebooklist = notebooklist

		self._loading = True
		for name, path in self.notebooklist.get_names():
			self.append((False, name, path))
		self._loading = False
Beispiel #14
0
	def do_popup_menu(self, button=3, activate_time=0):
		menu = gtk.Menu()

		list = get_notebook_list()
		self._populate_menu_notebooks(menu, list.get_names())

		item = gtk.MenuItem(_('_Other...')) # T: menu item in tray icon menu
		item.connect_object('activate', self.__class__.do_open_notebook, self)
		menu.append(item)

		menu.append(gtk.SeparatorMenuItem())

		item = gtk.MenuItem(_('_Quit')) # T: menu item in tray icon menu
		item.connect_object('activate', self.__class__.do_quit, self)
		menu.append(item)

		menu.show_all()
		menu.popup(None, None, gtk.status_icon_position_menu, button, activate_time, self)
Beispiel #15
0
	def __init__(self, notebooklist=None):
		'''Constructor. If "notebooklist" is None, the default list as
		provided by zim.notebook.get_notebook_list() is used.

		@param notebooklist: a list of L{NotebookInfo} objects
		'''
		gtk.ListStore.__init__(self, bool, str, str, gtk.gdk.Pixbuf, object)
						# OPEN_COL, NAME_COL, TEXT_COL PIXBUF_COL INFO_COL

		if notebooklist is None:
			self.notebooklist = get_notebook_list()
		else:
			self.notebooklist = notebooklist

		self._loading = True
		for info in self.notebooklist:
			self._append(info)
		self._loading = False
Beispiel #16
0
	def __init__(self, notebooklist=None):
		'''Constructor. If "notebooklist" is None, the default list as
		provided by zim.notebook.get_notebook_list() is used.

		@param notebooklist: a list of L{NotebookInfo} objects
		'''
		gtk.ListStore.__init__(self, bool, str, str, gtk.gdk.Pixbuf, object)
						# OPEN_COL, NAME_COL, TEXT_COL PIXBUF_COL INFO_COL

		if notebooklist is None:
			self.notebooklist = get_notebook_list()
		else:
			self.notebooklist = notebooklist

		self._loading = True
		for info in self.notebooklist:
			self._append(info)
		self._loading = False
def prompt_notebook():
	'''Prompts the NotebookDialog and returns the result or None.
	As a special case for first time usage it immediatly prompts for
	the notebook location without showing the notebook list.
	'''
	list = get_notebook_list()
	if not list:
		logger.debug('First time usage - prompt for notebook folder')
		fields = AddNotebookDialog(ui=None).run()
		if fields:
			dir = Dir(fields['folder'])
			init_notebook(dir, name=fields['name'])
			list.append(dir.uri)
			list.write()
			return dir
		else:
			return None # User cancelled the dialog ?
	else:
		# Multiple notebooks defined and no default
		return NotebookDialog(ui=None).run()
Beispiel #18
0
def prompt_notebook():
    """Prompts the NotebookDialog and returns the result or None.
    As a special case for first time usage it immediately prompts for
    the notebook location without showing the notebook list.
    """
    list = get_notebook_list()
    if len(list) == 0:
        logger.debug("First time usage - prompt for notebook folder")
        fields = AddNotebookDialog(ui=None).run()
        if fields:
            dir = Dir(fields["folder"])
            init_notebook(dir, name=fields["name"])
            list.append(NotebookInfo(dir.uri, name=fields["name"]))
            list.write()
            return dir.uri
        else:
            return None  # User canceled the dialog ?
    else:
        # Multiple notebooks defined and no default
        return NotebookDialog(ui=None).run()
Beispiel #19
0
def prompt_notebook():
	'''Prompts the NotebookDialog and returns the result or None.
	As a special case for first time usage it immediately prompts for
	the notebook location without showing the notebook list.
	@returns: a L{NotebookInfo} object or C{None}
	'''
	list = get_notebook_list()
	if len(list) == 0:
		logger.debug('First time usage - prompt for notebook folder')
		fields = AddNotebookDialog(ui=None).run()
		if fields:
			dir = Dir(fields['folder'])
			init_notebook(dir, name=fields['name'])
			list.append(NotebookInfo(dir.uri, name=fields['name']))
			list.write()
			return NotebookInfo(dir.uri, name=fields['name'])
		else:
			return None # User canceled the dialog ?
	else:
		# Multiple notebooks defined and no default
		return NotebookDialog(ui=None).run()
Beispiel #20
0
    def runTest(self):
        from zim.gui.notebookdialog import prompt_notebook, \
         AddNotebookDialog, NotebookDialog

        tmpdir = self.create_tmp_dir()
        dir1 = Dir(tmpdir + '/mynotebook1')
        dir2 = Dir(tmpdir + '/mynotebook2')

        # First time we get directly the AddNotebookDialog
        def doAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, AddNotebookDialog))
            dialog.form['name'] = 'Foo'
            dialog.form['folder'] = dir1.path
            dialog.assert_response_ok()

        with tests.DialogContext(doAddNotebook):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir1.uri)

        # Second time we get the list
        def testNotebookDialog(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))
            selection = dialog.treeview.get_selection()
            selection.select_path((0, ))  # select first and only notebook
            dialog.assert_response_ok()

        with tests.DialogContext(testNotebookDialog):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir1.uri)

        # Third time we add a notebook and set the default
        def doAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, AddNotebookDialog))
            dialog.form['name'] = 'Bar'
            dialog.form['folder'] = dir2.path
            dialog.assert_response_ok()

        def testAddNotebook(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))

            with tests.DialogContext(doAddNotebook):
                dialog.do_add_notebook()

            dialog.combobox.set_active(0)

            selection = dialog.treeview.get_selection()
            selection.select_path((1, ))  # select newly added notebook
            dialog.assert_response_ok()

        with tests.DialogContext(testAddNotebook):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir2.uri)

        # Check the notebook exists and the notebook list looks like it should
        for dir in (dir1, dir2):
            self.assertTrue(dir.exists())
            self.assertTrue(dir.file('notebook.zim').exists())

        list = get_notebook_list()
        self.assertTrue(len(list) == 2)
        self.assertEqual(list[0], NotebookInfo(dir1.uri, name='Foo'))
        self.assertEqual(list[1], NotebookInfo(dir2.uri, name='Bar'))
        self.assertEqual(list.default, NotebookInfo(dir1.uri, name='Foo'))

        # Now unset the default and again check the notebook list
        def unsetDefault(dialog):
            self.assertTrue(isinstance(dialog, NotebookDialog))
            dialog.combobox.set_active(-1)
            selection = dialog.treeview.get_selection()
            selection.select_path((1, ))  # select newly added notebook
            dialog.assert_response_ok()

        with tests.DialogContext(unsetDefault):
            info = prompt_notebook()
            self.assertIsNotNone(info)
            self.assertEqual(info.uri, dir2.uri)

        list = get_notebook_list()
        self.assertTrue(len(list) == 2)
        self.assertTrue(list.default is None)
Beispiel #21
0
	def runTest(self):
		from zim.gui.notebookdialog import prompt_notebook, \
			AddNotebookDialog, NotebookDialog

		tmpdir = self.create_tmp_dir()
		dir1 = Dir(tmpdir + '/mynotebook1')
		dir2 = Dir(tmpdir + '/mynotebook2')

		# First time we get directly the AddNotebookDialog
		def doAddNotebook(dialog):
			self.assertTrue(isinstance(dialog, AddNotebookDialog))
			dialog.form['name'] = 'Foo'
			dialog.form['folder'] = dir1.path
			dialog.assert_response_ok()

		with tests.DialogContext(doAddNotebook):
			self.assertEqual(prompt_notebook(), dir1.uri)

		# Second time we get the list
		def testNotebookDialog(dialog):
			self.assertTrue(isinstance(dialog, NotebookDialog))
			selection = dialog.treeview.get_selection()
			selection.select_path((0,)) # select first and only notebook
			dialog.assert_response_ok()

		with tests.DialogContext(testNotebookDialog):
			self.assertEqual(prompt_notebook(), dir1.uri)

		# Third time we add a notebook and set the default
		def doAddNotebook(dialog):
			self.assertTrue(isinstance(dialog, AddNotebookDialog))
			dialog.form['name'] = 'Bar'
			dialog.form['folder'] = dir2.path
			dialog.assert_response_ok()

		def testAddNotebook(dialog):
			self.assertTrue(isinstance(dialog, NotebookDialog))

			with tests.DialogContext(doAddNotebook):
				dialog.do_add_notebook()

			dialog.combobox.set_active(0)

			selection = dialog.treeview.get_selection()
			selection.select_path((1,)) # select newly added notebook
			dialog.assert_response_ok()

		with tests.DialogContext(testAddNotebook):
			self.assertEqual(prompt_notebook(), dir2.uri)

		# Check the notebook exists and the notebook list looks like it should
		for dir in (dir1, dir2):
			self.assertTrue(dir.exists())
			self.assertTrue(dir.file('notebook.zim').exists())

		list = get_notebook_list()
		self.assertTrue(len(list) == 2)
		self.assertEqual(list[0], NotebookInfo(dir1.uri, name='Foo'))
		self.assertEqual(list[1], NotebookInfo(dir2.uri, name='Bar'))
		self.assertEqual(list.default, NotebookInfo(dir1.uri, name='Foo'))

		# Now unset the default and again check the notebook list
		def unsetDefault(dialog):
			self.assertTrue(isinstance(dialog, NotebookDialog))
			dialog.combobox.set_active(-1)
			selection = dialog.treeview.get_selection()
			selection.select_path((1,)) # select newly added notebook
			dialog.assert_response_ok()

		with tests.DialogContext(unsetDefault):
			self.assertEqual(prompt_notebook(), dir2.uri)

		list = get_notebook_list()
		self.assertTrue(len(list) == 2)
		self.assertTrue(list.default is None)
Beispiel #22
0
	def _list_open_notebooks(self):
		list = get_notebook_list()
		for uri in self.daemon.list_notebooks():
			name = list.get_name(uri) or uri
			yield name, uri