My first wxPython App with Twisted - barebones version

koranthala koranthala at gmail.com
Wed Aug 5 03:41:40 CEST 2009


Hi,
   I am creating the first GUI app (wxPython based) using Twisted.
   I am facing an issue which I cannot seem to solve/understand due
to lack of trace or anything.
   I had a big app written on twisted and now I am creating a login
screen to the app.
   The app used to work without any issues. I added the login screen
and the login screen comes up.
    But then everything freezes up. I have to force quit the python
application to get anything back. Can anyone help me solve it?
   The code is as follows:

import wx
import os
import logging

from twisted.internet import wxreactor
wxreactor.install()
from twisted.internet import reactor #Called only after
wxreactor.install()
from twisted.internet.task import LoopingCall

import clientapp


def opj(path):
    """ Convert paths to the platform-specific separator """
    st = apply(os.path.join, tuple(path.split('/')))
    if path.startswith('/'):
        st = '/' + st
    return st


class APPApp(wx.App):
    def OnInit(self):
        self.frame = APPFrame(None, -1, " APP Login", size=(200, 150))
        self.panel = APPPanel(self.frame,-1)
        client = clientapp.setup_app()
        call = LoopingCall(client.run)
        call.start(.51)
        return True


def main():
    app = APPApp(0)
    reactor.registerWxApp(app)
    try:
        reactor.run()
    except StandardError:
        raise


class APPFrame(wx.Frame):
    def __init__(self, parent, id, title, size=None):
        wx.Frame.__init__(self, parent, id, title,
                          size=size, pos=wx.Point(400, 300))
        icon = self.get_icon()
        self.SetIcon(icon)
        self.Show(True)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        self.Bind(wx.EVT_ICONIZE, self.OnIconify)

    def on_login_click(self, username, password):
        self.Hide()

    def OnCloseWindow(self, event):
        event.Skip()

    def OnIconify(self, event):
        self.Hide()

    def get_image(self):
        img= wx.Image(opj('client.ico'), wx.BITMAP_TYPE_ICO)
        return img

    def get_icon(self):
        img = self.get_image()
        icon = wx.IconFromBitmap(img.ConvertToBitmap() )
        return icon


if __name__ == '__main__':
    main()



More information about the Python-list mailing list