Viewing Category : python

Post thumbnail of How to make a dictionary of dictionaries with Python
18 October 2011
Continue reading How to make a dictionary of dictionaries with Python

How to make a dictionary of dictionaries with Python

Create a simple class of dictionaries to make a dictionary of dictionaries. No need for generators, iterators or lambdas. Use a deck of cards for example.

Post thumbnail of Get the hostname of a system in python
7 October 2011
Continue reading Get the hostname of a system in python

Get the hostname of a system in python

There are multiple ways to do it. Some are platform dependent.The best way is probably through socket, but you can use platform and os too.

Post thumbnail of Avoid looping through treeview iterators with row references
27 September 2011
Continue reading Avoid looping through treeview iterators with row references

Avoid looping through treeview iterators with row references

Keeping a dictionary of treerowreferences is the way to go. It makes keeping track of rows a breeze. You don’t have to worry about row locations changing over time as the treerowref keeps track of that automatically.
When you add a parent row to a treestore you get an iterator returned. …

Post thumbnail of Make stock gtk icons from your own images and pixbufs
19 September 2011
Continue reading Make stock gtk icons from your own images and pixbufs

Make stock gtk icons from your own images and pixbufs

If you want to set a cell to a pixmap, ok no problem, but what about setting individual liststore values to a pixmap? You can’t do it directly unless you’re using a gtk.STOCK_ image. Here’s a way around that little problem.

Post thumbnail of Python: two-way thread communication made simple
13 September 2011
Continue reading Python: two-way thread communication made simple

Python: two-way thread communication made simple

You don’t need heavyweight communication layers for very simple message passing between threads in python. It’s pretty simple to use pipes and implement your own thread class.

Post thumbnail of Hide a dialog without destroying - pygtk one-liner
2 September 2011
Continue reading Hide a dialog without destroying - pygtk one-liner

Hide a dialog without destroying - pygtk one-liner

If you like the standard window decorations and dont need/want to create your own buttons to handle custom events, closing a dialog without destroying it is a simple one-liner in pygtk. This is helpful when you have logic that replaces individual widgets inside a dialog and you don’t want to recreate the whole dialog.

Post thumbnail of Capture Right Click events in pygtk
27 July 2011
Continue reading Capture Right Click events in pygtk

Capture Right Click events in pygtk

If you pass in the event when you enter a callback, you can look at event.type to determine which button was pushed and process the action accordingly. Make sure to check the event.type first for a button press as not all events will define an event.button.

Post thumbnail of Compile python scripts without running them
7 July 2011
Continue reading Compile python scripts without running them

Compile python scripts without running them

If you want to check for syntax errors without actually running your code, you can compile it with py_compile. You may want to do this if your code modifies files or interacts with the network or external hardware or applications.

Post thumbnail of Thread control in python - how to safely stop a thread
20 June 2011
Continue reading Thread control in python - how to safely stop a thread

Thread control in python - how to safely stop a thread

So you want to kill a thread… Dangerous. How about asking a thread to die instead? Of course it’s unsafe to just kill a thread dead in its tracks. What if the thread has some resource acquired or is controlling other threads itself? It’s much better to communicate with a thread and tell it to stop, then just wait for it to kill itself.

Post thumbnail of Simple AES Encryption Vault in python
9 June 2011
Continue reading Simple AES Encryption Vault in python

Simple AES Encryption Vault in python

I needed to encrypt some strings before sending them out over the network to another process and I don’t want to rely on another mechanism for handling the encryption, so here’s my simple AES encryption class. You can load plain text out of the vault by providing a cipher or save an encrypted message by supplying the plain text.

 Page 1 of 4  1  2  3  4 »
Powered by Wordpress   |   Lunated designed by ZenVerse