Example #1
0
    def runTest(self):
        dir = Dir(self.create_tmp_dir())
        #~ dir =  VirtualDir('/test')

        i = 0
        print ''
        for template, file in list_templates(self.format):
            print 'Testing template: %s' % template
            notebook = tests.new_notebook(fakedir='/foo')
            pages = AllPages(notebook)  # TODO - sub-section ?
            exporter = build_notebook_exporter(dir.subdir(template),
                                               self.format, template)
            self.assertIsInstance(exporter, MultiFileExporter)

            with tests.LoggingFilter('zim.formats.latex',
                                     'Could not find latex equation'):
                exporter.export(pages)

            file = exporter.layout.page_file(Path('roundtrip'))
            text = file.read()
            self.assertIn('Lorem ipsum dolor sit amet', text)

            i += 1

        if self.format in ('html', 'latex'):
            self.assertTrue(i >= 3)
Example #2
0
    def runTest(self):
        output_folder = self.setUpFolder()
        notebook = self.setUpNotebook(content=tests.FULL_NOTEBOOK)

        i = 0
        print('')
        for template, file in list_templates(self.format):
            #print 'Testing template: %s' % template
            pages = AllPages(notebook)  # TODO - sub-section ?
            exporter = build_notebook_exporter(output_folder.folder(template),
                                               self.format, template)
            self.assertIsInstance(exporter, MultiFileExporter)

            with tests.LoggingFilter('zim.formats.latex',
                                     'Could not find latex equation'):
                exporter.export(pages)

            file = exporter.layout.page_file(Path('roundtrip'))
            text = file.read()
            self.assertIn('Lorem ipsum dolor sit amet', text)

            i += 1

        if self.format in ('html', 'latex'):
            self.assertTrue(i >= 3)  # Ensure we actually tested something ..
Example #3
0
	def __init__(self, widget, navigation, notebook, path=None, subpage=False):
		if subpage:
			title = _('New Page in %s') % path # T: Dialog title
		else:
			title = _('New Page') # T: Dialog title

		Dialog.__init__(self, widget, title,
			help_text=_(
				'Please note that linking to a non-existing page\n'
				'also creates a new page automatically.'),
			# T: Dialog text in 'new page' dialog
			help=':Help:Pages'
		)
		self.notebook = notebook
		self.navigation = navigation

		default = notebook.get_page_template_name(path)
		templates = [t[0] for t in list_templates('wiki')]
		if not default in templates:
			templates.insert(0, default)

		self.add_form([
			('page', 'page', _('Page Name'), path), # T: Input label
			('template', 'choice', _('Page Template'), templates) # T: Choice label
		])
		self.form['template'] = default
		# TODO: reset default when page input changed -
		# especially if namespace has other template

		self.form.set_default_activate('page') # close dialog on <Enter> immediatly, do not select template

		if subpage:
			self.form.widgets['page'].subpaths_only = True
	def refresh(self):
		model = self.get_model()
		model.clear()
		for category in list_template_categories():
			parent = model.append(None, (category, None, None))
			for name, basename in list_templates(category):
				base = XDG_DATA_HOME.file(('zim', 'templates', category, basename))
				default = data_file(('templates', category, basename)) # None if not existing
				#~ print '>>>', name, base, default
				model.append(parent, (name, base, default))

		self.expand_all()
	def refresh(self):
		model = self.get_model()
		model.clear()
		for category in list_template_categories():
			parent = model.append(None, (category, None, None))
			for name, basename in list_templates(category):
				base = XDG_DATA_HOME.file(('zim', 'templates', category, basename))
				default = data_file(('templates', category, basename)) # None if not existing
				#~ print('>>>', name, base, default)
				model.append(parent, (name, base, default))

		self.expand_all()
Example #6
0
	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())
Example #7
0
    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())
Example #8
0
    def __init__(self, notebookinfo=None, port=8080, public=True, **opts):
        '''Constructor
		@param notebookinfo: the notebook location
		@param port: the http port to serve on
		@param public: allow connections to the server from other
		computers - if C{False} can only connect from localhost
		@param opts: options for L{WWWInterface.__init__()}
		'''
        GObject.GObject.__init__(self)
        self.set_title('Zim - ' + _('Web Server'))  # T: Window title
        self.set_border_width(10)
        self.interface_opts = opts
        self.httpd = None
        self._source_id = None

        # Widgets
        self.status_label = Gtk.Label()
        self.status_label.set_markup('<i>' + _('Server not started') + '</i>')
        # T: Status in web server gui
        self.start_button = IconButton('gtk-media-play')
        self.start_button.connect('clicked', lambda o: self.start())
        self.stop_button = IconButton('gtk-media-stop')
        self.stop_button.connect('clicked', lambda o: self.stop())
        self.stop_button.set_sensitive(False)

        self.link_button = Gtk.LinkButton('')
        self.link_button.set_sensitive(False)

        self.notebookcombobox = NotebookComboBox(current=notebookinfo)
        self.open_button = IconButton('gtk-index')
        self.open_button.connect('clicked',
                                 lambda *a: NotebookDialog(self).run())

        self.portentry = Gtk.SpinButton()
        self.portentry.set_numeric(True)
        self.portentry.set_range(80, 10000)
        self.portentry.set_increments(1, 80)
        self.portentry.set_value(port)

        self.public_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Allow public access'))
        # T: Checkbox in web server gui
        self.public_checkbox.set_active(public)

        self.templatecombobox = Gtk.ComboBoxText.new()
        template_names = [name for name, _ in list_templates('html')]
        for name in template_names:
            self.templatecombobox.append_text(name)
        self.templatecombobox.set_active(template_names.index('Default'))

        self.auth_checkbox = Gtk.CheckButton.new_with_mnemonic(
            _('Require authentication'))
        # T: checkbox in dialog for starting webserver
        self.username_input = InputEntry()
        self.password_input = InputEntry()
        self.password_input.set_visibility(False)

        # Build the interface
        vbox = Gtk.VBox()
        self.add(vbox)

        hbox = Gtk.HBox(spacing=12)
        hbox.pack_start(self.start_button, False, True, 0)
        hbox.pack_start(self.stop_button, False, True, 0)
        hbox.pack_start(self.status_label, False, True, 0)
        vbox.pack_start(hbox, False, False, 0)

        table = input_table_factory((
            (_('Notebook'), self.notebookcombobox, self.open_button),
            # T: Field in web server gui
            (_('Port'), self.portentry),
            # T: Field in web server gui for HTTP port (e.g. port 80)
            (_('Template'), self.templatecombobox),
            # T: Field in web server gui for webpage template
            self.public_checkbox,
            self.auth_checkbox,
            (_('Username'), self.username_input),
            # T: Field in web server gui
            (_('Password'), self.password_input)
            # T: Field in web server gui
        ))
        vbox.pack_start(table, False, False, 0)

        if self.link_button:
            hbox = Gtk.HBox()
            hbox.pack_end(self.link_button, False, True, 0)
            vbox.pack_start(hbox, False, False, 0)