[go: up one dir, main page]

Menu

[r36]: / minimpypreferences.py  Maximize  Restore  History

Download this file

236 lines (209 with data), 10.7 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env python
import sys
import os
import functions
try:
import pygtk
pygtk.require("2.0")
except:
print("pygtk Not Availible")
sys.exit(1)
try:
import gtk
import gobject
except:
print("GTK Not Availible")
sys.exit(1)
class PrefWin(object):
def delete_event(self, widget, event):
self.window.destroy()
def __init__(self, parent):
self.parent = parent
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("MinimPy Program Preferences")
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)
table = gtk.Table(11, 2,)
self.set_tab_pos_cbo = gtk.combo_box_new_text()
self.set_tab_pos_cbo.append_text("Left")
self.set_tab_pos_cbo.append_text("Right")
self.set_tab_pos_cbo.append_text("Top")
self.set_tab_pos_cbo.append_text("Bottom")
self.set_tab_pos_cbo.set_active(parent.notebook.get_tab_pos())
label = gtk.Label("Program Tab Positions")
table.attach(label, 0, 1, 0, 1)
table.attach(self.set_tab_pos_cbo, 1, 2, 0, 1)
sep = gtk.HSeparator()
table.attach(sep, 0, 2, 1, 2)
self.load_recent_chk = gtk.CheckButton("Load Last Project on Startup")
self.load_recent_chk.set_active(self.parent.config.getboolean('project', 'load_recent'))
table.attach(self.load_recent_chk, 0, 2, 2, 3)
self.batch_allocation_chk = gtk.CheckButton("Batch Allocation (simulated allocations, only for research purposes)")
self.batch_allocation_chk.set_active(self.parent.config.getboolean('interface', 'batch_allocation'))
table.attach(self.batch_allocation_chk, 0, 2, 4, 5)
self.alt_random_chk = gtk.CheckButton("Use Operating System's Random Number Generator (Windows and Linux)")
self.alt_random_chk.set_active(self.parent.config.getboolean('operations', 'alt_random'))
table.attach(self.alt_random_chk, 0, 2, 5, 6)
self.backup_network_file_chk = gtk.CheckButton("Back up Network Sync File to this Folder -->")
self.backup_network_file_chk.set_active(self.parent.config.getboolean('operations', 'backup_network'))
table.attach(self.backup_network_file_chk, 0, 1, 6, 7)
self.backup_network_file_path_button = gtk.FileChooserButton("Select Backup Path")
self.backup_network_file_path_button.set_title('Select Path for Network Sync Backup')
self.backup_network_file_path_button.set_action(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
self.backup_network_file_path_button.set_current_folder(self.parent.config.get('operations', 'backup_network_path'))
table.attach(self.backup_network_file_path_button, 1, 2, 6, 7)
self.cach_cred_chk = gtk.CheckButton("Store username and password for network sync")
self.cach_cred_chk.set_active(self.parent.config.getboolean('operations', 'cach_cred'))
table.attach(self.cach_cred_chk, 0, 1, 7, 8)
hb = gtk.HBox()
button = gtk.Button('Show Cached Data')
button.connect('clicked', self.clear_cach_button)
hb.pack_start(button, False, False)
table.attach(hb, 1, 2, 7, 8)
sep = gtk.HSeparator()
table.attach(sep, 0, 2, 8, 9)
self.cached_cred_vbox = gtk.VBox()
table.attach(self.cached_cred_vbox, 0, 2, 9, 10)
sep = gtk.HSeparator()
table.attach(sep, 0, 2, 10, 11)
btn = gtk.Button(None, gtk.STOCK_SAVE)
btn.connect("clicked", self.save_prefs)
table.attach(btn, 0, 1, 11, 12, xoptions=gtk.EXPAND)
btn = gtk.Button(None, gtk.STOCK_CLOSE)
btn.connect("clicked", self.close_window)
table.attach(btn, 1, 2, 11, 12, xoptions=gtk.EXPAND)
self.window.add(table)
self.window.show_all()
self.cached_cred_vbox.hide()
def clear_cach_button(self, button, data=None):
if button.get_label() == 'Show Cached Data':
button.set_label('Hide Cached Data')
else:
button.set_label('Show Cached Data')
self.files_treeview.destroy()
self.cached_cred_vbox.hide()
return
path_found = True
cach_empty = False
platform = sys.platform # if linux linux2 if windows win32
if platform == 'linux2':
path = os.path.expanduser('~/.subversion/auth/svn.simple')
elif platform == 'win32':
path = os.path.join(os.path.expandvars('$APPDATA'), 'Subversion\\auth\\svn.simple')
else:
path_found = False
if path_found:
if os.path.exists(path) and os.path.isdir(path):
files = os.listdir(path)
files = map(lambda x: os.path.join(path, x), files)
files = filter(os.path.isfile, files)
#files = dict([(os.path.basename(x), x) for x in files])
if len(files):
self.display_cached_data(files)
return
else:
# this probably means the cach folder is empty
cach_empty = True
else:
path_found = False
def is_cached_data_file(self, file_name):
# every other line of file must be 'K n' and 'V m' valuse.
# n and m must be the lengths of the following lines
# ther must be a line == 'K 8' followed by a line == 'username' followed by line == 'V m' followed by username of len m
# the last line mus be a 'END'
fp = open(file_name)
lines = fp.readlines()
fp.close()
lines = map(str.strip, lines)
if lines[-1] != 'END': return (False, "Last line mus be a 'END'")
lines = lines[:-1]
if not all([line.startswith('K') for line in lines[::4]]): return (False, "Every fourth line must be a 'K n'")
if not all([line.startswith('V') for line in lines[2::4]]): return (False, "Every fourth line must be a 'V m'")
for i in range(0, len(lines)-1, 2):
if lines[i].split()[1].isdigit():
length = int(lines[i].split()[1])
else:
return (False, "In 'K n' and 'V m' n and m must be integers")
if len(lines[i+1]) != length:
return (False, "n and m in 'K n' and 'V m' must be lengths of following lines")
if lines[-3] != 'username':
return (False, "There is no 'username' line")
if lines[-7] != 'svn:realmstring':
return (False, "There is no 'svn:realmstring' line")
return [True, lines[-1], lines[-5]]
def display_cached_data(self, files):
self.cached_files = []
accounts = []
for f in files:
try:
ret = self.is_cached_data_file(f)
except:
continue
if ret[0]:
self.cached_files.append(f)
account = ret[1:]
account.append(False)
accounts.append(account)
column_types = (gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_BOOLEAN)
column_names = ('Username', 'SVN Realmstring', 'Clear')
liststore = gtk.ListStore(*column_types)
treeview = gtk.TreeView(liststore)
treeview.set_grid_lines(gtk.TREE_VIEW_GRID_LINES_BOTH)
for n in range(len(column_names)):
if n < 2:
cell = gtk.CellRendererText()
tvcolumn = gtk.TreeViewColumn(column_names[n], cell, text=n)
else:
cell = gtk.CellRendererToggle()
cell.set_property('activatable', True)
cell.connect('toggled', self.cach_clear_toggled, n, liststore)
tvcolumn = gtk.TreeViewColumn(column_names[n], cell)
tvcolumn.add_attribute(cell, 'active', n)
treeview.append_column(tvcolumn)
self.files_treeview = treeview
for account in accounts:
liststore.append(account)
hb = gtk.HBox()
hb.pack_start(self.files_treeview)
self.cached_cred_vbox.pack_start(hb)
self.cached_cred_vbox.show_all()
def cach_clear_toggled(self, cell, row, col, model):
model[row][col] = not model[row][col]
def save_prefs(self, widget, data=None):
self.parent.notebook.set_tab_pos(self.set_tab_pos_cbo.get_active())
self.parent.hbuttonbox_batch_mode.set_property('visible', self.batch_allocation_chk.get_active())
self.parent.config.set('interface', 'tab_pos', self.set_tab_pos_cbo.get_active())
self.parent.config.set('interface', 'batch_allocation', self.batch_allocation_chk.get_active())
self.parent.config.set('project', 'load_recent', self.load_recent_chk.get_active())
self.parent.config.set('operations', 'alt_random', self.alt_random_chk.get_active())
self.parent.config.set('operations', 'cach_cred', self.cach_cred_chk.get_active())
self.parent.config.set('operations', 'backup_network', self.backup_network_file_chk.get_active())
self.parent.config.set('operations', 'backup_network_path', self.backup_network_file_path_button.get_filename())
with open(self.parent.config_file, 'wb') as config_file:
self.parent.config.write(config_file)
config_file.flush()
config_file.close()
self.parent.config.read(self.parent.config_file)
if not self.parent.trial_file_name:
if self.parent.config.getboolean('project', 'load_recent'):
self.parent.trial_file_name = self.parent.config.get('project', 'recent_trial')
else:
self.parent.trial_file_name = None
if self.parent.trial_file_name:
self.parent.waiting_function(self.parent.load_trial, (self.parent.trial_file_name,))
if not self.parent.trial_file_name:
functions.error_dialog(self.window, 'Critical error while loading the last trial!', 'Trial load failed!')
self.parent.set_new_trial()
else:
self.parent.set_new_trial()
if self.cached_cred_vbox.get_property('visible'):
model = self.files_treeview.get_model()
for row in range(len(model)):
if model[row][2]:
os.remove(self.cached_files[row])
self.parent.random = functions.get_app_random(self.parent.config)
self.window.destroy()
def close_window(self, widget, data=None):
self.window.destroy()