[go: up one dir, main page]

Menu

[r81]: / editallocation.py  Maximize  Restore  History

Download this file

185 lines (170 with data), 7.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/python
import sys
import time
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(450, 350)
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)
hb = gtk.HBox(False)
self.case_properties_liststore, self.case_properties_treeview = functions.make_treeview(
(str, str), [self._('name'), self._('value')],
editable=True, edit_handler=self.case_properties_cell_edited)
functions.make_scrolling(self.case_properties_treeview, hb)
if parent.allocations[allocation_row].has_key('properties'):
self.set_case_properties(parent.allocations[allocation_row]['properties'])
vbuttonbox = gtk.VButtonBox()
vbuttonbox.set_layout(gtk.BUTTONBOX_START)
button = gtk.Button(None, gtk.STOCK_ADD)
button.connect("clicked", self.case_properties_add_button)
vbuttonbox.pack_start(button, False, False)
button = gtk.Button(None, gtk.STOCK_DELETE)
button.connect("clicked", self.case_properties_delete_button)
vbuttonbox.pack_start(button, False, False)
button = gtk.Button(None, gtk.STOCK_DATE)
button.connect("clicked", self.case_properties_date_button)
vbuttonbox.pack_start(button, False, False)
hb.pack_start(vbuttonbox, False, False)
lbl = gtk.Label(self._('case_extra_properties'))
end_vb.pack_start(lbl, False, False)
end_vb.pack_start(hb, False, False)
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 case_properties_cell_edited(self, cell, row, new_text, col):
# event function for cell edit event
self.case_properties_liststore[row][col] = new_text
def case_properties_add_button(self, widget, data=None):
# event function for add trial property event
self.case_properties_liststore.append((self._('property_name'), self._('property_value')))
def case_properties_delete_button(self, widget, data=None):
# event function for delete property event
if self.case_properties_treeview.get_cursor()[0]:
row = self.case_properties_treeview.get_cursor()[0][0]
self.case_properties_liststore.remove(self.case_properties_liststore.get_iter(row))
def case_properties_date_button(self, widget, data=None):
# event function for add trial property event
self.case_properties_liststore.append((self._('enrolled_on'), time.ctime()))
def get_case_properties(self):
# getting case properties
table = [['', ''] for row in range(len(self.case_properties_liststore))]
for row in range(len(table)):
for col in range(len(table[0])):
table[row][col] = self.case_properties_liststore[row][col]
return table
def set_case_properties(self, table):
# setting the case propeties liststore from the supplied table
self.case_properties_liststore.clear()
for row in range(len(table)):
self.case_properties_liststore.append(table[row])
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()
for row, case in enumerate(self.parent.allocations):
if case['UI'] == self.allocation_ui:
allocation_row = row
break
else:
self.window.destroy()
return
self.allocation_row = allocation_row
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()
functions.treeview_scroll_select_row(
self.parent.window, self.parent.allocations_treeview, self.allocation_row)
self.parent.window.set_focus(self.parent.allocations_treeview)
for row, case in enumerate(self.parent.allocations):
if case['UI'] == self.allocation_ui:
allocation_row = row
break
else:
self.window.destroy()
return
self.allocation_row = allocation_row
case_properties = self.get_case_properties()
self.parent.allocations[self.allocation_row]['properties'] = case_properties
self.parent.save_trial(self.save_path)
self.window.destroy()
def cancel_allocation_event(self, button, data=None):
self.window.destroy()