Moved common options dialog stuff to mprj

master
Yevgen Muntyan 2007-01-20 03:16:58 -06:00
parent 97f00261c5
commit 54e5c55cb5
2 changed files with 142 additions and 0 deletions

View File

@ -0,0 +1,72 @@
if __name__ == '__main__':
import sys
import os.path
dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dir, '../..'))
sys.path.insert(0, os.path.join(dir, '..'))
import gobject
import os.path
import moo
from moo.utils import _
dir = os.path.dirname(__file__)
def _init_page(page, page_id, config, glade_file):
cls = page.__class__
xml = moo.utils.GladeXML(moo.utils.GETTEXT_PACKAGE)
xml.map_id(page_id, cls)
types = getattr(cls, '__types__', {})
for id in types:
xml.map_id(id, types[id])
glade_file = open(glade_file)
try:
xml.fill_widget(page, glade_file.read(), page_id)
assert xml.get_widget(page_id) is page
finally:
glade_file.close()
label = getattr(cls, '__label__', None)
if label is not None:
page.set_property('label', label)
page.xml = xml
page.config = config
page.widgets = [xml.get_widget(k) for k in types]
return page
class ConfigPage(moo.utils.PrefsDialogPage):
def __init__(self, page_id, config, glade_file):
moo.utils.PrefsDialogPage.__init__(self)
_init_page(self, page_id, config, glade_file)
def do_init(self):
pass
def do_apply(self):
for widget in self.widgets:
widget.apply()
class Dialog(moo.utils.PrefsDialog):
def __init__(self, project, title=_('Project Options')):
moo.utils.PrefsDialog.__init__(self, title)
self.project = project
self.config_copy = project.config.copy()
def do_apply(self):
moo.utils.PrefsDialog.do_apply(self)
self.project.config.copy_from(self.config_copy)
self.project.save_config()
# print '============================='
# print self.project.config.dump_xml()
# print '============================='
gobject.type_register(ConfigPage)
gobject.type_register(Dialog)

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!-- Generated with glade3
Version: 3.0.0
Date: Thu Jan 18 20:20:28 2007
User: muntyan
Host: munt10
-->
<glade-interface>
<widget class="GtkWindow" id="window1">
<child>
<widget class="GtkVBox" id="page">
<property name="visible">True</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkEntry" id="project_dir">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Project directory:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="name">
<property name="visible">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">1.000000</property>
<property name="label" translatable="yes">Name:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</glade-interface>