2006-04-23 00:29:02 +02:00
|
|
|
import pygtk
|
2006-05-09 15:17:17 +02:00
|
|
|
# pygtk.require('2.0')
|
2006-04-23 00:29:02 +02:00
|
|
|
import gtk
|
|
|
|
import sys
|
|
|
|
import os
|
2006-04-25 11:53:35 +02:00
|
|
|
import gobject
|
|
|
|
from system import logger, project, workflow
|
|
|
|
import workflows
|
2006-04-23 00:29:02 +02:00
|
|
|
|
2006-04-27 13:20:12 +02:00
|
|
|
DATADIR = os.path.dirname(sys.modules['system'].__file__)
|
2006-05-29 13:24:33 +02:00
|
|
|
GLADEFILENAME = os.path.join(DATADIR, 'fluents.glade')
|
2006-04-23 00:29:02 +02:00
|
|
|
|
|
|
|
class CreateProjectDruid(gtk.Window):
|
|
|
|
"""A druid for creating a new project.
|
|
|
|
|
|
|
|
The CreateProjectDruid gets a list of all classes derived from
|
|
|
|
Workflow, and asks the user to select one of these. A new project of
|
|
|
|
the selected class is added to the application."""
|
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
gtk.Window.__init__(self)
|
|
|
|
self.app = app
|
|
|
|
self.widget_tree = gtk.glade.XML(GLADEFILENAME, 'new_project_druid')
|
|
|
|
self.workflows = self.make_workflow_list()
|
|
|
|
self.selected = None
|
|
|
|
|
|
|
|
renderer = gtk.CellRendererText()
|
|
|
|
wf_name = gtk.TreeViewColumn('Workflow Name', renderer, text=0)
|
|
|
|
self['workflow_list'].insert_column(wf_name, 0)
|
|
|
|
|
|
|
|
self.wf_info = gtk.TextBuffer()
|
|
|
|
self['workflow_info'].set_buffer(self.wf_info)
|
|
|
|
|
2006-04-24 23:52:18 +02:00
|
|
|
def __getitem__(self, key):
|
|
|
|
return self.widget_tree.get_widget(key)
|
2006-04-23 00:29:02 +02:00
|
|
|
|
|
|
|
def make_workflow_list(self):
|
|
|
|
store = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
|
2006-04-24 23:52:18 +02:00
|
|
|
for wf in workflow.workflow_list():
|
|
|
|
store.insert_after(None, (wf.name, wf))
|
2006-04-23 00:29:02 +02:00
|
|
|
return store
|
2006-04-24 23:52:18 +02:00
|
|
|
|
2006-04-23 00:29:02 +02:00
|
|
|
def run(self):
|
|
|
|
self['workflow_list'].set_model(self.workflows)
|
|
|
|
|
|
|
|
self['druidpagestart1'].show()
|
|
|
|
self['druidpagefinish1'].show()
|
|
|
|
self['new_project_druid'].show()
|
|
|
|
|
|
|
|
self['druidpagefinish1'].connect('finish', self.finish)
|
|
|
|
self['workflow_list'].connect('cursor_changed', self.selection_updated)
|
2006-04-26 16:01:46 +02:00
|
|
|
self['druid'].connect('cancel', self.cancel)
|
2006-04-23 00:29:02 +02:00
|
|
|
self.connect('destroy', self.delete)
|
|
|
|
|
|
|
|
def delete(self, widget):
|
|
|
|
return False
|
|
|
|
|
|
|
|
def hide(self):
|
|
|
|
self['druidpagestart1'].hide()
|
|
|
|
self['druidpagefinish1'].hide()
|
|
|
|
self['new_project_druid'].hide()
|
|
|
|
gtk.Window.hide(self)
|
|
|
|
|
|
|
|
def finish(self, *rest):
|
|
|
|
tree, it = self['workflow_list'].get_selection().get_selected()
|
|
|
|
wf = self.workflows.get_value(it, 1)
|
|
|
|
proj = project.Project()
|
|
|
|
self.app.set_workflow(wf(self.app))
|
|
|
|
self.app.set_project(proj)
|
|
|
|
self.hide()
|
|
|
|
self.destroy()
|
|
|
|
|
2006-04-26 16:01:46 +02:00
|
|
|
def cancel(self, *ignored):
|
|
|
|
self.hide()
|
|
|
|
self.destroy()
|
|
|
|
|
2006-04-23 00:29:02 +02:00
|
|
|
def selection_updated(self, *rest):
|
|
|
|
tree, it = self['workflow_list'].get_selection().get_selected()
|
|
|
|
wf = self.workflows.get_value(it, 1)
|
|
|
|
self.wf_info.set_text(wf.description)
|
|
|
|
|
2006-05-05 16:30:23 +02:00
|
|
|
|
|
|
|
def get_text(title, text):
|
|
|
|
"""Allow user to type in a string for text."""
|
|
|
|
dlg = gtk.Dialog(title)
|
|
|
|
dlg.show()
|
|
|
|
|
|
|
|
text = gtk.Label(text)
|
|
|
|
text.show()
|
|
|
|
|
|
|
|
entry = gtk.Entry()
|
|
|
|
entry.show()
|
|
|
|
entry.set_activates_default(True)
|
|
|
|
dlg.vbox.pack_start(text)
|
|
|
|
dlg.vbox.pack_start(entry)
|
|
|
|
|
|
|
|
dlg.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
|
|
|
|
dlg.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
|
|
|
|
dlg.set_default_response(gtk.RESPONSE_OK)
|
|
|
|
response = dlg.run()
|
|
|
|
|
|
|
|
retval = None
|
|
|
|
|
|
|
|
if response == gtk.RESPONSE_OK:
|
|
|
|
retval = entry.get_text()
|
|
|
|
dlg.destroy()
|
|
|
|
return retval
|
|
|
|
|