Esempio n. 1
0
    def run(self):
        config = ConfigManager()
        preferences = config.get_config_dict(
            'preferences.conf')['TrayIconPlugin']
        preferences.setdefault('classic', False)

        set_global_trayicon(preferences['classic'])
	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
Esempio n. 4
0
	def testChangeFont(self):
		preferences = ConfigManager.get_config_dict('preferences.conf')
		window = MyWindow()

		text_style = ConfigManager.get_config_dict('style.conf')
		text_style['TextView'].setdefault('font', None, str)
		text_style['TextView']['font'] = 'Sans 12'

		dialog = PreferencesDialog(window)
		self.assertEqual(dialog.forms['Interface']['use_custom_font'], True)
		dialog.assert_response_ok()
		self.assertEqual(text_style['TextView']['font'], 'Sans 12')
		self.assertFalse(any(['use_custom_font' in d for d in list(preferences.values())]))

		text_style['TextView']['font'] = 'Sans 12'
		dialog = PreferencesDialog(window)
		self.assertEqual(dialog.forms['Interface']['use_custom_font'], True)
		dialog.forms['Interface']['use_custom_font'] = False
		dialog.assert_response_ok()
		self.assertEqual(text_style['TextView']['font'], None)
		self.assertFalse(any(['use_custom_font' in d for d in list(preferences.values())]))
Esempio n. 5
0
	def testSetSimpleValue(self):
		preferences = ConfigManager.get_config_dict('preferences.conf')
		window = MyWindow()

		dialog = PreferencesDialog(window)
		self.assertEqual(dialog.forms['Interface']['toggle_on_ctrlspace'], False)
		dialog.assert_response_ok()
		self.assertEqual(preferences['GtkInterface']['toggle_on_ctrlspace'], False)

		dialog = PreferencesDialog(window)
		dialog.forms['Interface']['toggle_on_ctrlspace'] = True
		dialog.assert_response_ok()
		self.assertEqual(preferences['GtkInterface']['toggle_on_ctrlspace'], True)
Esempio n. 6
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()
Esempio n. 7
0
def mount_notebook(filepath):
	from zim.config import ConfigManager, String

	configdict = ConfigManager.get_config_dict('automount.conf')

	groups = sorted([k for k in list(configdict.keys()) if k.startswith('Path')])
	for group in groups:
		path = group[4:].strip() # len('Path') = 4
		dir = Dir(path)
		if is_relevant_mount_point(dir, filepath):
			configdict[group].define(mount=String(None))
			handler = ApplicationMountPointHandler(dir, **configdict[group])
			if handler(filepath):
				break
Esempio n. 8
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()
Esempio n. 9
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
Esempio n. 10
0
File: trayicon.py Progetto: gdw2/zim
	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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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, basestring):
			notebook = notebook.uri

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

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

		# TODO dropdown could use an option "Other..."
		label = gtk.Label(_('Notebook')+': ')
		label.set_alignment(0.0, 0.5)
		self.form.attach(label, 0,1, 0,1, xoptions=gtk.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)
Esempio n. 14
0
	def _init_view(self):
		self.buffer.object_attrib.connect('changed', self.on_attrib_changed)

		self.view = GtkSource.View()
		self.view.set_buffer(self.buffer)
		self.view.set_auto_indent(True)
		self.view.set_smart_home_end(True)
		self.view.set_highlight_current_line(True)
		self.view.set_right_margin_position(80)
		self.view.set_show_right_margin(True)
		self.view.set_tab_width(4)
		self.view.set_show_line_numbers(self.buffer.object_attrib['linenumbers'])
		self.view.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
		self.view.set_border_width(3)

		self.WRAP_MODE = {
			WRAP_NONE: Gtk.WrapMode.NONE,
			WRAP_WORD_CHAR: Gtk.WrapMode.WORD_CHAR,
			WRAP_CHAR: Gtk.WrapMode.CHAR,
			WRAP_WORD: Gtk.WrapMode.WORD,
		}

		text_style = ConfigManager.get_config_dict('style.conf')
		try:
			font = text_style['Tag code']['family']
		except KeyError:
			font = 'monospace'
		finally:
			self.view.modify_font(Pango.FontDescription(font))

		# simple toolbar
		#~ bar = Gtk.HBox() # FIXME: use Gtk.Toolbar stuff
		#~ lang_selector = Gtk.ComboBoxText()
		#~ lang_selector.append_text('(None)')
		#~ for l in lang_names: lang_selector.append_text(l)
		#~ try:
			#~ lang_selector.set_active(lang_ids.index(self._attrib['lang'])+1)
			#~ self.set_language(self._attrib['lang'] or None, False)
		#~ except (ValueError, KeyError):
			#~ lang_selector.set_active(0)
			#~ self.set_language(None, False)
		#~ lang_selector.connect('changed', self.on_lang_changed)
		#~ bar.pack_start(lang_selector, False, False)

		#~ line_numbers = Gtk.ToggleButton('Line numbers')
		#~ try:
			#~ line_numbers.set_active(self._attrib['linenumbers']=='true')
			#~ self.show_line_numbers(self._attrib['linenumbers'], False)
		#~ except (ValueError, KeyError):
			#~ line_numbers.set_active(True)
			#~ self.show_line_numbers(True, False)
		#~ line_numbers.connect('toggled', self.on_line_numbers_toggled)
		#~ bar.pack_start(line_numbers, False, False)
		#~ self.add_header(bar)

		# TODO: other toolbar options
		# TODO: autohide toolbar if textbuffer is not active

		win = ScrolledWindow(self.view, Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.NEVER, Gtk.ShadowType.NONE)
		self.add(win)

		self.view.connect('populate-popup', self.on_populate_popup)