Add cell styles to style sheet editor

This commit is contained in:
Nick Hall 2014-08-19 23:00:37 +01:00
parent da2023b3f8
commit 0751d49adc
3 changed files with 240 additions and 1 deletions

View File

@ -163,6 +163,9 @@ class StyleSheetList(object):
for t_name in sheet.get_table_style_names():
self.write_table_style(xml_file, sheet, t_name)
for c_name in sheet.get_cell_style_names():
self.write_cell_style(xml_file, sheet, c_name)
xml_file.write('</sheet>\n')
xml_file.write('</stylelist>\n')
xml_file.close()
@ -228,6 +231,22 @@ class StyleSheetList(object):
xml_file.write('</table>\n')
xml_file.write('</style>\n')
def write_cell_style(self, xml_file, sheet, c_name):
cell = sheet.get_cell_style(c_name)
# Write out style definition
xml_file.write(
'<style name="%s">\n' % escxml(c_name) +
'<cell lborder="%d" ' % cell.get_left_border() +
'rborder="%d" ' % cell.get_right_border() +
'tborder="%d" ' % cell.get_top_border() +
'bborder="%d" ' % cell.get_bottom_border() +
'pad="%.3f" ' % cell.get_padding() +
'/>\n' +
'</style>\n'
)
def parse(self):
"""
Loads the StyleSheets from the associated file, if it exists.
@ -464,6 +483,13 @@ class SheetParser(handler.ContentHandler):
self.column_widths = []
elif tag == "column":
self.column_widths.append(int(attrs['width']))
elif tag == "cell":
self.c = TableCellStyle()
self.c.set_left_border(int(attrs['lborder']))
self.c.set_right_border(int(attrs['rborder']))
self.c.set_top_border(int(attrs['tborder']))
self.c.set_bottom_border(int(attrs['bborder']))
self.c.set_padding(glocale.float(attrs['pad']))
def endElement(self, tag):
"Overridden class that handles the end of a XML element"
@ -474,3 +500,5 @@ class SheetParser(handler.ContentHandler):
elif tag == "table":
self.t.set_column_widths(self.column_widths)
self.s.add_table_style(self.style_name, self.t)
elif tag == "cell":
self.s.add_cell_style(self.style_name, self.c)

View File

@ -50,6 +50,12 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="adjustment9">
<property name="upper">100</property>
<property name="value">0.20000000000000001</property>
<property name="step_increment">0.10000000000000001</property>
<property name="page_increment">1</property>
</object>
<object class="GtkDialog" id="editor">
<property name="can_focus">False</property>
<property name="type_hint">dialog</property>
@ -1372,6 +1378,174 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkGrid" id="grid1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<object class="GtkLabel" id="label21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="ypad">3</property>
<property name="label" translatable="yes">Borders</property>
<property name="justify">center</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="width">5</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="cell_padding">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">adjustment9</property>
<property name="climb_rate">1</property>
<property name="digits">2</property>
<property name="numeric">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label29">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Padding:</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label30">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">cm</property>
</object>
<packing>
<property name="left_attach">3</property>
<property name="top_attach">2</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkCheckButton" id="cell_lborder">
<property name="label" translatable="yes">Left</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="cell_rborder">
<property name="label" translatable="yes">Right</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="cell_tborder">
<property name="label" translatable="yes">Top</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="cell_bborder">
<property name="label" translatable="yes">Bottom</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">1</property>
<property name="width">4</property>
<property name="height">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">4</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label20">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Cell options&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="position">4</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="resize">True</property>

View File

@ -52,7 +52,7 @@ from gi.repository import Gtk, Gdk
#------------------------------------------------------------------------
from gramps.gen.plug.docgen import (StyleSheet, FONT_SERIF, FONT_SANS_SERIF,
PARA_ALIGN_RIGHT, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
PARA_ALIGN_JUSTIFY, ParagraphStyle, TableStyle)
PARA_ALIGN_JUSTIFY, ParagraphStyle, TableStyle, TableCellStyle)
from gramps.gen.constfunc import cuni
from ...listmodel import ListModel
from ...managedwindow import set_titles
@ -237,6 +237,9 @@ class StyleEditor(object):
names = _alphanumeric_sort(self.style.get_table_style_names())
for t_name in names:
self.plist.add([t_name], self.style.get_table_style(t_name))
names = _alphanumeric_sort(self.style.get_cell_style_names())
for c_name in names:
self.plist.add([c_name], self.style.get_cell_style(c_name))
self.plist.select_row(0)
if self.parent:
@ -268,6 +271,25 @@ class StyleEditor(object):
elif isinstance(self.current_style, TableStyle):
self.show_pages([0, 3])
self.draw_table()
elif isinstance(self.current_style, TableCellStyle):
self.show_pages([0, 4])
self.draw_cell()
def draw_cell(self):
"""
Updates the display with the selected cell style.
"""
c = self.current_style
self.pname.set_text( '<span size="larger" weight="bold">%s</span>' %
self.current_name)
self.pname.set_use_markup(True)
self.pdescription.set_text(_("No description available") )
self.top.get_object("cell_lborder").set_active(c.get_left_border())
self.top.get_object("cell_rborder").set_active(c.get_right_border())
self.top.get_object("cell_tborder").set_active(c.get_top_border())
self.top.get_object("cell_bborder").set_active(c.get_bottom_border())
self.top.get_object("cell_padding").set_value(c.get_padding())
def draw_table(self):
"""
@ -376,6 +398,21 @@ class StyleEditor(object):
self.save_paragraph()
elif isinstance(self.current_style, TableStyle):
self.save_table()
elif isinstance(self.current_style, TableCellStyle):
self.save_cell()
def save_cell(self):
"""
Saves the current cell style displayed on the dialog.
"""
c = self.current_style
c.set_left_border(self.top.get_object("cell_lborder").get_active())
c.set_right_border(self.top.get_object("cell_rborder").get_active())
c.set_top_border(self.top.get_object("cell_tborder").get_active())
c.set_bottom_border(self.top.get_object("cell_bborder").get_active())
c.set_padding(self.top.get_object("cell_padding").get_value())
self.style.add_cell_style(self.current_name, self.current_style)
def save_table(self):
"""