Example #1
0
 def __init__(self, attrib, data, ui=None):
     if data.endswith('\n'):
         data = data[:-1]
         # If we have trailing \n it looks like an extra empty line
         # in the buffer, so we default remove one
     CustomObjectClass.__init__(self, attrib, data, ui)
     self.view = None
Example #2
0
 def __init__(self, attrib, data, preferences):
     if data.endswith('\n'):
         data = data[:-1]
         # If we have trailing \n it looks like an extra empty line
         # in the buffer, so we default remove one
     CustomObjectClass.__init__(self, attrib, data)
     self.preferences = preferences
     self.buffer = None
     self._widgets = WeakSet()
Example #3
0
	def __init__(self, attrib, data, preferences):
		if data.endswith('\n'):
			data = data[:-1]
			# If we have trailing \n it looks like an extra empty line
			# in the buffer, so we default remove one
		CustomObjectClass.__init__(self, attrib, data)
		self.preferences = preferences
		self.buffer = None
		self._widgets = WeakSet()
Example #4
0
	def __init__(self, attrib, data, ui=None):
		if data.endswith('\n'):
			data = data[:-1]
			# If we have trailing \n it looks like an extra empty line
			# in the buffer, so we default remove one
		CustomObjectClass.__init__(self, attrib, data, ui)
		self.data = None
		self.rowheader = None
		self.columnheader = None
		#self.connect('modified-changed', self.dump)
		
		self._init_widget()
Example #5
0
 def dump(self, format, dumper, linker=None):
     if format == "html":
         if self._attrib['lang']:
             # class="brush: language;" works with SyntaxHighlighter 2.0.278
             # by Alex Gorbatchev <http://alexgorbatchev.com/SyntaxHighlighter/>
             # TODO: not all GtkSourceView language ids match with SyntaxHighlighter
             # language ids.
             # TODO: some template instruction to be able to use other highlighters as well?
             output = [
                 '<pre class="brush: %s;">\n' %
                 html_encode(self._attrib['lang'])
             ]
         else:
             output = ['<pre>\n']
         data = self.get_data()
         data = html_encode(
             data)  # XXX currently dumper gives encoded lines - NOK
         if self._attrib['linenumbers']:
             for i, l in enumerate(data.splitlines(1)):
                 output.append('%i&nbsp;' % (i + 1) + l)
         else:
             output.append(data)
         output.append('</pre>\n')
         return output
     return CustomObjectClass.dump(self, format, dumper, linker)
Example #6
0
	def dump(self, format, dumper, linker=None):
		if format == "html":
			if self._attrib['lang']:
				''' to use highlight.js add the following to your template:
				<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/default.min.css">
				<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
				<script>hljs.initHighlightingOnLoad();</script>
				Map GtkSourceView language ids match with Highlight.js language ids.
				http://packages.ubuntu.com/precise/all/libgtksourceview2.0-common/filelist
				http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html
                '''
				sh_map = {'dosbatch': 'dos'}
				sh_lang = sh_map[self._attrib['lang']] if self._attrib['lang'] in sh_map else self._attrib['lang']
				# TODO: some template instruction to be able to use other highlighters as well?
				output = ['<pre><code class="%s">' % html_encode(sh_lang)] # for syntaxhigligther
				'''' class="brush: language;" works with SyntaxHighlighter 2.0.278, 3 & 4
				output = ['<pre class="brush: %s;">' % html_encode(sh_lang)] # for syntaxhigligther
				'''
			else:
				output = ['<pre>\n']
			data = self.get_data()
			data = html_encode(data) # XXX currently dumper gives encoded lines - NOK
			#if self._attrib['linenumbers']:
			#	for i, l in enumerate(data.splitlines(1)):
			#		output.append('%i&nbsp;' % (i+1) + l)
			#else:
			output.append(data) # ignoring numbering for html - syntaxhighlighter takes care of that
			if self._attrib['lang']:
				output.append('</code></pre>\n')
			else:
				output.append('</pre>\n')
			return output
		return CustomObjectClass.dump(self, format, dumper, linker)
