11"""
22 BlocklyProp Client
33
4+ 0.5.3 February 22, 2017
5+ - Correct error in path to propeller-load executable.
6+ - Detect condition where serial port has disappeared
7+ - Correct error where browser request for specific port
8+ speed was disregarded.
9+
410"""
511import Tkinter as tk
612import ttk as ttk
2329__author__ = 'Michel & Vale'
2430
2531PORT = 6009
26- VERSION = "0.5.2"
32+
33+ # -----------------------------------------------------------------------
34+ # NOTE:
35+ #
36+ # Please verify that the version number in the local about.txt and the
37+ # ./package/win0resources/blocklypropclient-installer.iss
38+ # -----------------------------------------------------------------------
39+ VERSION = "0.5.3"
2740
2841
2942# Enable logging for functions outside of the class definition
30- module_logger = logging . getLogger ( 'blockly' )
43+ module_logger = None
3144
3245
3346class BlocklyPropClient (tk .Tk ):
3447 def __init__ (self , * args , ** kwargs ):
48+ global module_logger
3549
3650 # Enable application logging
3751 BlocklyLogger .init ()
3852 self .logger = logging .getLogger ('blockly.main' )
53+ module_logger = logging .getLogger ('blockly' )
54+
3955 self .logger .info ('Creating logger.' )
4056
4157 BlocklyHardware .init ()
@@ -45,11 +61,13 @@ def __init__(self, *args, **kwargs):
4561
4662 # initialize values
4763 self .version = 0.0
64+ self .app_version = "0.0"
4865 self .connected = False
4966
50- # Path
67+ # Path to where application was launched
5168 self .appdir = os .path .dirname (sys .argv [0 ])
5269 self .logger .info ('Logging is enabled' )
70+ self .logger .info ('Application launched from %s' , self .appdir )
5371
5472 # initialize config variables
5573 self .ip_address = tk .StringVar ()
@@ -62,21 +80,28 @@ def __init__(self, *args, **kwargs):
6280
6381 self .title ("BlocklyProp" )
6482
65- # Set icon
83+ # Set icon for Windows platform
6684 self .logger .info ('Operating system is %s' , os .name )
6785 if "nt" == os .name :
6886 self .wm_iconbitmap (bitmap = 'blocklyprop.ico' )
69- else :
70- #self.wm_iconbitmap(bitmap = "@myicon.xbm")
71- pass
7287
88+ # Init the system
7389 self .initialize ()
7490 self .initialize_menu ()
75- # Verify the hardware is connected and available
7691
92+ # Set the application version and app_version values
7793 def set_version (self , version ):
78- self .logger .info ('Application version is %s' , version )
79- self .version = version
94+ # The application version number was converted to a traditional 'major'.'minor'.'patch_level'
95+ # format. There is code in the BlocklyProp Javascript that expects the version number as a
96+ # float. We handle that issue here.
97+ ver_elements = VERSION .split ('.' )
98+ if len (ver_elements ) >= 2 :
99+ n_version = float (ver_elements [0 ] + '.' + ver_elements [1 ])
100+ else :
101+ n_version = 0.4
102+
103+ self .version = n_version
104+ self .app_version = version
80105
81106 def initialize (self ):
82107 self .logger .info ('Initializing the UI' )
@@ -188,17 +213,19 @@ def handle_connect(self):
188213 self .logger .info ('Connect state is: %s' , self .connected )
189214
190215 if self .connected :
216+ self .logger .debug ('Terminating server process' )
191217 BlocklyServer .stop (self .q )
192218 self .server_process .terminate ()
193219 self .connected = False
220+
221+ # Set the connect/disconnect button text to the alternate state
194222 self .btn_connect ['text' ] = "Connect"
195223 else :
196224 # read entered values and start server
197225 self .server_process = multiprocessing .Process (
198226 target = BlocklyServer .main ,
199227 args = (int (self .port .get ()), self .version , self .q ))
200228
201- # self.server_process = threading.Thread(target=BlocklyServer.main, args=(int(self.port.get()), self.version)) #, kwargs={'out':self.stdoutToQueue})
202229 self .server_process .start ()
203230
204231 self .connected = True
@@ -222,23 +249,27 @@ def handle_code_browser(self):
222249 def handle_client_code_browser (self ):
223250 webbrowser .open_new ('http://github.com/parallaxinc/BlocklyPropClient' )
224251
252+ # Open the application About dialog box
225253 def about_info (self ):
226254 try :
227255 with open (self .appdir + '/about.txt' , 'r' ) as about_file :
228256 tkMessageBox .showinfo ("About BlocklyProp" , about_file .read ())
229- except :
257+ except OSError :
230258 tkMessageBox .showinfo ("About BlocklyProp" , "About file is missing" )
231259
260+ # Open the application Quit dialog box and process user selection
232261 def handle_close (self ):
233262 self .logger .info ('Opening Quit dialog' )
234263
235264 if tkMessageBox .askokcancel ("Quit?" , "Are you sure you want to quit?" ):
236- self .logger .info ('Quitting' )
237265 # stop server if running
238266 if self .connected :
239- # BlocklyServer.stop( )
267+ self . logger . info ( 'Terminating server process' )
240268 self .server_process .terminate ()
269+
241270 self .quit ()
271+ else :
272+ self .logger .debug ('Cancelling application quit request' )
242273
243274 def text_catcher (self ):
244275 try :
@@ -252,8 +283,8 @@ def text_catcher(self):
252283 self .ent_log .yview_pickplace ("end" )
253284 self .ent_log ['state' ] = 'disabled'
254285 except EOFError :
255- print ('EOF Error' )
256- # self.logger.error('Unexpected end of file encountered')
286+ # print('EOF Error')
287+ self .logger .error ('Unexpected end of file encountered' )
257288
258289
259290if __name__ == '__main__' :
0 commit comments