source: remote_control/puzzlebox_brainstorms_client_interface_local.py @ 101

Last change on this file since 101 was 101, checked in by sc, 11 years ago
  • DISCRETE_CONTROL_COMMANDS renamed VARIABLE_CONTROL_DURATION
  • Property svn:executable set to *
File size: 5.5 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
29import puzzlebox_brainstorms_configuration as configuration
30import puzzlebox_brainstorms_client_interface as client_interface
31import puzzlebox_brainstorms_network_client as brainstorms_client
32import puzzlebox_brainstorms_network_server as server
33import puzzlebox_brainstorms_remote_control as remote_control
34#import puzzlebox_logger
35
36#####################################################################
37# Globals
38#####################################################################
39
40DEBUG = 1
41
42SERVER_INTERFACE = configuration.BRAINSTORMS_SERVER_INTERFACE
43SERVER_HOST = configuration.BRAINSTORMS_SERVER_HOST
44SERVER_PORT = configuration.BRAINSTORMS_SERVER_PORT
45
46CLIENT_NO_REPLY_WAIT = configuration.CLIENT_NO_REPLY_WAIT * 1000
47
48DELIMITER = configuration.BRAINSTORMS_DELIMITER
49
50BLUETOOTH_DEVICE = configuration.NXT_BLUETOOTH_DEVICE
51
52VARIABLE_CONTROL_DURATION = configuration.BRAINSTORMS_VARIABLE_CONTROL_DURATION
53
54#####################################################################
55# Classes
56#####################################################################
57
58class puzzlebox_brainstorms_client_interface_local( \
59              server.puzzlebox_brainstorms_network_server, \
60              client_interface.puzzlebox_brainstorms_client_interface):
61       
62        def __init__(self, log, \
63                          server_interface=SERVER_INTERFACE, \
64                          server_port=SERVER_PORT, \
65                          DEBUG=DEBUG, \
66                          parent=None):
67               
68                self.log = log
69                self.DEBUG = DEBUG
70               
71                self.server_interface = server_interface
72                self.server_port = server_port
73               
74                QtGui.QWidget.__init__(self, parent)
75                self.setupUi(self)
76               
77                self.configureNetwork()
78               
79                self.configureSettings()
80                self.configureNetworkBrainstorms()
81                self.connectWidgets()
82               
83                self.drive_state = 'stop_motors'
84                self.current_speed = 0
85               
86                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
87                            device=BLUETOOTH_DEVICE, \
88                            DEBUG=DEBUG)
89
90
91#####################################################################
92#####################################################################
93
94class puzzlebox_brainstorms_network_server_threaded( \
95              QtCore.QThread, \
96              server.puzzlebox_brainstorms_network_server):
97       
98        def __init__(self, log, \
99                          server_interface=SERVER_INTERFACE, \
100                          server_port=SERVER_PORT, \
101                          embedded_mode=True, \
102                          DEBUG=DEBUG, \
103                          parent=None):
104               
105                #super(puzzlebox_brainstorms_network_server_threaded, self).__init__(parent)
106                QtCore.QThread.__init__(self,parent)
107               
108                self.log = log
109                self.DEBUG = DEBUG
110               
111                self.server_interface = server_interface
112                self.server_port = server_port
113               
114                self.embedded_mode=embedded_mode
115               
116                self.configureNetwork()
117               
118                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
119                            device=BLUETOOTH_DEVICE, \
120                            DEBUG=DEBUG)
121       
122       
123        ##################################################################
124       
125        def run(self):
126               
127                if self.DEBUG:
128                        print "<---- [%s]: Main thread running" % self.socket.name
129                        self.exec_()
130               
131                #while True:
132                        #print "server: alive"
133                        #QtCore.QThread.sleep(1)
134
135
136#####################################################################
137# Functions
138#####################################################################
139
140#####################################################################
141# Main
142#####################################################################
143
144if __name__ == '__main__':
145       
146        # Perform correct KeyboardInterrupt handling
147        signal.signal(signal.SIGINT, signal.SIG_DFL)
148       
149        #log = puzzlebox_logger.puzzlebox_logger(logfile='client_interface')
150        log = None
151       
152        # Collect default settings and command line parameters
153        server_interface = SERVER_INTERFACE
154        server_host = SERVER_HOST
155        server_port = SERVER_PORT
156       
157        for each in sys.argv:
158               
159                if each.startswith("--interface="):
160                        server_interface = each[ len("--interface="): ]
161                if each.startswith("--host="):
162                        server_host = each[ len("--host="): ]
163                if each.startswith("--port="):
164                        server_port = each[ len("--port="): ]
165       
166        app = QtGui.QApplication(sys.argv)
167       
168        server = server.puzzlebox_brainstorms_network_server(log, \
169                    server_interface, \
170                    server_port, \
171                    embedded_mode=True, \
172                    DEBUG=DEBUG)
173       
174        #server = puzzlebox_brainstorms_network_server_threaded(log, \
175                    #server_interface, \
176                    #server_port, \
177                    #embedded_mode=True, \
178                    #DEBUG=DEBUG)
179        #server.start()
180       
181        # For debugging purposes it may be useful to launch an integrated
182        # ThinkGear Connect server emulator
183        #
184        #sys.path.append(os.path.join(os.getcwd(), "../thinkgear_emulator"))
185        #import puzzlebox_thinkgear_server as thinkgear_server
186        #
187        #thinkgear_server = \
188        #   thinkgear_server.puzzlebox_brainstorms_network_server_thinkgear(log, DEBUG=DEBUG)
189       
190       
191        window = client_interface.puzzlebox_brainstorms_client_interface(log, DEBUG)
192        window.connectToBrainstormsServer()
193        window.show()
194       
195        sys.exit(app.exec_())
196
Note: See TracBrowser for help on using the repository browser.