Better projects

master
Yevgen Muntyan 2007-01-20 02:01:58 -06:00
parent f2397e77f5
commit eb38443c4b
11 changed files with 365 additions and 729 deletions

View File

@ -36,7 +36,7 @@
</configure> </configure>
</optimized> </optimized>
</configurations> </configurations>
<file_selector_dir>/home/muntyan/projects/moo/moo/mooutils/</file_selector_dir> <file_selector_dir>/home/muntyan/projects/moo/moo/moopython/plugins/pyproject/mprj/</file_selector_dir>
<run> <run>
<args>--g-fatal-warnings --new-app --mode=project</args> <args>--g-fatal-warnings --new-app --mode=project</args>
<exe>medit/medit</exe> <exe>medit/medit</exe>

View File

@ -15,9 +15,11 @@ nobase_plugin_DATA = \
mprj/__init__.py \ mprj/__init__.py \
mprj/manager.py \ mprj/manager.py \
mprj/project.py \ mprj/project.py \
mprj/optdialog.py \
mprj/session.py \ mprj/session.py \
mprj/settings.py \ mprj/settings.py \
mprj/simple.py \ mprj/simple.py \
mprj/simple.glade \
mprj/test.py \ mprj/test.py \
mprj/utils.py \ mprj/utils.py \
mprj/config/_config.py \ mprj/config/_config.py \
@ -37,7 +39,6 @@ nobase_projects_DATA = \
projects/cproj/__init__.py \ projects/cproj/__init__.py \
projects/cproj/optdialog.py \ projects/cproj/optdialog.py \
projects/cproj/parser.py \ projects/cproj/parser.py \
projects/cproj/view.py \
projects/cproj/options.glade \ projects/cproj/options.glade \
projects/latex.py \ projects/latex.py \
projects/ltxproj/config.py \ projects/ltxproj/config.py \
@ -46,7 +47,6 @@ nobase_projects_DATA = \
projects/pyproj/config.py \ projects/pyproj/config.py \
projects/pyproj/__init__.py \ projects/pyproj/__init__.py \
projects/pyproj/optdialog.py \ projects/pyproj/optdialog.py \
projects/pyproj/view.py \
projects/pyproj/options.glade projects/pyproj/options.glade
EXTRA_DIST = \ EXTRA_DIST = \

View File

