#!/usr/bin/python
import sys
import functions
try:
import pygtk
pygtk.require("2.0")
import gobject
except:
print("pygtk Not Availible")
sys.exit(1)
try:
import gtk
except:
print("GTK Not Availible")
sys.exit(1)
class EditAllocation(object):
def delete_event(self, widget, event):
self.window.destroy()
def __init__(self, parent, allocation_ui, save_path):
self.parent = parent
self._ = parent._
self.allocation_ui = allocation_ui
self.save_path = save_path
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title(self._("allocation_edit_win_title"))
self.window.connect("delete_event", self.delete_event)
self.window.set_border_width(10)
self.window.set_transient_for(parent.window)
self.window.set_modal(True)
self.window.set_size_request(250, 250)
end_vb = gtk.VBox(False, spacing=10)
vb = gtk.VBox(False, spacing=10)
hb = gtk.HBox(False, spacing=5)
end_vb.pack_start(hb, False, False)
for row, case in enumerate(parent.allocations):
if case['UI'] == allocation_ui:
allocation_row = row
break
else:
self.window.destroy()
return
self.allocation_row = allocation_row
UI_len = len(str(parent.trial_sample_size_spin.get_value_as_int()-1))
lbl = gtk.Label('UI: {0}'.format(str(allocation_ui).zfill(UI_len)))
hb.pack_start(lbl, False, False)
hb = gtk.HBox(False, spacing=5)
end_vb.pack_start(hb, False, False)
lbl = gtk.Label('Group')
hb.pack_start(lbl, False, False)
group_cbo = gtk.combo_box_new_text()
for group in parent.group_liststore:
group_cbo.append_text(group[0])
group = parent.allocations[allocation_row]['allocation']
group_cbo.set_active(group)
hb.pack_start(group_cbo, False, False)
self.group_cbo = group_cbo
self.variable_combos = []
for i, variable in enumerate(parent.variable_liststore):
hb = gtk.HBox(True, spacing=5)
vb.pack_start(hb, True, False)
lbl = gtk.Label(variable[0])
hb.pack_start(lbl, True, True)
cbo = gtk.combo_box_new_text()
for level in map(str.strip, variable[2].split(',')):
cbo.append_text(level)
self.variable_combos.append(cbo)
hb.pack_start(cbo, False, False)
cbo.set_active(parent.allocations[allocation_row]['levels'][i])
functions.make_scrolling(vb, end_vb)
sep = gtk.HSeparator()
end_vb.pack_start(sep, False, False)
hbuttonbox = gtk.HButtonBox()
hbuttonbox.set_layout(gtk.BUTTONBOX_START)
end_vb.pack_start(hbuttonbox, False, False)
button =gtk.Button(None, gtk.STOCK_SAVE)
button.connect('clicked', self.save_allocation_event)
hbuttonbox.pack_start(button, False, False)
button =gtk.Button(None, gtk.STOCK_CANCEL)
button.connect('clicked', self.cancel_allocation_event)
hbuttonbox.pack_start(button, False, False)
self.window.add(end_vb)
self.window.show_all()
def save_allocation_event(self, button, data=None):
msg = self._('editallocation_warning')
dialog = gtk.MessageDialog(self.window, flags = gtk.DIALOG_MODAL, type = gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_YES_NO, message_format = msg)
dialog.set_title(self._("save_warning"))
if dialog.run() == gtk.RESPONSE_NO:
dialog.destroy()
self.window.destroy()
return False
dialog.destroy()
self.parent.allocations[self.allocation_row]['allocation'] = self.group_cbo.get_active()
for i, variable in enumerate(self.parent.variable_liststore):
cbo = self.variable_combos[i]
self.parent.allocations[self.allocation_row]['levels'][i] = cbo.get_active()
self.parent.refresh_allocations_treeview()
self.parent.save_trial(self.save_path)
self.window.destroy()
def cancel_allocation_event(self, button, data=None):
self.window.destroy()