Editing Python Smart Terminal Technical

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 54: Line 54:
 
The SmartTerminal.__init__ method is the initialization and "run" method for the application.  Much of the code that would normally be in it has been moved to SmartTerminal.restart which is used to restart the application when just the parameters have been changed.  See the docstring there.
 
The SmartTerminal.__init__ method is the initialization and "run" method for the application.  Much of the code that would normally be in it has been moved to SmartTerminal.restart which is used to restart the application when just the parameters have been changed.  See the docstring there.
  
== Global Values ==
+
== The Tkinker Thread ==
  
Yes I know that globals are bad, but they can be usefulFor example many class instances need to access the parameter file.  This can be done using the singleton class AppGlobal.
+
Once Tkinker is started it runs its own mainloopIn order to receive however we need to check the rs232 port from time to time.  This is done in SmartTerminal.polling() I call this thread the GUI thread or gtThe terminal is configured to have a second thread called the Helper Thread or ht.  See SmartTerminalHelper for more info.
It has values at the class level ( not instance ) that are available simply by importing the classMost values are defaulted to None, and are set to valid values as the application initializes.
 
  
== Threads ==
+
== HelperThread ==
 
 
The application runs two threads, one for the GUI and one where processing can occur ( HelperThread ) with out locking up the GUI.  There are 2 queues that allow the threads to communicate.
 
 
 
=== The Tkinker Thread ===
 
 
 
Once Tkinker is started it runs its own mainloop.  In order to receive however we need to check the rs232 port from time to time.  This is done in SmartTerminal.polling()  I call this thread the GUI thread or gt.  The terminal is configured to have a second thread called the Helper Thread or ht.  In some cases the receiving of data is passed to the Helper Thread so where data is processed in addition to being posted to the GUI. See the section HelperThread for more info.
 
 
 
=== HelperThread ===
 
  
 
HelperThread in smart_terminal_helper.py  This class provides the support for a second thread of execution that does not block the main thread being run by Tinker.  I call the two threads the GUI Thread (gt) and the Helper Thread ( ht ).  It can get confusing keeping track of which method is running in which thread, I sometimes annotate them with gt and ht.  The helper thread is started by running HelperThread.run() which pretty much just runs a polling task in HelperThread.polling().  HelperThread.polling() is an infinite loop, it uses sleep to set the polling rate.  When used with the green house processing module, it may call a function there that is its own infinite loop.  There are a lot of details here, I should write some more about it.
 
HelperThread in smart_terminal_helper.py  This class provides the support for a second thread of execution that does not block the main thread being run by Tinker.  I call the two threads the GUI Thread (gt) and the Helper Thread ( ht ).  It can get confusing keeping track of which method is running in which thread, I sometimes annotate them with gt and ht.  The helper thread is started by running HelperThread.run() which pretty much just runs a polling task in HelperThread.polling().  HelperThread.polling() is an infinite loop, it uses sleep to set the polling rate.  When used with the green house processing module, it may call a function there that is its own infinite loop.  There are a lot of details here, I should write some more about it.
Line 73: Line 64:
 
== Parameters ==
 
== Parameters ==
  
Parameters ( in parameters.py ) this is pretty much a structure ( that is all instance variables ) that is instantiated early in the life of the application.  It passes values, strings, numbers, objects around the application to other parts of the application that need them.  Much of the appearance and behavior of the application is controlled here.
+
Parameters ( in parameters.py ) this is pretty much a structure ( that is all instance variables ) that is instantiated early in the life of the application.  It passes values, strings, numbers, objects around the application to other parts of the application that needs them.  Much of the appearance and behavior of the application is controlled here.
  
 
The standard gui has a button to kick off editing of this file, the application may then be restarted ( another button ) with the new values.
 
The standard gui has a button to kick off editing of this file, the application may then be restarted ( another button ) with the new values.
  
