Beispiel #1
0
Datei: main.py Projekt: gdw2/zim
	def get_notebook_argument(self):
		'''Get the notebook and page arguments for this command
		@returns: a 2-tuple of an L{NotebookInfo} object and an
		optional L{Path} or C{(None, None)} if the notebook
		argument is optional and not given
		@raises NotebookLookupError: if the notebook is mandatory and
		not given, or if it is given but could not be resolved
		'''
		assert self.arguments[0] in ('NOTEBOOK', '[NOTEBOOK]')
		args = self.get_arguments()
		notebook = args[0]

		if notebook is None:
			notebook = self.get_default_or_only_notebook()
			if notebook:
				logger.info('Using default notebook: %s', notebook)
			elif self.arguments[0] == 'NOTEBOOK': # not optional
				raise NotebookLookupError, _('Please specify a notebook')
					# T: Error when looking up a notebook
			else:
				return None, None

		notebookinfo = resolve_notebook(notebook)
		if not notebookinfo:
			raise NotebookLookupError, _('Could not find notebook: %s') % notebook

		if len(self.arguments) > 1 \
		and self.arguments[1] in ('PAGE', '[PAGE]') \
		and args[1] is not None:
			pagename = Notebook.cleanup_pathname(args[1], purge=True)
			return notebookinfo, Path(pagename)
		else:
			return notebookinfo, None
Beispiel #2
0
    def get_notebook_argument(self):
        '''Get the notebook and page arguments for this command
		@returns: a 2-tuple of an L{NotebookInfo} object and an
		optional L{Path} or C{(None, None)} if the notebook
		argument is optional and not given
		@raises NotebookLookupError: if the notebook is mandatory and
		not given, or if it is given but could not be resolved
		'''
        assert self.arguments[0] in ('NOTEBOOK', '[NOTEBOOK]')
        args = self.get_arguments()
        notebook = args[0]

        if notebook is None:
            notebook = self.get_default_or_only_notebook()
            if notebook:
                logger.info('Using default notebook: %s', notebook)
            elif self.arguments[0] == 'NOTEBOOK':  # not optional
                raise NotebookLookupError, _('Please specify a notebook')
                # T: Error when looking up a notebook
            else:
                return None, None

        notebookinfo = resolve_notebook(notebook)
        if not notebookinfo:
            raise NotebookLookupError, _(
                'Could not find notebook: %s') % notebook
            # T: error message

        if len(self.arguments) > 1 \
        and self.arguments[1] in ('PAGE', '[PAGE]') \
        and args[1] is not None:
            pagename = Notebook.cleanup_pathname(args[1], purge=True)
            return notebookinfo, Path(pagename)
        else:
            return notebookinfo, None
Beispiel #3
0
 def on_text_changed(self, buffer):
     if not self._title_set_manually:
         # Automatically generate a (valid) page name
         self._updating_title = True
         bounds = buffer.get_bounds()
         title = buffer.get_text(*bounds).strip()[:50]
         # Cut off at 50 characters to prevent using a whole paragraph
         title = title.replace(':', '')
         if '\n' in title:
             title, _ = title.split('\n', 1)
         try:
             title = Notebook.cleanup_pathname(title, purge=True)
             self.form['basename'] = title
         except PageNameError:
             pass
         self._updating_title = False
Beispiel #4
0
	def on_text_changed(self, buffer):
		if not self._title_set_manually:
			# Automatically generate a (valid) page name
			self._updating_title = True
			bounds = buffer.get_bounds()
			title = buffer.get_text(*bounds).strip()[:50]
				# Cut off at 50 characters to prevent using a whole paragraph
			title = title.replace(':', '')
			if '\n' in title:
				title, _ = title.split('\n', 1)
			try:
				title = Notebook.cleanup_pathname(title, purge=True)
				self.form['basename'] = title
			except PageNameError:
				pass
			self._updating_title = False