[PyKDE] GUI wrapper for modules

Jonathan Gardner jgardner at jonathangardner.net
Tue Jun 1 20:00:00 BST 2004


On Sunday 30 May 2004 02:48 am, Thorsten Kampe wrote:
> For my first GUI Python application I thought of a wrapper for my
> utility modules I have already written. Kind of "EasyGUI"[1] style but
> much less sophisticated.
>
> I've got a module "test.py" in $PYTHONPATH containing one function:
> def multiply_by_two(x):
>     return x * 2
>
> Now the GUI app should do the following:
> * import module test
> * show one button with the following function:
> When I click on the button display one input form where I can enter a
> number and say "please enter a number". Then the application takes the
> number executes test.multiply_by_two(number) and display the result
> with message "the result is:"
>
> If anyone could provide me with the appropriate Python/PyQt code (even
> some "Pseudo Python code"), I'd be grateful.
>

Humm, I think I see where you are at right now. I will provide some pseudo 
code for you to get started. Feel free to ask details for things that 
aren't clear. However, spend some time yourself thinking about this.

Here's the pseudo code.

from your_module import multiply_by_two
from qt import *

class MainWidget(QWidget):

  def __init__(self, blah): # Sets up the widgets in the App.
    ...
    connect(the button, self.on_click)

  def on_click(self): # Creates and pops up the MyDialog
    .... 

class MyDialog(QDialog):

  def __init__(self, blah): # Sets up the widgets in the Dialog
    ...
    connect(the button, self.on_click)

  def on_click(self):
    # does multiple_by_two on whatever is in the box, and then pops up an
    # info dialog with the result. When the info dialog closes, this dialog
    # will close.
    ....

if __name__ == '__main__':
  # Generic set-up-the-app stuff.

If you'd like to see how to do this using QT Designer (thus saving time), 
you should look at the various tutorials available on PyQt on the internet. 
I'll shamelessly plug mine:

http://www.python.org/cgi-bin/moinmoin/JonathanGardnerPyQtTutorial

Questions and confusions are gladly accepted. Again, this is a starting 
point, ask questions about stuff that is confusing and we'll get it done 
together.

-- 
Jonathan Gardner
jgardner at jonathangardner.net




More information about the PyQt mailing list