aboutsummaryrefslogtreecommitdiff
path: root/botvac.py
blob: 9731d367e5f8e3f8c533cf9d2b959577ebdeabba (plain) (blame)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'botvac.ui'
#
# Created by: PyQt4 UI code generator 4.12.1
#
# WARNING! All changes made in this file will be lost!

from PyQt4 import QtCore, QtGui
#!/usr/bin/env python
from subprocess import call as run
from subprocess import check_output
from os.path import exists as chkf
import sys
import json

reload(sys)  
sys.setdefaultencoding('utf8')
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(472, 323)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab = QtGui.QWidget()
        self.tab.setObjectName(_fromUtf8("tab"))
        self.verticalLayout_2 = QtGui.QVBoxLayout(self.tab)
        self.verticalLayout_2.setMargin(0)
        self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
        self.startButton = QtGui.QPushButton(self.tab)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.startButton.sizePolicy().hasHeightForWidth())
        self.startButton.setSizePolicy(sizePolicy)
        self.startButton.setObjectName(_fromUtf8("startButton"))
        self.verticalLayout_2.addWidget(self.startButton)
        self.pauseButton = QtGui.QPushButton(self.tab)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.pauseButton.sizePolicy().hasHeightForWidth())
        self.pauseButton.setSizePolicy(sizePolicy)
        self.pauseButton.setObjectName(_fromUtf8("pauseButton"))
        self.verticalLayout_2.addWidget(self.pauseButton)
        self.resumeButton = QtGui.QPushButton(self.tab)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.resumeButton.sizePolicy().hasHeightForWidth())
        self.resumeButton.setSizePolicy(sizePolicy)
        self.resumeButton.setObjectName(_fromUtf8("resumeButton"))
        self.verticalLayout_2.addWidget(self.resumeButton)
        self.stopButton = QtGui.QPushButton(self.tab)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.stopButton.sizePolicy().hasHeightForWidth())
        self.stopButton.setSizePolicy(sizePolicy)
        self.stopButton.setObjectName(_fromUtf8("stopButton"))
        self.verticalLayout_2.addWidget(self.stopButton)
        self.send2baseButton = QtGui.QPushButton(self.tab)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.send2baseButton.sizePolicy().hasHeightForWidth())
        self.send2baseButton.setSizePolicy(sizePolicy)
        self.send2baseButton.setObjectName(_fromUtf8("send2baseButton"))
        self.verticalLayout_2.addWidget(self.send2baseButton)
        self.tabWidget.addTab(self.tab, _fromUtf8(""))
        self.tab_2 = QtGui.QWidget()
        self.tab_2.setObjectName(_fromUtf8("tab_2"))
        self.verticalLayout_3 = QtGui.QVBoxLayout(self.tab_2)
        self.verticalLayout_3.setMargin(0)
        self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
        self.textEdit = QtGui.QTextEdit(self.tab_2)
        self.textEdit.setReadOnly(True)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.verticalLayout_3.addWidget(self.textEdit)
        self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
        self.verticalLayout.addWidget(self.tabWidget)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 472, 26))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menuAbout = QtGui.QMenu(self.menubar)
        self.menuAbout.setObjectName(_fromUtf8("menuAbout"))
        MainWindow.setMenuBar(self.menubar)
        self.actionNeato_Account = QtGui.QAction(MainWindow)
        self.actionNeato_Account.setObjectName(_fromUtf8("actionNeato_Account"))
        self.actionMy_robot = QtGui.QAction(MainWindow)
        self.actionMy_robot.setObjectName(_fromUtf8("actionMy_robot"))
        self.actionThis_software = QtGui.QAction(MainWindow)
        self.actionThis_software.setObjectName(_fromUtf8("actionThis_software"))
        self.menuAbout.addAction(self.actionMy_robot)
        self.menubar.addAction(self.menuAbout.menuAction())
	
        
            
            
        def getAvailCmds():
            run(["python","aneatocli.py","--gc"])
            with open("robotstate.json","r") as json_file:
                data=json.load(json_file)
                
            def setbuttonState(dictstr,obj):
                if data[dictstr]:
                    obj.setEnabled(True)
                else:
                    obj.setEnabled(False)
            setbuttonState("start",self.startButton)
            setbuttonState("stop",self.stopButton)
            setbuttonState("pause",self.pauseButton)
            setbuttonState("resume",self.resumeButton)
            setbuttonState("goToBase",self.send2baseButton)

        getAvailCmds()
        
        # Penser à râfraichir l'état du robot de manière moins dégueulasse avec UN thread (même si c'est chaud en python wlh. Au moins toutes les 10-15secondes
        
        
        
        def __start(self):
            run(["python","aneatocli.py","--go"])
            getAvailCmds()
           
        def __stop(self):
            run(["python","aneatocli.py","--stp"])
            getAvailCmds()
        
        def __pause(self):
           run(["python","aneatocli.py","--pse"])
           getAvailCmds() 
            
            
            
        def __resume(self):
           run(["python","aneatocli.py","--res"])
           getAvailCmds()
        
        
        def __return(self):
           run(["python","aneatocli.py","--base"])
           getAvailCmds()
        
        self.startButton.clicked.connect(__start)
        self.stopButton.clicked.connect(__stop)
        self.pauseButton.clicked.connect(__pause)
        self.resumeButton.clicked.connect(__resume)
        self.send2baseButton.clicked.connect(__return)



        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "Neato Control", None))
        self.startButton.setText(_translate("MainWindow", "Start", None))
        self.pauseButton.setText(_translate("MainWindow", "Pause", None))
        self.resumeButton.setText(_translate("MainWindow", "Resume", None))
        self.stopButton.setText(_translate("MainWindow", "Stop", None))
        self.send2baseButton.setText(_translate("MainWindow", "Send to base", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("MainWindow", "Commands", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("MainWindow", "Info", None))
        self.menuAbout.setTitle(_translate("MainWindow", "My robot", None))
        self.actionNeato_Account.setText(_translate("MainWindow", "Neato Account", None))
        self.actionMy_robot.setText(_translate("MainWindow", "Account Infos", None))
        self.actionThis_software.setText(_translate("MainWindow", "This software", None))


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())