@ -1,9 +1,20 @@
__all__ = ['Column', 'View', 'CellText', 'CellToggle'] if __name__ == '__main__':
import sys
import os.path
dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dir, '../..'))
__all__ = ['Column', 'View', 'CellText', 'CellToggle',
'DictView', 'GroupView', 'Entry']
""" configview.py: TreeView column and cell renderers for settings """ """ configview.py: TreeView column and cell renderers for settings """
import gtk import gtk
import gobject import gobject
import pango
from moo.utils import _
import mprj.config import mprj.config
@ -97,8 +108,284 @@ class View(gtk.TreeView):
setting = model.get_value(iter, 0) setting = model.get_value(iter, 0)
cell.set_property('text', setting.get_name()) cell.set_property('text', setting.get_name())
class DictView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.dct = None
self.column_name = gtk.TreeViewColumn(_('Name'))
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.cell_name.set_property('editable', True)
self.cell_name.connect('edited', self.name_edited)
self.cell_name.connect('editing-started', self.editing_started, 0)
self.column_value = gtk.TreeViewColumn(_('Value'))
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.set_property('editable', True)
self.cell_value.connect('edited', self.value_edited)
self.cell_value.connect('editing-started', self.editing_started, 1)
def set_dict(self, dct):
self.dct = dct
store = gtk.ListStore(object)
self.set_model(store)
keys = dct.keys()
keys.sort()
for key in keys:
store.append([[key, dct[key]]])
store.append([[None, None]])
def name_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[0] is None:
cell.set_property('text', _('new...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[0])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def editing_started(self, cell, entry, path, ind):
model = self.get_model()
iter = model.get_iter(path)
data = model.get_value(iter, 0)
if data[ind] is None:
entry.set_text('')
def name_edited(self, cell, path, text):
if not text:
return
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
old_key = data[0]
old_val = data[1]
new_key = text
if old_key == new_key:
return
if self.dct.has_key(new_key):
raise KeyError()
if old_val is None:
old_val = ''
self.dct[new_key] = old_val
if old_key is not None:
del self.dct[old_key]
new_data = [new_key, self.dct[new_key]]
model.set_value(iter, 0, new_data)
if old_key is None:
model.append([[None, None]])
def value_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[1] is None:
cell.set_property('text', _('click to edit...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[1])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
if data[1] == text:
return
if data[0] is not None:
self.dct[data[0]] = text
data = [data[0], self.dct[data[0]]]
else:
if not text:
text = None
data = [data[0], text]
model.set_value(iter, 0, data)
def delete_activated(self, item, path):
model = self.get_model()
iter = model.get_iter(path)
if not iter:
return
data = model.get_value(iter, 0)
del self.dct[data[0]]
model.remove(iter)
def do_button_press_event(self, event):
if event.button != 3:
return gtk.TreeView.do_button_press_event(self, event)
pos = self.get_path_at_pos(int(event.x), int(event.y))
if pos is None:
return gtk.TreeView.do_button_press_event(self, event)
model = self.get_model()
if model is None:
return gtk.TreeView.do_button_press_event(self, event)
iter = model.get_iter(pos[0])
data = model.get_value(iter, 0)
if data[0] is None:
return gtk.TreeView.do_button_press_event(self, event)
self.get_selection().select_iter(iter)
menu = gtk.Menu()
item = gtk.MenuItem(_("Delete"), False)
item.show()
item.connect('activate', self.delete_activated, pos[0])
menu.add(item)
menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class GroupView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.items = None
self.column_name = gtk.TreeViewColumn()
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.column_value = gtk.TreeViewColumn()
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.connect('edited', self.value_edited)
self.hidden_column = gtk.TreeViewColumn()
self.hidden_column.set_visible(False)
self.append_column(self.hidden_column)
def set_group(self, group):
self.set_items(group.items())
def set_items(self, items):
need_tree = False
for i in items:
if i.get_visible() and isinstance(i, mprj.config.Group):
need_tree = True
break
self.items = items
store = gtk.TreeStore(object)
self.set_model(store)
if need_tree:
self.set_expander_column(self.column_name)
else:
self.set_expander_column(self.hidden_column)
def append(store, items, parent):
for item in items:
iter = (parent and model.get_iter(parent)) or None
iter = store.append(iter, [item])
if isinstance(item, mprj.config.Group):
new_parent = store.get_path(iter)
append(store, item.items(), new_parent)
append(store, items, None)
def name_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
cell.set_property('text', item.get_name())
def value_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
if isinstance(item, mprj.config.Group):
cell.set_property('text', None)
cell.set_property('editable', False)
else:
cell.set_property('text', item.get_value())
cell.set_property('editable', True)
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
item = model.get_value(iter, 0)
item.set_string(text)
# def delete_activated(self, item, path):
# model = self.get_model()
# iter = model.get_iter(path)
# if not iter:
# return
# data = model.get_value(iter, 0)
# del self.dct[data[0]]
# model.remove(iter)
# def do_button_press_event(self, event):
# if event.button != 3:
# return gtk.TreeView.do_button_press_event(self, event)
# pos = self.get_path_at_pos(int(event.x), int(event.y))
# if pos is None:
# return gtk.TreeView.do_button_press_event(self, event)
# model = self.get_model()
# if model is None:
# return gtk.TreeView.do_button_press_event(self, event)
# iter = model.get_iter(pos[0])
# data = model.get_value(iter, 0)
# if data[0] is None:
# return gtk.TreeView.do_button_press_event(self, event)
# self.get_selection().select_iter(iter)
# menu = gtk.Menu()
# item = gtk.MenuItem(_("Delete"), False)
# item.show()
# item.connect('activate', self.delete_activated, pos[0])
# menu.add(item)
# menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class Entry(gtk.Entry):
def __init__(self):
gtk.Entry.__init__(self)
self.setting = None
def set_setting(self, setting):
self.setting = setting
if setting.get_value() is not None:
self.set_text(setting.get_value())
def apply(self):
if self.setting is not None:
self.setting.set_string(self.get_text())
gobject.type_register(Column) gobject.type_register(Column)
gobject.type_register(View) gobject.type_register(View)
gobject.type_register(DictView)
gobject.type_register(GroupView)
gobject.type_register(Entry)
""" _CellMeta: metaclass for all settings cell renderers """ """ _CellMeta: metaclass for all settings cell renderers """

View File

@ -1,6 +1,15 @@
import moo 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 os.path
import shutil import shutil
import moo
from moo.utils import _ from moo.utils import _
from mprj.project import Project from mprj.project import Project
@ -8,6 +17,7 @@ from mprj.config import Config, Dict
from mprj.settings import Filename from mprj.settings import Filename
from mprj.utils import print_error from mprj.utils import print_error
from mprj.session import Session from mprj.session import Session
import mprj.optdialog
class SimpleConfig(Config): class SimpleConfig(Config):
@ -103,6 +113,24 @@ class SimpleProject(Project):
return None return None
class ConfigPage(mprj.optdialog.ConfigPage):
__label__ = _("General")
__types__ = {}
def __init__(self, config):
mprj.optdialog.ConfigPage.__init__(self, "page", config,
os.path.join(os.path.dirname(__file__), "simple.glade"))
def do_init(self):
mprj.optdialog.ConfigPage.do_init(self)
def do_apply(self):
mprj.optdialog.ConfigPage.do_apply(self)
gobject.type_register(ConfigPage)
if __name__ == '__main__': if __name__ == '__main__':
from mprj.config import File from mprj.config import File

View File

@ -57,7 +57,7 @@ def oops(window, error):
moo.utils.error_dialog(window, "OOPS", format_error(error)) moo.utils.error_dialog(window, "OOPS", format_error(error))
def print_error(error=None): def print_error(error=None):
print format_error(error) print >> sys.stderr, format_error(error)
def format_error(error=None): def format_error(error=None):
if error: if error:

View File

@ -1,3 +1,9 @@
if __name__ == '__main__':
import sys
import os.path
dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dir, '..'))
import gtk import gtk
import moo import moo
import os.path import os.path

View File

@ -2,49 +2,22 @@ if __name__ == '__main__':
import sys import sys
import os.path import os.path
dir = os.path.dirname(__file__) dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dir, '../..'))
sys.path.insert(0, os.path.join(dir, '..')) sys.path.insert(0, os.path.join(dir, '..'))
import gobject import gobject
import gtk
import os.path import os.path
import moo import moo
from moo.utils import _ from moo.utils import _
from cproj.view import * import mprj.optdialog
from mprj.config.view import *
from cproj.config import * from cproj.config import *
dir = os.path.dirname(__file__)
def create_page(cls, page_id, config, types={}, label=None, file='options.glade'): class ConfigsPage(mprj.optdialog.ConfigPage):
file = os.path.join(dir, file)
xml = moo.utils.GladeXML(moo.utils.GETTEXT_PACKAGE)
xml.map_id(page_id, cls)
if not types and hasattr(cls, '__types__'):
types = getattr(cls, '__types__')
for id in types:
xml.map_id(id, types[id])
page = cls()
file = open(file)
try:
xml.fill_widget(page, file.read(), page_id)
assert xml.get_widget(page_id) is page
finally:
file.close()
if not label and hasattr(cls, '__label__'):
label = getattr(cls, '__label__')
if label:
page.set_property('label', label)
page.xml = xml
page.config = config
return page
class ConfigsPage(moo.utils.PrefsDialogPage):
__label__ = _('Configurations') __label__ = _('Configurations')
__types__ = {'build_dir' : Entry, __types__ = {'build_dir' : Entry,
'args' : Entry, 'args' : Entry,
@ -83,26 +56,22 @@ class ConfigsPage(moo.utils.PrefsDialogPage):
combo.connect('changed', self.combo_changed) combo.connect('changed', self.combo_changed)
def do_init(self): def do_init(self):
self.widgets = [self.xml.w_build_dir, self.xml.w_args] mprj.optdialog.ConfigPage.do_init(self)
self.init_combo() self.init_combo()
self.combo_changed() self.combo_changed()
def do_apply(self):
for widget in self.widgets:
widget.apply()
class RunOptionsPage(mprj.optdialog.ConfigPage):
class RunOptionsPage(moo.utils.PrefsDialogPage):
__label__ = _('Run options') __label__ = _('Run options')
__types__ = {'vars' : DictView, __types__ = {'vars' : DictView,
'exe' : Entry, 'exe' : Entry,
'args' : Entry} 'args' : Entry}
def do_init(self): def do_init(self):
mprj.optdialog.ConfigPage.do_init(self)
self.xml.w_vars.set_dict(self.config.run.vars) self.xml.w_vars.set_dict(self.config.run.vars)
self.xml.w_exe.set_setting(self.config.run['exe']) self.xml.w_exe.set_setting(self.config.run['exe'])
self.xml.w_args.set_setting(self.config.run['args']) self.xml.w_args.set_setting(self.config.run['args'])
self.widgets = [self.xml.get_widget(name) for name in ['vars', 'exe', 'args']]
run_from = self.config.run.run_from run_from = self.config.run.run_from
if run_from == RUN_FROM_BUILD_DIR: if run_from == RUN_FROM_BUILD_DIR:
@ -116,8 +85,7 @@ class RunOptionsPage(moo.utils.PrefsDialogPage):
self.xml.w_custom_dir_entry) self.xml.w_custom_dir_entry)
def do_apply(self): def do_apply(self):
for widget in self.widgets: mprj.optdialog.ConfigPage.do_apply(self)
widget.apply()
if self.xml.w_build_dir.get_active(): if self.xml.w_build_dir.get_active():
self.config.run.run_from = RUN_FROM_BUILD_DIR self.config.run.run_from = RUN_FROM_BUILD_DIR
@ -127,35 +95,23 @@ class RunOptionsPage(moo.utils.PrefsDialogPage):
self.config.run.run_from = self.xml.w_custom_dir_entry.get_text() self.config.run.run_from = self.xml.w_custom_dir_entry.get_text()
class BuildCommandsPage(moo.utils.PrefsDialogPage): class BuildCommandsPage(mprj.optdialog.ConfigPage):
__label__ = _('Build commands') __label__ = _('Build commands')
__types__ = {'commands' : GroupView} __types__ = {'commands' : GroupView}
def do_init(self): def do_init(self):
mprj.optdialog.ConfigPage.do_init(self)
self.xml.w_commands.set_items(self.config.commands.items()) self.xml.w_commands.set_items(self.config.commands.items())
self.widgets = [self.xml.get_widget(name) for name in ['commands']]
def do_apply(self):
for widget in self.widgets:
widget.apply()
class Dialog(moo.utils.PrefsDialog): class Dialog(mprj.optdialog.Dialog):
def __init__(self, project, title=_('Project Options')): def __init__(self, project):
moo.utils.PrefsDialog.__init__(self, title) mprj.optdialog.Dialog.__init__(self, project)
self.project = project glade_file = os.path.join(os.path.dirname(__file__), 'options.glade')
self.config_copy = project.config.copy() # self.append_page(mprj.simple.ConfigPage(self.config_copy))
self.append_page(create_page(ConfigsPage, 'page_configs', self.config_copy)) self.append_page(ConfigsPage('page_configs', self.config_copy, glade_file))
self.append_page(create_page(RunOptionsPage, 'page_run', self.config_copy)) self.append_page(RunOptionsPage('page_run', self.config_copy, glade_file))
self.append_page(create_page(BuildCommandsPage, 'page_commands', self.config_copy)) self.append_page(BuildCommandsPage('page_commands', self.config_copy, glade_file))
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(ConfigsPage) gobject.type_register(ConfigsPage)
@ -171,8 +127,9 @@ if __name__ == '__main__':
from c import CProject from c import CProject
editor = moo.edit.create_editor_instance() editor = moo.edit.create_editor_instance()
config = CConfig(File(_sample_file, '/tmp/fake/file')) config_file = File(_sample_file, '/tmp/fake/file')
project = CProject(None, config) config = CConfig(config_file)
project = CProject(None, config, config_file)
dialog = Dialog(project) dialog = Dialog(project)
dialog.connect('destroy', gtk.main_quit) dialog.connect('destroy', gtk.main_quit)
dialog.run() dialog.run()