There are a couple of meta parameters, the most important of which is mode which is then used in conditionals later in parameters.  Except for this sort of thing there is really not much "code" in parameters.  You can change this code pretty much as much as you like, as long as you end up setting up values for the required parameters.
+
There are a couple of meta parameters, the most important of which is mode which is then used in conditionals later in parameters.  Except for this sort of thing there is really no "code" in parameters.  You can change this code pretty much as much as you like, as long as you end up setting up values for the required parameters.
  
The code is extensively commented: use that for documentation.
+
The code is extensively commented use that for your documentation.
  
 
Values are often set to None as a default, then later set to some other value.  Or the value may be set several times in a row ( this is an artifact of messing with the values ); only the last value set has any meaning.
 
Values are often set to None as a default, then later set to some other value.  Or the value may be set several times in a row ( this is an artifact of messing with the values ); only the last value set has any meaning.
  
If asked for in the command line you can also envoke a second parameter file.  This is handy if you want two different instances of the terminal.
+
If asked for in the command line you can also envoke a second parameter file.  This is handy
 
 
For a lot more info see:  [[Smart Terminal Parameter Examples]]
 
  
 
== Processing Modules==  
 
== Processing Modules==  
  
So called processing modules offer you the opportunity to put some custom automatic processing in your terminal.  Typically this is matched up with a custom microcontroller application on the other end of the com port.  These are all implemented as descandants of the class ABCProcessing.  ( so far ABCProcessing does not add much value ) A couple of examples of processing modules and the arduino code are included in the download package, but beware they are in various states of maintenance. See: [[Writing You Own Extensions to SmartTerminal]]
+
So called processing modules offer you the opportunity to put some custom automatic processing in your terminal.  Typically this is matched up with a custom microcontroller application on the other end of the com port.  These are all implemented as descandants of the class ABCProcessing.  ( so far ABCProcessing does not add much value ) A couple of examples of processing modules and the arduino code are included in the download package, but beware they are in various states of maintenance.
  
 
== Microcontroller and Its Protocol ==
 
== Microcontroller and Its Protocol ==
Line 103: Line 92:
  
 
GHProcessing( in gh_processing.py )
 
GHProcessing( in gh_processing.py )
 
== Polling ==
 
Both threads have method that perform polling for events, events like received text, or items in their queue that may have been sent from the other thread.  More info in [[Python Smart Terminal Technical Details]]
 
  
 
== Logging ==
 
== Logging ==
This uses the standard Python logging class.  Logging level and other logging details are set up using the parameter file.
+
This uses the standard Python logging class.  Logging level is set up using the parameter file.
  
 
== Other Classes ==
 
== Other Classes ==
Line 118: Line 104:
  
 
== Names ==
 
== Names ==
Be consistent: this is good but have not been very successful in standards: I keep changing my mind.  Names across classes are pretty consistent.  I am avoiding short names and try to make them descriptive enough that they are somewhat self documenting.  References are often copied across objects for easy access ( lots of parameters for example ); when this happens the name of the object is generally ( should be always ) the same in both objects.
+
Be consistent: have not been very successful in standards: I keep changing my mind.  Names across classes are pretty consistent.  But I do not like short names and home my names are mostly descriptive.
  
 
== Formatting ==
 
== Formatting ==
Line 137: Line 123:
 
Almost everything is a class.  Not much in the way of module functions, not many classes in a module.  I am trying to have all my classes descend from something be it only Object.  And now that I am in Python 3.6 this is how it always works.
 
Almost everything is a class.  Not much in the way of module functions, not many classes in a module.  I am trying to have all my classes descend from something be it only Object.  And now that I am in Python 3.6 this is how it always works.
  
== Documentation for Class Instance Methods ==
+
== Class Methods ==
  
 
Look something like this:
 
Look something like this:
Line 148: Line 134:
 
         args:  strings
 
         args:  strings
 
         ret:  instance of the class
 
         ret:  instance of the class
        Side effects Class created
 
 
         """
 
         """
  

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)