-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_gui.py
174 lines (124 loc) · 5.61 KB
/
all_gui.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
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
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 24 17:43:57 2018
gui to run everything
@author: Patrick
"""
#import necessary modules
import os
import sys
# os.chdir(getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))))
import subprocess
import spike_analysis.gui
import kilosort_control.sort_gui
#import GUI objects/Widgets
from PySide2.QtCore import QRect
from PySide2.QtWidgets import (QApplication, QMainWindow, QFrame, QSizePolicy,
QVBoxLayout, QMenuBar, QPushButton)
from PySide2.QtGui import QGuiApplication
#make sure we're using the right qt API
os.environ['QT_API'] = 'pyside2'
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Let's begin!
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#class for MainWindow instance
class MainWindow(QMainWindow):
def __init__(self, parent=None):
''' sets up the whole main window '''
#standard init
super(MainWindow, self).__init__(parent)
#set the window title
self.setWindowTitle('SpikeSuite')
#get screen dimensions
self.screen_height = QGuiApplication.primaryScreen().availableGeometry().height()
self.screen_width = QGuiApplication.primaryScreen().availableGeometry().width()
self.make_buttons()
#create a QMenuBar and set geometry
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QRect(0, 0, self.screen_width*.5, self.screen_height*.03))
#set the QMenuBar as menu bar for main window
self.setMenuBar(self.menubar)
#show the window fullscreen
self.resize(600, 400)
def make_buttons(self):
buttons = QFrame(self)
buttons_layout = QVBoxLayout()
self.acquire_button = QPushButton('Acquire',buttons)
self.sort_button = QPushButton('Sort',buttons)
self.analyze_button = QPushButton('Analyze',buttons)
self.acquire_button.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
self.sort_button.setSizePolicy(QSizePolicy.Preferred,QSizePolicy.Expanding)
self.analyze_button.setSizePolicy(QSizePolicy.Preferred,QSizePolicy.Expanding)
self.acquire_button.setStyleSheet('background-color: darkRed')
self.sort_button.setStyleSheet('background-color: darkBlue')
self.analyze_button.setStyleSheet('background-color: darkGreen')
self.analyze_button.clicked.connect(self.run_analysis)
self.acquire_button.clicked.connect(self.run_acq)
self.sort_button.clicked.connect(self.run_sort)
buttonstyle = 'QPushButton{border-style: solid;border-width: 2px;border-radius: 40px;font: bold 30px; color: white}'
buttonstyle += 'QPushButton:hover{border-width: 4px; border-color:black}'
buttons.setStyleSheet(buttonstyle)
buttons_layout.addWidget(self.acquire_button)
buttons_layout.addWidget(self.sort_button)
buttons_layout.addWidget(self.analyze_button)
buttons.setLayout(buttons_layout)
self.setCentralWidget(buttons)
def run_analysis(self):
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/spike_analysis')
#create and show the main window
self.analysis_frame = spike_analysis.gui.MainWindow(launcher=self)
self.analysis_frame.show()
#set up stream for stdout and stderr based on outputStream class
self.outputStream = spike_analysis.gui.outputStream()
#when outputStream sends messages, connect to appropriate function for
#writing to terminal window
self.outputStream.message.connect(self.analysis_frame.print_message)
#connect stdout and stderr to outputStream
sys.stdout = self.outputStream
sys.stderr = self.outputStream
self.close()
def run_sort(self,recdir=None):
os.chdir(os.path.dirname(os.path.abspath(__file__)) + '/kilosort_control')
#create and show the main window
self.recdir = recdir
self.sort_frame = kilosort_control.sort_gui.MainWindow(launcher=self)
self.sort_frame.show()
#set up stream for stdout and stderr based on outputStream class
self.outputStream = kilosort_control.sort_gui.outputStream()
#when outputStream sends messages, connect to appropriate function for
#writing to terminal window
self.outputStream.message.connect(self.sort_frame.print_message)
#connect stdout and stderr to outputStream
sys.stdout = self.outputStream
sys.stderr = self.outputStream
self.close()
def run_acq(self):
subprocess.Popen('python ./oe_control/control_gui.py',
shell=True)
# self.close()
sys.exit(app.exec_())
def show_launcher(self):
#create and show the main window
os.chdir(os.path.dirname(os.path.abspath(__file__)))
self.show()
try:
self.analysis_frame.close()
except:
pass
try:
self.sort_frame.close()
except:
pass
if __name__ == '__main__':
#create a QApplication if one doesn't already exist
app = QApplication.instance()
if app == None:
app = QApplication([])
#create and show the main window
frame = MainWindow()
if len(sys.argv) > 1:
frame.run_sort(sys.argv[1])
else:
frame.show()
#exit the app when we're all done
sys.exit(app.exec_())