View File

@ -1,307 +0,0 @@
import gobject
import gtk
import pango
import moo
from moo.utils import _
import mprj.config
class DictView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.dct = None
self.column_name = gtk.TreeViewColumn(_('Name'))
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.cell_name.set_property('editable', True)
self.cell_name.connect('edited', self.name_edited)
self.cell_name.connect('editing-started', self.editing_started, 0)
self.column_value = gtk.TreeViewColumn(_('Value'))
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.set_property('editable', True)
self.cell_value.connect('edited', self.value_edited)
self.cell_value.connect('editing-started', self.editing_started, 1)
def set_dict(self, dct):
self.dct = dct
store = gtk.ListStore(object)
self.set_model(store)
keys = dct.keys()
keys.sort()
for key in keys:
store.append([[key, dct[key]]])
store.append([[None, None]])
def name_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[0] is None:
cell.set_property('text', _('new...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[0])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def editing_started(self, cell, entry, path, ind):
model = self.get_model()
iter = model.get_iter(path)
data = model.get_value(iter, 0)
if data[ind] is None:
entry.set_text('')
def name_edited(self, cell, path, text):
if not text:
return
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
old_key = data[0]
old_val = data[1]
new_key = text
if old_key == new_key:
return
if self.dct.has_key(new_key):
raise KeyError()
if old_val is None:
old_val = ''
self.dct[new_key] = old_val
if old_key is not None:
del self.dct[old_key]
new_data = [new_key, self.dct[new_key]]
model.set_value(iter, 0, new_data)
if old_key is None:
model.append([[None, None]])
def value_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[1] is None:
cell.set_property('text', _('click to edit...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[1])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
if data[1] == text:
return
if data[0] is not None:
self.dct[data[0]] = text
data = [data[0], self.dct[data[0]]]
else:
if not text:
text = None
data = [data[0], text]
model.set_value(iter, 0, data)
def delete_activated(self, item, path):
model = self.get_model()
iter = model.get_iter(path)
if not iter:
return
data = model.get_value(iter, 0)
del self.dct[data[0]]
model.remove(iter)
def do_button_press_event(self, event):
if event.button != 3:
return gtk.TreeView.do_button_press_event(self, event)
pos = self.get_path_at_pos(int(event.x), int(event.y))
if pos is None:
return gtk.TreeView.do_button_press_event(self, event)
model = self.get_model()
if model is None:
return gtk.TreeView.do_button_press_event(self, event)
iter = model.get_iter(pos[0])
data = model.get_value(iter, 0)
if data[0] is None:
return gtk.TreeView.do_button_press_event(self, event)
self.get_selection().select_iter(iter)
menu = gtk.Menu()
item = gtk.MenuItem(_("Delete"), False)
item.show()
item.connect('activate', self.delete_activated, pos[0])
menu.add(item)
menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class GroupView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.items = None
self.column_name = gtk.TreeViewColumn()
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.column_value = gtk.TreeViewColumn()
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.connect('edited', self.value_edited)
self.hidden_column = gtk.TreeViewColumn()
self.hidden_column.set_visible(False)
self.append_column(self.hidden_column)
def set_group(self, group):
self.set_items(group.items())
def set_items(self, items):
need_tree = False
for i in items:
if i.get_visible() and isinstance(i, mprj.config.Group):
need_tree = True
break
self.items = items
store = gtk.TreeStore(object)
self.set_model(store)
if need_tree:
self.set_expander_column(self.column_name)
else:
self.set_expander_column(self.hidden_column)
def append(store, items, parent):
for item in items:
iter = (parent and model.get_iter(parent)) or None
iter = store.append(iter, [item])
if isinstance(item, mprj.config.Group):
new_parent = store.get_path(iter)
append(store, item.items(), new_parent)
append(store, items, None)
def name_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
cell.set_property('text', item.get_name())
def value_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
if isinstance(item, mprj.config.Group):
cell.set_property('text', None)
cell.set_property('editable', False)
else:
cell.set_property('text', item.get_value())
cell.set_property('editable', True)
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
item = model.get_value(iter, 0)
item.set_string(text)
# def delete_activated(self, item, path):
# model = self.get_model()
# iter = model.get_iter(path)
# if not iter:
# return
# data = model.get_value(iter, 0)
# del self.dct[data[0]]
# model.remove(iter)
# def do_button_press_event(self, event):
# if event.button != 3:
# return gtk.TreeView.do_button_press_event(self, event)
# pos = self.get_path_at_pos(int(event.x), int(event.y))
# if pos is None:
# return gtk.TreeView.do_button_press_event(self, event)
# model = self.get_model()
# if model is None:
# return gtk.TreeView.do_button_press_event(self, event)
# iter = model.get_iter(pos[0])
# data = model.get_value(iter, 0)
# if data[0] is None:
# return gtk.TreeView.do_button_press_event(self, event)
# self.get_selection().select_iter(iter)
# menu = gtk.Menu()
# item = gtk.MenuItem(_("Delete"), False)
# item.show()
# item.connect('activate', self.delete_activated, pos[0])
# menu.add(item)
# menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class Entry(gtk.Entry):
def __init__(self):
gtk.Entry.__init__(self)
self.setting = None
def set_setting(self, setting):
self.setting = setting
if setting.get_value() is not None:
self.set_text(setting.get_value())
def apply(self):
if self.setting is not None:
self.setting.set_string(self.get_text())
# class BrowseButton(gtk.Button):
# def connect(self, entry, topdir):
# self.entry = entry
#
# def do_clicked(self):
# start_dir=self.entry.get_text()
# if not start_dir:
# start_dir = None
# if start_dir and not os.path.isabs(start_dir):
# start_dir = os.path.join()
#
# path = moo.utils.file_dialog(moo.utils.FILE_DIALOG_OPEN_DIR,
# parent=self,
# start_dir=self.entry.get_text())
# if path:
# self.entry.set_text(path)
gobject.type_register(GroupView)
gobject.type_register(DictView)
gobject.type_register(Entry)
# gobject.type_register(BrowseButton)
if __name__ == '__main__':
DictView()

View File

@ -2,6 +2,8 @@ if __name__ == '__main__':
import sys import sys
import os.path import os.path
dir = os.path.dirname(__file__) dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(dir, '../../..'))
sys.path.insert(0, os.path.join(dir, '../..'))
sys.path.insert(0, os.path.join(dir, '..')) sys.path.insert(0, os.path.join(dir, '..'))
import gobject import gobject
@ -9,42 +11,11 @@ import os.path
import moo import moo
from moo.utils import _ from moo.utils import _
from pyproj.view import * import mprj.optdialog
from mprj.config.view import *
from pyproj.config import * from pyproj.config import *
dir = os.path.dirname(__file__) class RunOptionsPage(mprj.optdialog.ConfigPage):
def create_page(cls, page_id, config, types={}, label=None, file='options.glade'):
file = os.path.join(dir, file)
xml = moo.utils.GladeXML(moo.utils.GETTEXT_PACKAGE)
xml.map_id(page_id, cls)
if not types and hasattr(cls, '__types__'):
types = getattr(cls, '__types__')
for id in types:
xml.map_id(id, types[id])
page = cls()
file = open(file)
try:
xml.fill_widget(page, file.read(), page_id)
assert xml.get_widget(page_id) is page
finally:
file.close()
if not label and hasattr(cls, '__label__'):
label = getattr(cls, '__label__')
if label:
page.set_property('label', label)
page.xml = xml
page.config = config
return page
class RunOptionsPage(moo.utils.PrefsDialogPage):
__label__ = _('Run options') __label__ = _('Run options')
__types__ = {'vars' : DictView, __types__ = {'vars' : DictView,
'exe' : Entry, 'exe' : Entry,
@ -54,19 +25,15 @@ class RunOptionsPage(moo.utils.PrefsDialogPage):
self.xml.w_vars.set_dict(self.config.run.vars) self.xml.w_vars.set_dict(self.config.run.vars)
self.xml.w_exe.set_setting(self.config.run['exe']) self.xml.w_exe.set_setting(self.config.run['exe'])
self.xml.w_args.set_setting(self.config.run['args']) self.xml.w_args.set_setting(self.config.run['args'])
self.widgets = [self.xml.get_widget(name) for name in ['vars', 'exe', 'args']]
def do_apply(self):
for widget in self.widgets:
widget.apply()
class Dialog(moo.utils.PrefsDialog): class Dialog(moo.utils.PrefsDialog):
def __init__(self, project, title=_('Project Options')): def __init__(self, project, title=_('Project Options')):
moo.utils.PrefsDialog.__init__(self, title) moo.utils.PrefsDialog.__init__(self, title)
self.project = project self.project = project
self.config_copy = project.config.copy() self.config_copy = project.config.copy()
self.append_page(create_page(RunOptionsPage, 'page_run', self.config_copy)) # self.append_page(mprj.simple.ConfigPage(self.config_copy))
glade_file = os.path.join(os.path.dirname(__file__), 'options.glade')
self.append_page(RunOptionsPage('page_run', self.config_copy, glade_file))
def do_apply(self): def do_apply(self):
moo.utils.PrefsDialog.do_apply(self) moo.utils.PrefsDialog.do_apply(self)
@ -76,11 +43,9 @@ class Dialog(moo.utils.PrefsDialog):
print self.project.config.dump_xml() print self.project.config.dump_xml()
print '=============================' print '============================='
gobject.type_register(RunOptionsPage) gobject.type_register(RunOptionsPage)
gobject.type_register(Dialog) gobject.type_register(Dialog)
if __name__ == '__main__': if __name__ == '__main__':
import gtk import gtk
from pyproj.config import PyConfig, _sample_file from pyproj.config import PyConfig, _sample_file

View File

@ -1,307 +0,0 @@
import gobject
import gtk
import pango
import moo
from moo.utils import _
import mprj.config
class DictView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.dct = None
self.column_name = gtk.TreeViewColumn(_('Name'))
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.cell_name.set_property('editable', True)
self.cell_name.connect('edited', self.name_edited)
self.cell_name.connect('editing-started', self.editing_started, 0)
self.column_value = gtk.TreeViewColumn(_('Value'))
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.set_property('editable', True)
self.cell_value.connect('edited', self.value_edited)
self.cell_value.connect('editing-started', self.editing_started, 1)
def set_dict(self, dct):
self.dct = dct
store = gtk.ListStore(object)
self.set_model(store)
keys = dct.keys()
keys.sort()
for key in keys:
store.append([[key, dct[key]]])
store.append([[None, None]])
def name_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[0] is None:
cell.set_property('text', _('new...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[0])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def editing_started(self, cell, entry, path, ind):
model = self.get_model()
iter = model.get_iter(path)
data = model.get_value(iter, 0)
if data[ind] is None:
entry.set_text('')
def name_edited(self, cell, path, text):
if not text:
return
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
old_key = data[0]
old_val = data[1]
new_key = text
if old_key == new_key:
return
if self.dct.has_key(new_key):
raise KeyError()
if old_val is None:
old_val = ''
self.dct[new_key] = old_val
if old_key is not None:
del self.dct[old_key]
new_data = [new_key, self.dct[new_key]]
model.set_value(iter, 0, new_data)
if old_key is None:
model.append([[None, None]])
def value_data_func(self, column, cell, model, iter):
data = model.get_value(iter, 0)
if data[1] is None:
cell.set_property('text', _('click to edit...'))
cell.set_property('style', pango.STYLE_ITALIC)
# cell.set_property('foreground', 'grey')
else:
cell.set_property('text', data[1])
cell.set_property('style', pango.STYLE_NORMAL)
# cell.set_property('foreground', 'black')
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
data = model.get_value(iter, 0)
if data[1] == text:
return
if data[0] is not None:
self.dct[data[0]] = text
data = [data[0], self.dct[data[0]]]
else:
if not text:
text = None
data = [data[0], text]
model.set_value(iter, 0, data)
def delete_activated(self, item, path):
model = self.get_model()
iter = model.get_iter(path)
if not iter:
return
data = model.get_value(iter, 0)
del self.dct[data[0]]
model.remove(iter)
def do_button_press_event(self, event):
if event.button != 3:
return gtk.TreeView.do_button_press_event(self, event)
pos = self.get_path_at_pos(int(event.x), int(event.y))
if pos is None:
return gtk.TreeView.do_button_press_event(self, event)
model = self.get_model()
if model is None:
return gtk.TreeView.do_button_press_event(self, event)
iter = model.get_iter(pos[0])
data = model.get_value(iter, 0)
if data[0] is None:
return gtk.TreeView.do_button_press_event(self, event)
self.get_selection().select_iter(iter)
menu = gtk.Menu()
item = gtk.MenuItem(_("Delete"), False)
item.show()
item.connect('activate', self.delete_activated, pos[0])
menu.add(item)
menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class GroupView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
self.items = None
self.column_name = gtk.TreeViewColumn()
self.column_name.set_resizable(True)
self.cell_name = gtk.CellRendererText()
self.column_name.pack_start(self.cell_name, False)
self.append_column(self.column_name)
self.column_name.set_cell_data_func(self.cell_name, self.name_data_func)
self.column_value = gtk.TreeViewColumn()
self.column_value.set_resizable(True)
self.cell_value = gtk.CellRendererText()
self.column_value.pack_start(self.cell_value, False)
self.append_column(self.column_value)
self.column_value.set_cell_data_func(self.cell_value, self.value_data_func)
self.cell_value.connect('edited', self.value_edited)
self.hidden_column = gtk.TreeViewColumn()
self.hidden_column.set_visible(False)
self.append_column(self.hidden_column)
def set_group(self, group):
self.set_items(group.items())
def set_items(self, items):
need_tree = False
for i in items:
if i.get_visible() and isinstance(i, mprj.config.Group):
need_tree = True
break
self.items = items
store = gtk.TreeStore(object)
self.set_model(store)
if need_tree:
self.set_expander_column(self.column_name)
else:
self.set_expander_column(self.hidden_column)
def append(store, items, parent):
for item in items:
iter = (parent and model.get_iter(parent)) or None
iter = store.append(iter, [item])
if isinstance(item, mprj.config.Group):
new_parent = store.get_path(iter)
append(store, item.items(), new_parent)
append(store, items, None)
def name_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
cell.set_property('text', item.get_name())
def value_data_func(self, column, cell, model, iter):
item = model.get_value(iter, 0)
if isinstance(item, mprj.config.Group):
cell.set_property('text', None)
cell.set_property('editable', False)
else:
cell.set_property('text', item.get_value())
cell.set_property('editable', True)
def value_edited(self, cell, path, text):
model = self.get_model()
iter = model.get_iter(path)
if iter is None:
return
item = model.get_value(iter, 0)
item.set_string(text)
# def delete_activated(self, item, path):
# model = self.get_model()
# iter = model.get_iter(path)
# if not iter:
# return
# data = model.get_value(iter, 0)
# del self.dct[data[0]]
# model.remove(iter)
# def do_button_press_event(self, event):
# if event.button != 3:
# return gtk.TreeView.do_button_press_event(self, event)
# pos = self.get_path_at_pos(int(event.x), int(event.y))
# if pos is None:
# return gtk.TreeView.do_button_press_event(self, event)
# model = self.get_model()
# if model is None:
# return gtk.TreeView.do_button_press_event(self, event)
# iter = model.get_iter(pos[0])
# data = model.get_value(iter, 0)
# if data[0] is None:
# return gtk.TreeView.do_button_press_event(self, event)
# self.get_selection().select_iter(iter)
# menu = gtk.Menu()
# item = gtk.MenuItem(_("Delete"), False)
# item.show()
# item.connect('activate', self.delete_activated, pos[0])
# menu.add(item)
# menu.popup(None, None, None, event.button, event.time)
def apply(self):
pass
class Entry(gtk.Entry):
def __init__(self):
gtk.Entry.__init__(self)
self.setting = None
def set_setting(self, setting):
self.setting = setting
if setting.get_value() is not None:
self.set_text(setting.get_value())
def apply(self):
if self.setting is not None:
self.setting.set_string(self.get_text())
# class BrowseButton(gtk.Button):
# def connect(self, entry, topdir):
# self.entry = entry
#
# def do_clicked(self):
# start_dir=self.entry.get_text()
# if not start_dir:
# start_dir = None
# if start_dir and not os.path.isabs(start_dir):
# start_dir = os.path.join()
#
# path = moo.utils.file_dialog(moo.utils.FILE_DIALOG_OPEN_DIR,
# parent=self,
# start_dir=self.entry.get_text())
# if path:
# self.entry.set_text(path)
gobject.type_register(GroupView)
gobject.type_register(DictView)
gobject.type_register(Entry)
# gobject.type_register(BrowseButton)
if __name__ == '__main__':
DictView()

View File

@ -1,3 +1,10 @@
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 gtk import gtk
import os.path import os.path
import gobject import gobject