Skip to content

Commit

Permalink
Final
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeTheWatchGuy committed Sep 10, 2019
1 parent 763da2a commit e5b5ca7
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docs/Pythonic GUIs.md
Expand Up @@ -28,8 +28,8 @@ Now there's a loaded word. It's subjective to be sure, but there are certain tra
A few traits that I find particularly enjoyable about the language and perhaps fall into the "Pythonic" category are: A few traits that I find particularly enjoyable about the language and perhaps fall into the "Pythonic" category are:


* User code is often short * User code is often short
* Code can be simultaneusly compact and readable (and beautiful too) * Code can be simultaneously compact and readable (and beautiful too)
* Python emphasises simplicity * Python emphasizes simplicity
* It's modular and has namespaces * It's modular and has namespaces
* List and Dictionary containers are hecka-powerful (this was surprising) * List and Dictionary containers are hecka-powerful (this was surprising)


Expand Down Expand Up @@ -70,7 +70,7 @@ There are plenty others, but for this discussion, this is our list.


### Not From Here ### Not From Here


One interesting and problematic fact about the top 3 GUI pacakges in Python is that they were not written for Python. They were designed, written, and used with C++ prior to being adapted to be used with Python. One interesting and problematic fact about the top 3 GUI packages in Python is that they were not written for Python. They were designed, written, and used with C++ prior to being adapted to be used with Python.


Bringing an existing GUI library into Python isn't the problem here. The problem is that they also brought a rigid definition of how a user's GUI code is be architected. All three of these packages require the user to write their GUI code using an Object Oriented architecture. Bringing an existing GUI library into Python isn't the problem here. The problem is that they also brought a rigid definition of how a user's GUI code is be architected. All three of these packages require the user to write their GUI code using an Object Oriented architecture.


Expand All @@ -80,7 +80,7 @@ Classes are a way to create new types in Python. They are also used, heavily, in


The "preferred" (only practical) way to use these GUI packages require the end user to design and write their GUI in an object oriented manner. Pick up a book on any of these GUI libraries and you'll see in every exercise the word Class. It's just how it is. The "preferred" (only practical) way to use these GUI packages require the end user to design and write their GUI in an object oriented manner. Pick up a book on any of these GUI libraries and you'll see in every exercise the word Class. It's just how it is.


Sure, you can, with some effort, "get around" using classes, but it's not straightforward nor easy, a couple of the defining characteristics of being "pythonic". Sure, you can, with some effort, "get around" using classes, but it's not straightforward nor easy, a couple of the defining characteristics of being "Pythonic".


Think through the Python standard library and it's many packages. Do any of these packages require you to design large sections of your code in a particular way in order to use them? Think through the Python standard library and it's many packages. Do any of these packages require you to design large sections of your code in a particular way in order to use them?


Expand All @@ -96,7 +96,7 @@ In Python, if you want something called, you call it.


### Events - Queues ### Events - Queues


Let's take queues as an example for handling "events". In the Python library there is a `queue` module that has an object called, you guesded it, a `Queue`. In some languages or libraries, a Queue object like this one would generate a callback when something arrives in the queue. Let's take queues as an example for handling "events". In the Python library there is a `queue` module that has an object called, you guessed it, a `Queue`. In some languages or libraries, a Queue object like this one would generate a callback when something arrives in the queue.


The way this `Queue` works in Python is that you `get` an item from the Queue. There are 2 modes you can use, blocking and non-blocking. Additionally, if blocking is specified, you can set a timeout value that will raise an Empty Exception when nothing is found in the queue within the timeout. The way this `Queue` works in Python is that you `get` an item from the Queue. There are 2 modes you can use, blocking and non-blocking. Additionally, if blocking is specified, you can set a timeout value that will raise an Empty Exception when nothing is found in the queue within the timeout.


Expand Down Expand Up @@ -129,7 +129,7 @@ Remember this model, you'll be seeing it again later.


When thinking about making a GUI module in Python, from scratch, what would be some of the defining characteristics? Here's my short list: When thinking about making a GUI module in Python, from scratch, what would be some of the defining characteristics? Here's my short list:


* Be accessable to everyone * Be accessible to everyone
* Make it "Pythonic", of course * Make it "Pythonic", of course
* Make use of the Python language's unique constructs * Make use of the Python language's unique constructs


Expand All @@ -141,11 +141,11 @@ Let's get concrete so that these concepts and characteristics can be demonstrate


Let's talk about these characteristics individually. Let's talk about these characteristics individually.


#### Be Accessable to Everyone #### Be Accessible to Everyone


Since everything's an object in Python and Python programmers are comfortable using objects, use objects in a way that's logical and simple, but don't require the user to create new objects of their own (i.e. they don't have to write the word class). Since everything's an object in Python and Python programmers are comfortable using objects, use objects in a way that's logical and simple, but don't require the user to create new objects of their own (i.e. they don't have to write the word class).


In order to make a button, users use the `Button` object. To show some text in the window it's a `Text` object, etc. We're just talking about using these objects, just like Theads or Queues. In order to make a button, users use the `Button` object. To show some text in the window it's a `Text` object, etc. We're just talking about using these objects, just like Threads or Queues.


#### Python's Core Types #### Python's Core Types


Expand All @@ -162,11 +162,11 @@ layout = [ [Text('This is some text on the first row')],
[Text('And text on second row'), Button('Our Button')] ] [Text('And text on second row'), Button('Our Button')] ]
``` ```


What we have is a list, with two lists inside of it. Each of the interrior lists represents one row of the GUI. Looking at this layout, it's probably obvious what this window will look like. What we have is a list, with two lists inside of it. Each of the interior lists represents one row of the GUI. Looking at this layout, it's probably obvious what this window will look like.


#### Making a Window #### Making a Window


We've got our window's interrior, now let's make a window. Like other std lib calls, such as Threads, mentioned before, it's a simple object that users interact with. We've got our window's interior, now let's make a window. Like other std lib calls, such as Threads, mentioned before, it's a simple object that users interact with.


```python ```python
window = Window('Title of window', layout) window = Window('Title of window', layout)
Expand Down

0 comments on commit e5b5ca7

Please sign in to comment.