Editing Python Desk Top Applications
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 1: | Line 1: | ||
− | This | + | This will be a page about how I write my desktop applications, and so naturally, how I would recommend they be writtern. It also documents the structure of most of the applications that I have documented on this wiki. Try them and let me know how you think they might be better. |
− | + | [[Python Smart Plug Technical]] | |
= Overview = | = Overview = | ||
== General Information == | == General Information == | ||
− | These notes are here so you can more easily modify my code and build your own. | + | These notes are here so you can more easily modify my code and build your own. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Here is an overview of the general plan, details can be filled out by reading the example code in my projects ( see category ..... below). | Here is an overview of the general plan, details can be filled out by reading the example code in my projects ( see category ..... below). | ||
+ | |||
The overall architecture is called the model view controller or MVC. | The overall architecture is called the model view controller or MVC. | ||
Line 45: | Line 29: | ||
*Windows 10 64bit | *Windows 10 64bit | ||
− | *Anaconda Spyder | + | *Anaconda Spyder 3.x |
*Python 3.7 | *Python 3.7 | ||
Line 59: | Line 43: | ||
I have had some issues with matplotlib in linux which are still unresolved. | I have had some issues with matplotlib in linux which are still unresolved. | ||
− | = | + | = Components and Functions = |
− | + | ||
* Tkinter for the GUI | * Tkinter for the GUI | ||
* pyLogging for logging | * pyLogging for logging | ||
+ | * SmartTerminal a model-view-controller controller with some modifications ( '''[https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller Model–view–controller - Wikipedia ]''' or perhaps closer to '''[https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93presenter Model–view–presenter - Wikipedia ]''' ) | ||
* Second thread for processing without being blocked by/blocking the GUI | * Second thread for processing without being blocked by/blocking the GUI | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
* Global Singleton for app cohesion. | * Global Singleton for app cohesion. | ||
* Parameter file for easy customization. | * Parameter file for easy customization. | ||
− | * | + | * Mathplotlib for graphing. |
− | * | + | * SQLLite for the database. |
− | |||
− | + | == The Controllers for Smart Plug == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == The Controllers for | ||
The class for the MVC controller is also the class you create to run the application: see the code at the bottom of the file, just run the file. Similar code is at the bottom of some of the other source files to make it convenient to run from those files, this is just to make it easier in development, the code in smart_plug.py is the model for what should be used. Sometimes the code at the bottom of other file may have code for testing objects in the file, it may not be maintained, may not work as intended. | The class for the MVC controller is also the class you create to run the application: see the code at the bottom of the file, just run the file. Similar code is at the bottom of some of the other source files to make it convenient to run from those files, this is just to make it easier in development, the code in smart_plug.py is the model for what should be used. Sometimes the code at the bottom of other file may have code for testing objects in the file, it may not be maintained, may not work as intended. | ||
The __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 .restart which is used to restart the application when just the parameters have been changed. See the docstring there. | The __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 .restart which is used to restart the application when just the parameters have been changed. See the docstring there. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Threads == | == Threads == | ||
Line 139: | Line 70: | ||
=== HelperThread === | === HelperThread === | ||
− | + | Refers to similar but different program !! Will update for this program soon. | |
− | + | 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. | |
− | |||
− | |||
− | |||
− | |||
== 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 to application elements that need them. The instance of parameters is made globally available thru the AppGlobal class. Values in Parameters are treated as constants, read only. 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 to application elements that need them. The instance of parameters is made globally available thru the AppGlobal class. Values in Parameters are treated as constants, read only. Much of the appearance and behavior of the application is controlled here. | ||
Line 165: | Line 90: | ||
== DataBase == | == DataBase == | ||
For databases I have used both SQLLite and versions of MySQL. See application for which one it uses. I may expand on this section later for now see the code. | For databases I have used both SQLLite and versions of MySQL. See application for which one it uses. I may expand on this section later for now see the code. | ||
+ | |||
+ | == Polling == | ||
+ | Both threads have method that perform polling for events often for items in their queue that may have been sent from the other thread. Info on a similar app in [[Python Smart Terminal Technical Details]]. | ||
== Logging == | == Logging == | ||
− | This uses the standard Python logging class. Logging level and other logging details are controlled using the parameter file. | + | This uses the standard Python logging class. Logging level and other logging details are controlled using the parameter file. |
− | |||
== System Editor == | == System Editor == | ||
Line 175: | Line 102: | ||
== Other Classes == | == Other Classes == | ||
For now the documentation, as far as it exists is in the source code. This probably will not change. | For now the documentation, as far as it exists is in the source code. This probably will not change. | ||
+ | |||
= Coding Conventions = | = Coding Conventions = | ||
Line 191: | Line 119: | ||
− | [[Category:Python]] [[Category:Python Projects]] [[Category:SmartTerminal]][[Category:Python SmartPlug]] [[Category:Python Easy DB]] [[Category:ClipBoard | + | [[Category:Python]] [[Category:Python Projects]] [[Category:SmartTerminal]][[Category:Python SmartPlug]] [[Category:Python Easy DB]] [[Category:ClipBoard]] |