Example #7
0
    def __init__(self, attrib, data, bibliography, pageview, ui=None):
        #if data.endswith('\n'):
        #	data = data[:-1]
        # If we have trailing \n it looks like an extra empty line
        # in the buffer, so we default remove one
        CustomObjectClass.__init__(self, attrib, data, ui)
        self.data = None
        self.pageview = pageview
        self.pageview.view.get_buffer().connect_after('delete-range',
                                                      self.on_delete_range)
        self.anchor = None
        self.label = gtk.Label("")
        #self.label = gtk.LinkButton("")

        self.bibKey = attrib['bibkey']
        self.bibliography = bibliography
        if not bibliography is None:
            self.bibliography.register_reference(self)
Example #8
0
    def __init__(self, attrib, header, rows, preferences):
        '''
		Creates a new object which can displayed within the page
		:param attrib: aligns, wraps
		:param header: titles of the table as list
		:param rows: body-rows of the table as list of lists
		:param preferences: optionally some preferences
		'''
        _attrib = {}
        for k, v in attrib.iteritems():
            if isinstance(v, list):
                v = ','.join(map(str, v))
            _attrib[k] = v
        CustomObjectClass.__init__(self, _attrib, [header] + rows)
        self.attrib = {'type': OBJECT_TYPE}  # just to be sure

        self._tableattrib = attrib
        self._header = header
        self._rows = rows
        self._widgets = WeakSet()
        self._liststore = None  # shared model between widgets

        self.preferences = preferences
Example #9
0
	def dump(self, format, dumper, linker=None):
		if format == "html":
			if 'lang' in self._attrib:
				# class="brush: language;" works with SyntaxHighlighter 2.0.278
				# by Alex Gorbatchev <http://alexgorbatchev.com/SyntaxHighlighter/>
				# TODO: not all GtkSourceView language ids match with SyntaxHighlighter
				# language ids.
				output = ['<pre class="brush: %s;">\n' % html_encode(self._attrib['lang'])]
			else:
				output = ['<pre>\n']
			data = html_encode(self.get_data())
			if self._attrib['linenumbers'] == 'true':
				for i, l in enumerate(data.splitlines(1)):
					output.append('%i ' % (i+1) + l)
			else:
				output.append(data)
			output.append('</pre>\n')
			return output
		return CustomObjectClass.dump(self, format, dumper, linker)
Example #10
0
	def dump(self, format, dumper, linker=None):
		if format == "html":
			if self._attrib['lang']:
				# class="brush: language;" works with SyntaxHighlighter 2.0.278
				# by Alex Gorbatchev <http://alexgorbatchev.com/SyntaxHighlighter/>
				# TODO: not all GtkSourceView language ids match with SyntaxHighlighter
				# language ids.
				# TODO: some template instruction to be able to use other highlighters as well?
				output = ['<pre class="brush: %s;">\n' % html_encode(self._attrib['lang'])]
			else:
				output = ['<pre>\n']
			data = self.get_data()
			data = html_encode(data) # XXX currently dumper gives encoded lines - NOK
			if self._attrib['linenumbers']:
				for i, l in enumerate(data.splitlines(1)):
					output.append('%i&nbsp;' % (i+1) + l)
			else:
				output.append(data)
			output.append('</pre>\n')
			return output
		return CustomObjectClass.dump(self, format, dumper, linker)
