-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmainwindow.cpp
130 lines (99 loc) · 3.76 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include <QtWidgets>
#include <QDesktopServices>
#include <QUrl>
MainWindow::MainWindow(int ignoreSettings)
: attys_scope(new Attys_scope(this,ignoreSettings))
{
setCentralWidget(attys_scope);
QFile style(":/QTDark.stylesheet");
style.open(QIODevice::ReadOnly);
setStyleSheet(style.readAll());
style.close();
setAutoFillBackground(true);
QMenu *attysScopeMenu = menuBar()->addMenu(tr("&attys-scope"));
QAction *quitAct = new QAction(tr("&Exit"), this);
attysScopeMenu->addAction(quitAct);
connect(quitAct,&QAction::triggered,attys_scope,&QCoreApplication::quit);
QMenu *configMenu = menuBar()->addMenu(tr("&Config"));
QAction *saveConfigAct = new QAction(tr("&Save"), this);
configMenu->addAction(saveConfigAct);
connect(saveConfigAct,&QAction::triggered,attys_scope,&Attys_scope::slotSaveSettings);
QAction *loadConfigAct = new QAction(tr("&Load"), this);
configMenu->addAction(loadConfigAct);
connect(loadConfigAct,&QAction::triggered,attys_scope,&Attys_scope::slotLoadSettings);
QMenu *pyMenu = menuBar()->addMenu(tr("&Python"));
QAction *runPythonAct = new QAction(tr("&Run"), this);
pyMenu->addAction(runPythonAct);
connect(runPythonAct,&QAction::triggered,attys_scope,&Attys_scope::slotRunPython);
QAction *runPythonLog = new QAction(tr("&Console"), this);
pyMenu->addAction(runPythonLog);
connect(runPythonLog,&QAction::triggered,attys_scope,&Attys_scope::slotLogPython);
QMenu *udpMenu = menuBar()->addMenu(tr("&Broadcast"));
QAction *startUDPAct = new QAction(tr("&Start UDP"), this);
udpMenu->addAction(startUDPAct);
connect(startUDPAct,&QAction::triggered,attys_scope,&Attys_scope::slotStartUDP);
QAction *stopUDPAct = new QAction(tr("&Stop UDP"), this);
udpMenu->addAction(stopUDPAct);
connect(stopUDPAct,&QAction::triggered,attys_scope,&Attys_scope::slotStopUDP);
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
QAction *runGithub = new QAction(tr("&github"), this);
helpMenu->addAction(runGithub);
connect(runGithub,&QAction::triggered,this,&MainWindow::slotGithub);
}
void MainWindow::slotGithub() {
QDesktopServices::openUrl(QUrl("https://github.com/glasgowneuro/attys-scope"));
}
/////////////////////////////////////////////////////////////////////
void helptxt(char *name) {
fprintf(stderr,"Help: use '%s -i' or '%s /i' to disable reading the configuration.\n",name,name);
exit(1);
}
int main( int argc, char **argv )
{
for(int i = 0;i<argc;i++) {
if (strstr(argv[i],"-h")) helptxt(argv[0]);
if (strstr(argv[i],"--help")) helptxt(argv[0]);
}
// default values
int ignoreSettings = 0;
QSettings settings(QSettings::IniFormat,
QSettings::UserScope,
ATTYS_STRING,
PROGRAM_NAME);
QApplication a( argc, argv ); // create application object
QPixmap pixmap(":/attys.png");
QSplashScreen* splash = new QSplashScreen(pixmap);
splash->setFont( QFont("Helvetica", 10, QFont::Black) );
splash->show();
splash->showMessage("Scanning for paired devices");
a.processEvents();
// callback
AttysScanMsg attysScanMsg;
attysScanMsg.splash = splash;
attysScanMsg.app = &a;
attysScan.registerCallback(&attysScanMsg);
// see if we have any Attys!
int ret = attysScan.scan(AttysScan::MAX_ATTYS_DEVS);
// none detected
if ((0 != ret) || (attysScan.getNAttysDevices()<1)) {
char tmp[] = "No Attys detected.\nExiting.";
attysScanMsg.message(0,tmp);
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
attysScan.unregisterCallback();
delete splash;
return -1;
}
for(int i = 0;i<argc;i++) {
if (strstr(argv[i],"/i")) ignoreSettings = 1;
if (strstr(argv[i],"-i")) ignoreSettings = 1;
}
MainWindow mainWindow(ignoreSettings);
// show widget
mainWindow.show();
attysScan.unregisterCallback();
splash->finish(&mainWindow);
delete splash;
// run event loop
return a.exec();
}