source: remote_control/puzzlebox_brainstorms_client_interface_local.py @ 95

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

setup:

  • sip module added as per PyQt? requirement for py2exe

remote_control/puzzlebox_brainstorms_client_interface_local.py:

  • attempts at solving threading issue with client/server communication

remote_control/puzzlebox_brainstorms_network_server_thinkgear.py:

  • moved to thinkgear_emulator directory

remote_control/puzzlebox_brainstorms_network_server.py:

  • comment cleanup
  • Property svn:executable set to *
File size: 5.2 KB
RevLine 
[87]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.06.28
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
42#####################################################################
43# Globals
44#####################################################################
45
46DEBUG = 1
47
48SERVER_INTERFACE = configuration.BRAINSTORMS_SERVER_INTERFACE
49SERVER_HOST = configuration.BRAINSTORMS_SERVER_HOST
50SERVER_PORT = configuration.BRAINSTORMS_SERVER_PORT
51
52CLIENT_NO_REPLY_WAIT = configuration.CLIENT_NO_REPLY_WAIT * 1000
53
54DELIMITER = configuration.BRAINSTORMS_DELIMITER
55
56BLUETOOTH_DEVICE = configuration.NXT_BLUETOOTH_DEVICE
57
58DISCRETE_CONTROL_COMMANDS = configuration.BRAINSTORMS_DISCRETE_CONTROL_COMMANDS
59
60#####################################################################
61# Classes
62#####################################################################
63
[94]64class puzzlebox_brainstorms_client_interface_local( \
65              server.puzzlebox_brainstorms_network_server, \
66              client_interface.puzzlebox_brainstorms_client_interface):
67       
68        def __init__(self, log, \
69                          server_interface=SERVER_INTERFACE, \
70                          server_port=SERVER_PORT, \
71                          DEBUG=DEBUG, \
72                          parent=None):
73               
74                self.log = log
75                self.DEBUG = DEBUG
76               
77                self.server_interface = server_interface
78                self.server_port = server_port
79               
80                QtGui.QWidget.__init__(self, parent)
81                self.setupUi(self)
82               
83                self.configureNetwork()
84               
85                self.configureSettings()
86                self.configureNetworkBrainstorms()
87                self.connectWidgets()
88               
89                self.drive_state = 'stop_motors'
90                self.current_speed = 0
91               
92                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
93                            device=BLUETOOTH_DEVICE, \
94                            DEBUG=DEBUG)
95
96
[87]97#####################################################################
[94]98#####################################################################
99
100class puzzlebox_brainstorms_network_server_threaded( \
101              QtCore.QThread, \
102              server.puzzlebox_brainstorms_network_server):
103       
104        def __init__(self, log, \
105                          server_interface=SERVER_INTERFACE, \
106                          server_port=SERVER_PORT, \
107                          DEBUG=DEBUG, \
108                          parent=None):
109               
110                #super(puzzlebox_brainstorms_network_server_threaded, self).__init__(parent)
111                QtCore.QThread.__init__(self,parent)
112               
113                self.log = log
114                self.DEBUG = DEBUG
115               
116                self.server_interface = server_interface
117                self.server_port = server_port
118               
119                self.configureNetwork()
120               
121                self.rc = remote_control.puzzlebox_brainstorms_remote_control( \
122                            device=BLUETOOTH_DEVICE, \
123                            DEBUG=DEBUG)
124       
125       
126        def run(self):
127                print "server: run"
128                self.exec_()
129                while True:
130                        print "server: alive"
131                        QtCore.QThread.sleep(1)
132
133
134
135#####################################################################
[87]136# Functions
137#####################################################################
138
139#####################################################################
140# Main
141#####################################################################
142
143if __name__ == '__main__':
144       
145        # Perform correct KeyboardInterrupt handling
146        signal.signal(signal.SIGINT, signal.SIG_DFL)
147       
148        #log = puzzlebox_logger.puzzlebox_logger(logfile='client_interface')
149        log = None
150       
151        # Collect default settings and command line parameters
152        server_interface = SERVER_INTERFACE
153        server_host = SERVER_HOST
154        server_port = SERVER_PORT
155       
156        for each in sys.argv:
157               
158                if each.startswith("--interface="):
159                        server_interface = each[ len("--interface="): ]
160                if each.startswith("--host="):
161                        server_host = each[ len("--host="): ]
162                if each.startswith("--port="):
163                        server_port = each[ len("--port="): ]
164       
165        app = QtGui.QApplication(sys.argv)
166       
[94]167        server = puzzlebox_brainstorms_network_server_threaded(log, \
[87]168                    server_interface, \
169                    server_port, \
170                    DEBUG=DEBUG)
[94]171        server.start()
[87]172       
173        window = client_interface.puzzlebox_brainstorms_client_interface(log, DEBUG)
174        window.show()
175       
[94]176        #window = puzzlebox_brainstorms_client_interface_local(log, \
177                                                              #server_interface, \
178                                                              #server_port, \
179                                                              #DEBUG)
180        #window.show()
181       
[87]182        sys.exit(app.exec_())
183
Note: See TracBrowser for help on using the repository browser.