source: remote_control/puzzlebox_brainstorms_client_interface_local.py @ 97

Last change on this file since 97 was 97, checked in by sc, 11 years ago

remote_control/puzzlebox_brainstorms_client_interface.py:

  • corrected handling of disconnected Brainstorms server

remote_control/puzzlebox_brainstorms_client_interface_local.py:

  • thinkgear emulator added in to test server/client threading issues
  • Property svn:executable set to *
File size: 5.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Puzzlebox - Brainstorms - Client Interface - Qt - Local
5#
6# Copyright Puzzlebox Productions, LLC (2010)
7#
8# This code is released under the GNU Pulic License (GPL) version 2
9# For more information please refer to http://www.gnu.org/copyleft/gpl.html
10#
11# Last Update: 2010.07.09
12#
13#####################################################################
14
15import os, sys
16import signal
17
18#try:
19        #from PySide import QtCore, QtGui, QtNetwork
20#except:
21        #print "Using PyQt4 module"
22        #from PyQt4 import QtCore, QtGui, QtNetwork
23#else:
24        #print "Using PySide module"
25
26from PyQt4 import QtCore, QtGui, QtNetwork
27#from PySide import QtCore, QtGui, QtNetwork
28
29sys.path.append(os.path.join(os.getcwd(), "interface"))
30from qt4_form import Ui_Form
31
32import simplejson as json
33
34import puzzlebox_brainstorms_configuration as configuration
35import puzzlebox_brainstorms_client_interface as client_interface
36import puzzlebox_brainstorms_network_client as brainstorms_client
37import puzzlebox_brainstorms_network_client_thinkgear as thinkgear_client
38import puzzlebox_brainstorms_network_server as server
39import puzzlebox_brainstorms_remote_control as remote_control
40#import puzzlebox_logger
41
42sys.path.append(os.path.join(os.getcwd(), "../thinkgear_emulator"))
43import puzzlebox_thinkgear_server as thinkgear_server
44
45#####################################################################
46# Globals
47#####################################################################
48
49DEBUG = 1
50
51SERVER_INTERFACE = configuration.BRAINSTORMS_SERVER_INTERFACE
52SERVER_HOST = configuration.BRAINSTORMS_SERVER_HOST
53SERVER_PORT = configuration.BRAINSTORMS_SERVER_PORT
54
55CLIENT_NO_REPLY_WAIT = configuration.CLIENT_NO_REPLY_WAIT * 1000
56
57DELIMITER = configuration.BRAINSTORMS_DELIMITER
58
59BLUETOOTH_DEVICE = configuration.NXT_BLUETOOTH_DEVICE
60
61DISCRETE_CONTROL_COMMANDS = configuration.BRAINSTORMS_DISCRETE_CONTROL_COMMANDS
62
63#####################################################################
64# Classes
65#####################################################################
66
67class puzzlebox_brainstorms_client_interface_local( \
68              server.puzzlebox_brainstorms_network_server, \
69              client_interface.puzzlebox_brainstorms_client_interface):
70       
71        def __init__(self, log, \
72                          server_interface=SERVER_INTERFACE, \
73                          server_port=SERVER_PORT, \
74                          DEBUG=DEBUG, \
75                          parent=None):
76               
77                self.log = log
78                self.DEBUG = DEBUG
79               
80                self.server_interface = server_interface
81                self.server_port = server_port
82               
83                QtGui.QWidget.__init__(self, parent)
84                self.setupUi(self)
85               
86                self.configureNetwork()
87               
88                self.configureSettings()
89                self.configureNetworkBrainstorms()
90                self.connectWidgets()
91               
92                self.drive_state = 'stop_motors'
93                self.current_speed = 0
94               
95                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
96                            device=BLUETOOTH_DEVICE, \
97                            DEBUG=DEBUG)
98
99
100#####################################################################
101#####################################################################
102
103class puzzlebox_brainstorms_network_server_threaded( \
104              QtCore.QThread, \
105              server.puzzlebox_brainstorms_network_server):
106       
107        def __init__(self, log, \
108                          server_interface=SERVER_INTERFACE, \
109                          server_port=SERVER_PORT, \
110                          DEBUG=DEBUG, \
111                          parent=None):
112               
113                #super(puzzlebox_brainstorms_network_server_threaded, self).__init__(parent)
114                QtCore.QThread.__init__(self,parent)
115               
116                self.log = log
117                self.DEBUG = DEBUG
118               
119                self.server_interface = server_interface
120                self.server_port = server_port
121               
122                self.configureNetwork()
123               
124                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
125                            device=BLUETOOTH_DEVICE, \
126                            DEBUG=DEBUG)
127       
128       
129        def run(self):
130                print "server: run"
131                self.exec_()
132                while True:
133                        print "server: alive"
134                        QtCore.QThread.sleep(1)
135
136
137
138#####################################################################
139# Functions
140#####################################################################
141
142#####################################################################
143# Main
144#####################################################################
145
146if __name__ == '__main__':
147       
148        # Perform correct KeyboardInterrupt handling
149        signal.signal(signal.SIGINT, signal.SIG_DFL)
150       
151        #log = puzzlebox_logger.puzzlebox_logger(logfile='client_interface')
152        log = None
153       
154        # Collect default settings and command line parameters
155        server_interface = SERVER_INTERFACE
156        server_host = SERVER_HOST
157        server_port = SERVER_PORT
158       
159        for each in sys.argv:
160               
161                if each.startswith("--interface="):
162                        server_interface = each[ len("--interface="): ]
163                if each.startswith("--host="):
164                        server_host = each[ len("--host="): ]
165                if each.startswith("--port="):
166                        server_port = each[ len("--port="): ]
167       
168        app = QtGui.QApplication(sys.argv)
169       
170        server = puzzlebox_brainstorms_network_server_threaded(log, \
171                    server_interface, \
172                    server_port, \
173                    DEBUG=DEBUG)
174        server.start()
175       
176        thinkgear_server = thinkgear_server.puzzlebox_brainstorms_network_server_thinkgear(log, DEBUG=DEBUG)
177       
178        window = client_interface.puzzlebox_brainstorms_client_interface(log, DEBUG)
179        window.show()
180       
181        #window = puzzlebox_brainstorms_client_interface_local(log, \
182                                                              #server_interface, \
183                                                              #server_port, \
184                                                              #DEBUG)
185        #window.show()
186       
187        sys.exit(app.exec_())
188
Note: See TracBrowser for help on using the repository browser.