Example #1
0
	def add_style(self, lang, style, row=None):
		'''
		Add a style definition to a language group if the style definition isn't
		already in the group.
		
		*lang* (``str``) is the language to add the style to.
		
		*style* (``str``) is the name of the style to add.
		
		*row* (``dict``) is optional attributes to set on the row. ``None`` by
			default to represent the default row
		'''
		lang_iter = None
		if lang not in self.styles_rows:
			language_row = GThemerRow()
			language_row['definition'] = lang
			#New iter reference to the language
			new_iter = self.treestore.append(None, language_row.get_row())
			self.styles_rows[lang] = new_iter
			lang_iter = new_iter
		else:
			lang_iter = self.styles_rows[lang]

		if not self.in_treestore(lang_iter, style):
			row = {} if row is None else row
			default_row = GThemerRow(**row)
			default_row['definition'] = style if row == {} else default_row['definition']
			self.treestore.append(self.styles_rows[lang], default_row.get_row())
Example #2
0
	def init_globals(self, globals_defaults={}):
		'''
		Initialize the globals styles in the treestore
		
		*globals_defaults* (``dict``) is optional defaults to give the globals.
		'''
		self.global_styles = sorted([glob for glob in self.styles.iter_globals()], key=lambda x: x['scheme'])
		if '__globals' in self.styles_rows:
			child_iter = self.treestore.iter_children(self.styles_rows['__globals'])
			# Clear global's children
			remove = True
			while remove != False:
				remove = self.treestore.remove(child_iter)
		else:
			default_row = GThemerRow()
			default_row['definition'] = "Global gedit Settings"
			global_iter = self.treestore.append(None, default_row.get_row())
			self.styles_rows['__globals'] = global_iter
		
		# Add new iters
		for style in self.global_styles:
			row = globals_defaults.get(style['scheme'], {})
			global_row = GThemerRow(**row)
			global_row['definition'] = style['scheme'] if row == {} else global_row['definition']
			self.treestore.append(self.styles_rows['__globals'], global_row.get_row())
Example #3
0
	def clear_style(self, widget, model, path):
		'''
		Clear style at ``path``
		'''
		style = model[path][0]
		_, __, style_text, ___ = Pango.parse_markup(style, len(style), "\0")
		default_row = GThemerRow()
		default_row['definition'] = style_text
		for i in xrange(len(default_row)):
			model[path][i] = default_row.get_row()[i]
Example #4
0
	def add_styles(self, styles):
		'''
		Add styles nodes to the tree
		'''
		assert self.tree is not None, "lxml.etree hasn't been set"

		root = self.tree.getroot()
		defn_iter = styles.iter_children(None)
		while defn_iter is not None:
			lang = GThemerRow(*[style for style in styles[defn_iter]])
			print "Lang: {}".format(lang.get_row())
			if lang['definition'] == 'Global gedit Settings':
				# Handle globals
				child_iter = styles.iter_children(defn_iter)
				while child_iter is not None:
					child = GThemerRow(*[style for style in styles[child_iter]])
					print("Global child: {}".format(child.get_row()))
					if not all(item is None for item in child):
						element = etree.Element('style')
						for row, column in self.style_columns.iteritems():
							attr = str(child[row]) if isinstance(child[row], bool) else child[row]
							if column == 'name':
								_, __, attr, ___ = Pango.parse_markup(child[row], len(child[row]), "\0")
							if attr is not None:
								element.set(column, attr)
						root.append(element)
					else:
						print("Oops, this row is empty for lang: {}. {}".format(lang['definition'], child.get_row() ))
					child_iter = styles.iter_next(child_iter)
			else:
				# Handle everything else.
				child_iter = styles.iter_children(defn_iter)
				while child_iter is not None:
					child = GThemerRow(*styles[child_iter])
					print("Child: {}".format(child.get_row()))
					if not all(item is None for item in child):
						element = etree.Element('style')
						for row, column in self.style_columns.iteritems():
							attr = str(child[row]) if isinstance(child[row], bool) else child[row]
							if column == 'name':
								_, __, attr, ___ = Pango.parse_markup(child[row], len(child[row]), "\0")
							if attr is not None:
								element.set(column, attr)
						root.append(element)
					else:
						print("Oops, this row is empty for lang: {}. {}".format(lang['definition'], child.get_row() ))
					child_iter = styles.iter_next(child_iter)
			defn_iter = styles.iter_next(defn_iter)
Example #5
0
	def add_group(self, lang_name, lang_title, styles):
		'''
		Adds an entire language group of definitions to the TreeStore. If one
		of the languages already exist in the structure
		'''	
		if lang_title not in self.styles_rows:
			# A new language is being added to the TreeStore
			# First get the reference to the new language's GtkIter and
			# add it to self.styles.
			
			# language_row -- this row is only comprised of the language name
			language_row = GThemerRow()
			language_row['definition'] = lang_title
			# New iter reference to the language
			new_iter = self.treestore.append(None, language_row.get_row())
			self.styles_rows[lang_title] = new_iter

		# Append the data to the new row.
		for defn in sorted(styles):
			if not self.in_treestore(self.styles_rows[lang_title], defn):
				default_row = GThemerRow()
				default_row['definition'] = defn
				self.treestore.append(self.styles_rows[lang_title], default_row.get_row())