-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.py
116 lines (92 loc) · 3.31 KB
/
controller.py
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
# encoding: utf-8
import os
from Queue import Queue
from threading import Thread
from traceback import print_exc
from tkMessageBox import showinfo, showerror
from penview import *
from model import *
from dialog import *
class PVController(Thread):
# constructor & api methods
#
def __init__(self, window):
Thread.__init__(self)
self.conf = window.conf
self.window = window
self.loop = True
self.action_q = Queue()
window.set_controller(self)
def q(self, action):
self.action_q.put(action)
def wait_idle(self):
self.window.wait_idle()
self.action_q.join()
def stop(self):
self.loop = False
# target function called by Thread.start()
#
def run(self):
while self.loop:
task = self.action_q.get()
try:
self.get_handler(task)()
except Exception, e:
if debug_flag:
print_exc()
else:
self.window.tk_do(showerror, app_name, str(e))
finally:
self.action_q.task_done()
# helper function
#
def get_handler(self, action):
try:
return getattr(self, "do_" + PVAction.name(action))
except AttributeError:
raise Exception("'%s' is not implemented yet" % PVAction.name(action))
# event handlers for most defined actions
#
def do_quit_app(self):
self.window.stop()
self.stop()
def do_show_graph(self):
self.conf.set_viewmode(ViewMode.graph)
def do_show_table(self):
self.conf.set_viewmode(ViewMode.table)
def do_show_about(self):
self.window.tk_do(showinfo, "%s" % app_name, "Version %s" % app_version)
def do_show_help(self):
import webbrowser
homepage = "http://p2000.github.com/penview/"
message = """Your default web browser should take you to the PenView home page, %s, shortly.\n""" % homepage + \
"""Check the "Documentation" section there and if you still need further help, please don't hesitate to write an email to the developers."""
webbrowser.open(homepage)
self.window.tk_do(showinfo, "%s" % app_name, message)
def do_open_exp(self):
path = self.window.tk_do(Dialog.get_ex_path)
if not path:
return
self.conf.add_open_experiment(OpenExperiment(ExperimentFile(path), self.window))
def do_import_exp(self):
path = self.window.tk_do(Dialog.get_csv_path)
if not path:
return
csv = CSVImporter(path)
while True:
ex_path = self.window.tk_do(Dialog.get_new_ex_path)
if not ex_path:
return
if not os.path.exists(ex_path):
break
if self.window.tk_do(askokcancel, "Experiment File", "File exists. Overwrite?"):
os.unlink(ex_path)
break
if not ex_path.endswith(".sqlite"):
ex_path += ".sqlite"
ex_file = ExperimentFile(ex_path, csv.rowsize - 1)
ex_file.store_values(1, csv.values)
ex_file.store_metadata(csv.metadata)
self.conf.add_open_experiment(OpenExperiment(ex_file, self.window))
def do_reset_scale(self):
self.conf.reset_scales()