Example #11
0
	def __init__(self, attrib, data, ui=None):
		if data.endswith('\n'):
			data = data[:-1]
			# If we have trailing \n it looks like an extra empty line
			# in the buffer, so we default remove one
		CustomObjectClass.__init__(self, attrib, data, ui)
		if self.ui and self.ui.__class__.__name__ == 'GtkInterface': # XXX seperate widget and object
			from zim.gui.widgets import ScrolledWindow

			# SourceView scrolled window
			self.buffer = gtksourceview2.Buffer()
			self.buffer.set_text(self._data)
			self.buffer.connect('modified-changed', self.on_modified_changed)
			self.buffer.set_highlight_matching_brackets(True)
			self.buffer.set_modified(False)
			self._data = None
			self.view = gtksourceview2.View(self.buffer)
			self.view.modify_font(pango.FontDescription('monospace'))
			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)

			win = ScrolledWindow(self.view, gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER)
				# only horizontal scroll
			win.set_border_width(5)

			self._attrib.setdefault('lang', None)
			self._attrib.setdefault('linenumbers', 'true') # FIXME make boolean
			self.set_language(self._attrib['lang'], save=False)
			self.show_line_numbers(self._attrib['linenumbers'], save=False)

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

			# simple toolbar
			#~ bar = gtk.HBox() # FIXME: use gtk.Toolbar stuff
			#~ lang_selector = gtk.combo_box_new_text()
			#~ 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)

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

			# Pack everything
			box = gtk.VBox()
			#~ box.pack_start(bar, False, False)
			box.pack_start(win)
			self._widget = CustomObjectBin()
			self._widget.set_has_cursor(True)
			self._widget.add(box)

			# Hook up integration with pageview cursor movement
			def on_grab_cursor(bin, position):
				begin, end = self.buffer.get_bounds()
				if position == POSITION_BEGIN:
					self.buffer.place_cursor(begin)
				else:
					self.buffer.place_cursor(end)
				self.view.grab_focus()

			def on_move_cursor(view, step_size, count, extend_selection):
				buffer = view.get_buffer()
				iter = buffer.get_iter_at_mark(buffer.get_insert())
				if (iter.is_start() or iter.is_end()) \
				and not extend_selection:
					if iter.is_start() and count < 0:
						self._widget.release_cursor(POSITION_BEGIN)
						return None
					elif iter.is_end() and count > 0:
						self._widget.release_cursor(POSITION_END)
						return None

				return gtksourceview2.View.do_move_cursor(view, step_size, count, extend_selection)

			self._widget.connect('grab-cursor', on_grab_cursor)
			self.view.connect('move-cursor', on_move_cursor)

			# Resize widget if parent TextView has been resized -- XXX
			self.ui.mainwindow.pageview.view.connect_after('size-allocate',
												self.on_parent_view_resized)
		else:
			self.view = None
Example #12
0
    def __init__(self, attrib, text, pageview, ui=None):
        if not text is None and text.endswith('\n'):
            text = text[:-1]
            # If we have trailing \n it looks like an extra empty line
            # in the buffer, so we default remove one
        CustomObjectClass.__init__(self, attrib, text, ui)
        self.pageview = pageview
        self.referenceIds = {}
        self.references = {}
        ui.connect('close-page', self.on_close_page)

        #self.referenceStore = gtk.ListStore(str, str, str, str)
        self.referenceStore = gtk.ListStore(str, str, str)
        self.name = attrib['name']
        self.path = attrib['path']

        if not attrib.has_key('filedir'):
            self.fileDir = None
        else:
            self.fileDir = attrib['filedir']

        if not BibTexBibObject.bibliographies.has_key(pageview):
            BibTexBibObject.bibliographies[pageview] = []
        BibTexBibObject.bibliographies[pageview].append(self)

        # parse bibtex file
        def customizations(record):
            def getnames(names):
                tidynames = []
                for namestring in names:
                    namestring = namestring.strip()
                    if len(namestring) < 1:
                        continue
                    if ',' in namestring:
                        namesplit = namestring.split(',', 1)
                        last = namesplit[0].strip()
                    else:
                        namesplit = namestring.split()
                        last = namesplit.pop()
                    if last in ['jnr', 'jr', 'junior']:
                        last = firsts.pop()
                    tidynames.append(last)
                return tidynames

            def author(record):
                if "author" in record:
                    if record["author"]:
                        record["author"] = getnames([
                            i.strip() for i in record["author"].replace(
                                '\n', ' ').split(" and ")
                        ])
                    else:
                        del record["author"]
                return record

            record = author(record)
            return record

        self.parser = BibTexParser()
        self.parser.customization = customizations
        self.parse_bibtex_file()