New to Python, WxPython etc, etc

R

rodmc

I am totally new to Python and WxPython and need to write an
application which can open up an external windows from a plug-in within
GAIM (using pyGAIM). I have managed to hack some code together from
what little I have covered so far, however GAIM refuses to open until I
have closed the extra window. I appreciate this is probably a simple
point but I would be grateful for any advice people can offer on how I
can make them both appear so that people can interact with either GAIM
and/or the contents of the window. I am using Python 2.3.5, and GAIM 2
(beta).

I have attached the hacked code below which is based on a merging some
samples from WxPython and pyGaim. I have tried moving the bit below to
within def plug_in load but to no avail.

"app = MyApp(0)
app.MainLoop()"

Thanks in advance,

Rod


----

import _gaim
import wx

from wxPython.wx import *

ID_ABOUT = 101
ID_EXIT = 102

class MyFrame(wxFrame):
def __init__(self, parent, ID, title):
wxFrame.__init__(self, parent, ID, title,
wxDefaultPosition, wxSize(200, 150))

self.CreateStatusBar()
self.SetStatusText("This is the statusbar")
menu = wxMenu()
menu.Append(ID_ABOUT, "&About",
"More information about this program")
menu.AppendSeparator()
menu.Append(ID_EXIT, "E&xit", "Terminate the program")
menuBar = wxMenuBar()
menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)

EVT_MENU(self, ID_ABOUT, self.OnAbout)
EVT_MENU(self, ID_EXIT, self.TimeToQuit)

def OnAbout(self, event):
dlg = wxMessageDialog(self, "This sample program shows off\n"
"frames, menus, statusbars, and this\n"
"message dialog.",
"About Me", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()


def TimeToQuit(self, event):
self.Close(true)



class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "Hello from wxPython")
frame.Show(true)
self.SetTopWindow(frame)
return true


PLUGIN_INFO = {
'python_api_version' : 2,
'name' : "A Simple Test Plug-in",
'version' : "0.3",
'summary' : "This simply does nothing",
'description' : "Cheese",
'author' : "(e-mail address removed)",
'url' : "http://www.xxx.com/",
'load' : "plugin_load",
'unload' : "plugin_unload"
}


def timeout0(anObject):
print 'py:timeout0',anObject
return False

def timeout1(anObject):
print 'py:timeout1',anObject
## return True
return False

def signed_on_cb1(data,account,conv,msgText):
print 'p2:signed_on_cb1'
print 'Data',data
print 'account',account
print 'conversation',conv
print 'msgText',msgText
print 'account.gc',account.gc

blist = gaim.gaim_get_blist()
print blist.root

print conv.name,conv.title,conv.history

buddy = gaim.gaim_find_buddy(account,conv.name)
print buddy,buddy.name,buddy.alias

group = gaim.gaim_find_buddys_group(buddy)
print group,group.name,group.totalsize

return {'r':True,'a3':'this is my text:'+msgText}

def menu_item_activate_cb(node,data):
pass

def blist_node_extended_menu_cb(data,node,menu):
print 'node',node
print 'menu',menu

## if (!GAIM_BLIST_NODE_IS_BUDDY(node))
## return;

## buddy = (GaimBuddy *)node;
## act = gaim.gaim_blist_node_action_new("Send message",
## menu_item_activate_cb,None)
## print act
## *menu = g_list_append(*menu,act);

def plugin_load(plugin):

print 'py:plugin_load'
accs = gaim.gaim_accounts_get_all()
print accs
for account in accs:
print account
if account:
print account.username,account.alias
print 'New:',gaim._GaimAccount()
gaim.gaim_python_timeout_add(plugin,2000,timeout0,"this is timeout
0")
gaim.gaim_python_timeout_add(plugin,1000,timeout1,"this is timeout
1")

handle = gaim.gaim_conversations_get_handle()
gaim.gaim_python_signal_connect(plugin,handle,"writing-im-msg",
signed_on_cb1,"abc")


gaim.gaim_python_signal_connect(plugin,gaim.gaim_blist_get_handle(),
"blist-node-extended-menu",
blist_node_extended_menu_cb,None);
print 'py:after plugin load'

def plugin_unload(plugin):
print 'py:plugin_unload'

app = MyApp(0)
app.MainLoop()
 
H

Heiko Wundram

rodmc said:
I am totally new to Python and WxPython and need to write an
application which can open up an external windows from a plug-in within
GAIM (using pyGAIM).

<snip>

"app = MyApp(0)
app.MainLoop()"

You're trying to merge to event loops. GAIM uses the GTK2+ based loop,
whereas WxPython uses its own event loop. As you're starting the WxPython
main loop to service your program, no GUI events (such as displaying a
window) can get processed for GAIM. This is exactly what you're seeing.

I don't know how to patch into GAIM's event loop, but you should look for
some place where integration of pygtk and pygaim is discussed. wxPython
won't get you very far here.

--- Heiko.
 
M

Max Erickson

@g44g2000cwa.googlegroups.com:

import _gaim
import wx

from wxPython.wx import *

ID_ABOUT = 101
ID_EXIT = 102

class MyFrame(wxFrame):
def __init__(self, parent, ID, title):

I don't have an answer to your question, but as an aside, you should
think about using the wx namespace if you move forward with wxPython.
Basically, you would just eliminate 'from wxPython.wx import *' as you
are already importing wx. Then, instead of referring to wxFrame, you
would refer to wx.Frame.

See:
http://www.wxpython.org/MigrationGuide.html#the-wx-namespace

for more information about this.

Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top