-
Notifications
You must be signed in to change notification settings - Fork 0
/
pbrain2.py
executable file
·121 lines (89 loc) · 3.82 KB
/
pbrain2.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
117
118
119
120
121
import math, re, os, sys, string
import numpy
from pbrainlib.gtkutils import str2num_or_err, simple_msg, error_msg, \
not_implemented, yes_or_no, FileManager, select_name, get_num_range, Dialog_FileSelection, Dialog_FileChooser, get_num_value
from data import EEGWeb, EEGFileSystem, EOI, Amp, Grids
from file_formats import FileFormat_BNI, W18Header, FileFormat_AxonAscii, FileFormat_NeuroscanAscii, FileFormat_AlphaomegaAscii, NeuroscanEpochFile
import pygtk
pygtk.require('2.0')
import gtk
class Pbrain2:
self.extmap = { '.w18' : load_w18,
'.bni' : load_bmsi,
'.params' : load_params,
'.epoch' : load_epoch,
'.axonascii' : load_axonascii,
'.neuroscanascii' : load_neuroscanascii,
'.alphaomegaascii' : load_alphaomegaascii
}
# This is a callback function. The data arguments are ignored
# in this example. More on callbacks below.
def hello(self, widget, data=None):
print "Hello World"
def delete_event(self, widget, event, data=None):
print "delete event occurred"
return False
def destroy(self, widget, data=None):
print "destroy signal occurred"
gtk.main_quit()
def __init__(self):
# create a new window
self.win = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.win.connect("delete_event", self.delete_event)
self.win.connect("destroy", self.destroy)
self.win.set_border_width(10)
self.button = gtk.Button("Hello World")
self.button.connect("clicked", self.hello, None)
self.win.add(self.button)
self.button.show()
self.win.show()
self.fmanager = FileManager()
dlg = Dialog_FileChooser(defaultDir=self.fmanager.get_lastdir(),
okCallback=self.ok_callback,
title='Select Neuroscanascii file',
parent=self.win,
previous_dirnames=self.fmanager.get_lastdirs())
def ok_callback(self, dlg):
fname = dlg.get_filename()
fullpath = dlg.get_filename()
self.fmanager.set_lastdir(fullpath)
dlg.destroy()
if not os.path.exists(fullpath):
error_msg(
'Cannot find %s' % fullpath,
title='Error',
parent=self.win)
basename, ext = os.path.splitext(fullpath)
if not self.extmap.has_key(ext.lower()):
error_msg(
'Do not know how to handle extension %s in %s' % (ext, fullpath),
title='Error',
parent=self.win)
return
else:
loader = self.extmap[ext.lower()]
try: eeg = loader(fullpath)
except ValueError, msg:
msg = exception_to_str('Error loading EEG' )
error_msg(msg, title='Error loading EEG',
parent=self.win)
return
else:
if eeg is None: return
print "on_menuFileOpen_activate: eeg ext is ", ext
if (eeg.get_file_type() != 1): # hack -- .bnis do not need .amp files
amp = eeg.get_amp()
if amp.message is not None:
simple_msg(amp.message, title='Warning',
parent=self.win)
#self.load_eeg(eeg)
return False
def main(self):
# All PyGTK applications must have a gtk.main(). Control ends here
# and waits for an event to occur (like a key press or mouse event).
gtk.main()
# If the program is run directly or passed as an argument to the python
# interpreter then create a HelloWorld instance and show it
if __name__ == "__main__":
pbrain2 = Pbrain2()
pbrain2.main()