def runTest(self): from zim.gui.notebookdialog import NotebookComboBox, NotebookTreeModel class MyList(list): pass notebooklist = MyList([ NotebookInfo('file:///test/foo', name='Foo'), NotebookInfo('file:///test/bar', name='Bar') ]) notebooklist.default = notebooklist[1] notebooklist.write = lambda: None model = NotebookTreeModel(notebooklist) combobox = NotebookComboBox(model) self.assertEqual(combobox.get_notebook(), notebooklist[1].uri) # default combobox.set_active(-1) self.assertEqual(combobox.get_notebook(), None) combobox.set_notebook(notebooklist[0].uri) self.assertEqual(combobox.get_notebook(), notebooklist[0].uri) combobox.set_notebook('file:///yet/another/notebook') self.assertEqual(combobox.get_notebook(), None) combobox.set_notebook('file:///yet/another/notebook', append=True) self.assertEqual(combobox.get_notebook(), 'file:///yet/another/notebook')
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)
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__()} ''' gtk.Window.__init__(self) self.set_title('Zim - ' + _('Web Server')) # T: Window title self.set_border_width(10) self.connect('destroy', lambda a: gtk.main_quit()) 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) if gtk.gtk_version >= (2, 10): self.link_button = gtk.LinkButton('') self.link_button.set_sensitive(False) gtk.link_button_set_uri_hook(lambda o, url: webbrowser.open(url)) else: self.link_button = None 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(label=_('Allow public access')) # T: Checkbox in web server gui self.public_checkbox.set_active(public) # Build the interface vbox = gtk.VBox() self.add(vbox) hbox = gtk.HBox(spacing=12) hbox.pack_start(self.start_button, False) hbox.pack_start(self.stop_button, False) hbox.pack_start(self.status_label, False) vbox.add(hbox) 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) self.public_checkbox)) vbox.add(table) if self.link_button: hbox = gtk.HBox() hbox.pack_end(self.link_button, False) vbox.add(hbox)
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)