Exemple #1
0
def interwiki_link(link):
	'''Convert an interwiki link into an url'''
	assert isinstance(link, basestring) and '?' in link
	key, page = link.split('?', 1)
	url = None
	for line in config_file('urls.list'):
		if line.startswith(key+' ') or line.startswith(key+'\t'):
			url = line[len(key):].strip()
			break
	else:
		list = get_notebook_list()
		for name, path in list.get_names():
			if name.lower() == key.lower():
				url = path + '?{NAME}'
				break

	if url and is_url_re.match(url):
		if not ('{NAME}' in url or '{URL}' in url):
			url += '{URL}'

		url = url.replace('{NAME}', page)
		url = url.replace('{URL}', url_encode(page))

		return url
	else:
		return None
Exemple #2
0
def setupGtkInterface(test, klass=None):
	'''Setup a new GtkInterface object for testing.
	Will have test notebook, and default preferences.
	@param test: the test that wants to use this ui object
	@param klass: the klass to use, defaults to L{GtkInterface}, but
	could be partially mocked subclass
	'''
	if klass is None:
		klass = zim.gui.GtkInterface

	# start filtering
	filter = FilterNoSuchImageWarning()
	filter.wrap_test(test)

	# flush preferences
	preferences = config_file('preferences.conf')
	preferences.file.remove()

	# create interface object with new notebook
	dirpath = test.get_tmp_name()
	notebook = tests.new_notebook(fakedir=dirpath)
	path = Path('Test:foo:bar')
	ui = klass(notebook=notebook, page=path)

	# finalize plugins
	for plugin in ui.plugins:
		plugin.finalize_ui(ui)

	ui.mainwindow.init_uistate()

	return ui
Exemple #3
0
 def _read_list(self):
     file = config_file('customtools/customtools.list')
     seen = set()
     for line in file.readlines():
         name = line.strip()
         if not name in seen:
             seen.add(name)
             self.names.append(name)
Exemple #4
0
	def __init__(self, notebook=None):
		gobject.GObject.__init__(self)
		self.notebook = None
		self.plugins = []

		self.preferences = config_file('preferences.conf')
		self.uistate = None

		if not notebook is None:
			self.open_notebook(notebook)
Exemple #5
0
    def get_tool(self, name):
        '''Get a L{CustomTool} by name.
        @param name: the tool name
        @returns: a L{CustomTool} object
        '''
        if not name in self.tools:
            file = config_file('customtools/%s.desktop' % name)
            tool = CustomTool(file)
            self.tools[name] = tool

        return self.tools[name]
Exemple #6
0
    def on_profile_changed(self, notebook):
        # Copy config for independent plugins
        independent_preferences = {}
        for plugin in self.plugins[:]:
            if plugin.is_profile_independent:
                independent_preferences[plugin.plugin_key] = plugin.preferences.copy()

        # Switch config
        if self.notebook.profile:
            # Load the preferences for the profile
            # In case new profile does not exist or is incomplete
            # we cary over any settings from the current one
            logger.debug("Profile changed to: %s", notebook.profile)
            basename = self.notebook.profile.lower() + ".conf"
            file = config_file(("profiles", basename))
            self.preferences.change_file(file)
            self.preferences.write()
        else:
            # Load default preferences
            # We do a full flush to reset to default
            logger.debug("Profile reset to default")
            preferences = get_config("preferences.conf")
            file = preferences.file
            self.preferences.change_file(file)
            for section in self.preferences.values():
                section.clear()
            self.preferences.read()  # HACK Forces reading default as well

        # Notify ui objects
        self.emit("preferences-changed")

        # notify plugins of possible new preferences
        # and remove old plugins
        for plugin in self.plugins[:]:
            if plugin.plugin_key in self.preferences["General"]["plugins"]:
                plugin.emit("preferences-changed")
            elif plugin.is_profile_independent:
                self.preferences["General"]["plugins"].append(plugin.plugin_key)
                plugin.preferences.update(independent_preferences[plugin.plugin_key])
            else:
                self.unload_plugin(plugin)

        # load new plugins
        self.load_plugins()
Exemple #7
0
 def load_file(self):
     self.symbols = {}
     self.symbol_order = []
     file = config_file('symbols.list')
     for line in file.readlines():
         line = line.strip()
         if not line or line.startswith('#'): continue
         try:
             if '#' in line:
                 line, _ = line.split('#', 1)
                 line = line.strip()
             shortcut, code = line.split()
             symbol = unichr(int(code))
             if not shortcut in self.symbols:
                 self.symbols[shortcut] = symbol
                 self.symbol_order.append(shortcut)
             else:
                 logger.exception('Shortcut defined twice: %s', shortcut)
         except:
             logger.exception('Could not parse symbol: %s', line)
Exemple #8
0
 def _write_list(self):
     file = config_file('customtools/customtools.list')
     file.writelines([name + '\n' for name in self.names])
Exemple #9
0
	def setUp(self):
		list = config_file('notebooks.list')
		file = list.file
		if file.exists():
			file.remove()
Exemple #10
0
 def on_edit(self, button):
     file = config_file('symbols.list')
     if self.ui.edit_config_file(file):
         self.plugin.load_file()
         self.load_symbols()
Exemple #11
0
def get_notebook_list():
	'''Returns a list of known notebooks'''
	# TODO use weakref here
	return config_file('notebooks.list', klass=NotebookList)