SetFocus problem (Patricio Stegmann)

I created a simpler example you can test.
The SetFocus is being called, but is not focusing the element.
See the example in this url:

http://pastebin.com/f3a4d2ef6

or in the following code:

import wx
from wx import xrc
import thread
import time

g__gui_xrc = ‘’‘<?xml version="1.0" encoding="utf-8"?>


Primary Frame
100,100


2
1
0
0



1
wxEXPAND
5

bt1



1
wxEXPAND
5

bt2





’‘’

def do_some_calculation(i__obj=None):
print ‘calculating something …’
time.sleep(3)
print ‘done, now gotresult’
i__obj()

class GuiApp(wx.App):
def OnInit(self):
self.m__timer = None
self.m__cnt = 0
self.m__buttons = [‘m__button_one’,‘m__button_two’]
self.m__xrc_ressource = xrc.EmptyXmlResource()
self.m__xrc_ressource.LoadFromString(g__gui_xrc)
self.m__capture_frame = self.m__xrc_ressource.LoadFrame(None, ‘mainFrame’)
self.m__main_panel = xrc.XRCCTRL(self.m__capture_frame, ‘mainPanel’)
self.m__button_one = xrc.XRCCTRL(self.m__capture_frame, ‘button_one’)
self.m__button_two = xrc.XRCCTRL(self.m__capture_frame, ‘button_two’)
self.m__capture_frame.Bind(wx.EVT_BUTTON, self.buttonClick, self.m__button_one)
self.m__capture_frame.Bind(wx.EVT_BUTTON, self.buttonClick, self.m__button_two)
self.m__capture_frame.Show()
return True

def buttonClick(self, i__event=None):
    thread.start_new_thread(do_some_calculation, (self.gotResult,))

def gotResult(self):
    print 'gotResult'
    self.m__cnt += 1
    l__button_name = self.m__buttons[self.m__cnt%2]
    print 'giving focus to ',l__button_name
    l__obj = getattr(self, l__button_name)
    l__obj.SetFocus()

if name == ‘main’:
g__app = GuiApp(0)
g__app.MainLoop()

Please let me know if I am doing something wrong. I am using wxPython 2.8.9 and python 2.5.1 on windows xp.

···

From: wxpython-users-request@lists.wxwidgets.org
Subject: wxpython-users Digest, Vol 15, Issue 108
To: wxpython-users@lists.wxwidgets.org
Date: Fri, 22 May 2009 17:20:28 -0700

Send wxpython-users mailing list submissions to
wxpython-users@lists.wxwidgets.org

To subscribe or unsubscribe via the World Wide Web, visit
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
or, via email, send a message with subject or body ‘help’ to
wxpython-users-request@lists.wxwidgets.org

You can reach the person managing the list at
wxpython-users-owner@lists.wxwidgets.org

When replying, please edit your Subject line so it is more specific
than “Re: Contents of wxpython-users digest…”

Today’s Topics:

  1. Re: import wx behaviour on Ubuntu (Robin Dunn)
  2. SetFocus problem (Patricio Stegmann)
  3. Re: import wx behaviour on Ubuntu (Stani)
  4. same mediactrl instance on multiple frame? (Qui Le)

Message: 1
Date: Fri, 22 May 2009 15:14:08 -0700
From: Robin Dunn robin@alldunn.com
Subject: Re: [wxpython-users] import wx behaviour on Ubuntu
To: wxpython-users@lists.wxwidgets.org
Message-ID: 4A1723B0.3000407@alldunn.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Stani wrote:

On Fri, May 22, 2009 at 11:46 PM, Robin Dunn robin@alldunn.com wrote:

Federico Fanton wrote:

Stani wrote:

I would have expected that 2.8 would be the default, but of course
this is debatable. Is this intended behaviour? Is there a way to set
system wide the preference for 2.8 instead of 2.6? Robin, does Ubuntu
implement this differently from upstream wxpython?
This used to work as expected in Ubuntu < 9.04…

Under Jaunty things are different, because every wxpython package adds a
wx-2.[68]-gtk2-unicode.pth to /usr/lib/python2.6/dist-packages, so - if I
understand it correctly - on a “import wx” Python chooses alphabetically,
thus the 2.6 version…

I worked around it by removing those .pth’s and keeping a simple wx.pth
containing “wx-2.8-gtk2-unicode”.

I don’t know if there’s an “official” way of doing it :slight_smile:

You’re supposed to be able to use update-alternatives to switch between
which wx.pth file is installed in [site|dist]-packages, but if Ubuntu has
changed how that file is installed and managed then that feature is probably
broken.
Could you give the full command? I don’t know the argument, eg it is
clearly not:
sudo update-alternatives python-wxgtk

It should be something like:

sudo update-alternatives --set NAME DEST

Where NAME is some link in /etc/alternatives (used to be just wx.pth,
but now I think it is something like wx$PYVER.pth) and DEST is the file
that it should be linked to. My packages install the DEST files in
/usr/lib/wx/python$PYVER/wx$WXVER.pth. I’m not sure if the Ubuntu
packages follow the same pattern any more, or even if they are still
using update-alternatives for that .pth file. (And I don’t have an
untweaked Ubuntu box handy to check.)


Robin Dunn
Software Craftsman
http://wxPython.org


Message: 2
Date: Fri, 22 May 2009 19:22:50 -0300
From: Patricio Stegmann kpoman@hotmail.com
Subject: [wxpython-users] SetFocus problem
To: wxpython users mailing list wxpython-users@lists.wxwidgets.org
Message-ID: BAY141-W26D6CB3980D0AAF4AF1449D9560@phx.gbl
Content-Type: text/plain; charset=“windows-1252”

Hello to all,

I am having a problem on the SetFocus method of an element. =

Basically the wxApp receives an external call for it to focus a particular =
button on the frame’s gui.
However the Focus is not being passed even if the element ‘AcceptsFocus’.

I have here an example: the application is run and a webservice talks to it=
. This webservice allows, via a client, to set the Focus on a particular bu=
tton. However nothing happens.
I am trying to solve this issue and cant figure out what is going on. I alr=
eady tried asking on IRC etc… but nobody helps me !

Please check here the webservice server code:

server.py

import SOAPpy
import wx
from wx import xrc
import thread

g__gui_xrc =3D ‘’'<?xml version=3D"1.0" encoding=3D"utf-8"?>

<object class=3D"wxFrame" name=3D"mainFrame">

Primary Frame 2 1 0 0 1 wxEXPAND 5 bt1 1 wxEXPAND 5 bt2 1 wxEXPAND 5 bt3 1 wxEXPAND 5 bt4 Secondary Frame This is a dynamically created frame. '''

def launch_gui(i__object, i__gui_app):
app =3D i__gui_app(0)
app.m__controller =3D i__object
app.m__controller.m__gui_running =3D app
app.MainLoop()

class GuiApp(wx.App):
def OnInit(self):
print g__gui_xrc
self.m__controller =3D None
self.m__xrc_ressource =3D xrc.EmptyXmlResource()
self.m__xrc_ressource.LoadFromString(g__gui_xrc)
self.m__capture_frame =3D self.m__xrc_ressource.LoadFrame(None, ‘ma=
inFrame’)
self.m__main_panel =3D xrc.XRCCTRL(self.m__capture_frame, ‘mainPane=
l’)
self.m__button_one =3D xrc.XRCCTRL(self.m__capture_frame, ‘button_o=
ne’)
self.m__button_two =3D xrc.XRCCTRL(self.m__capture_frame, ‘button_t=
wo’)
self.m__button_three =3D xrc.XRCCTRL(self.m__capture_frame, ‘button=
three’)
self.m__button_four =3D xrc.XRCCTRL(self.m__capture_frame, 'button
=
four’)
self.m__capture_frame.Bind(wx.EVT_BUTTON, self.buttonClick, self.m_=
_button_one)
self.m__capture_frame.Show()
return True

def buttonClick(self, i__event=3DNone):
self.m__controller.printSomething()

def setElementFocus(self, i__button_name=3DNone):
print 'setting element focus to ', i__button_name
l__obj =3D getattr(self, i__button_name)
self.m__main_panel.SetFocus()
print ‘accepts focus:’,l__obj.AcceptsFocus()
l__obj.SetFocus()
l__obj.SetFocusFromKbd()
l__obj.SetBackgroundColour(wx.Colour(255,255,255))

class GuiController():
def init(self):
self.m__gui_running =3D False
self.m__gui_thread =3D False
self.m__something =3D ‘bla bla bla’

def printSomething(self):
print self.m__something

def showGui(self):
if not self.m__gui_running:
#self.m__gui_running =3D GuiApp(0)
#self.m__gui_thread =3D thread.start_new_thread(launch_gui, (se=
lf, GuiApp))
self.m__gui_thread =3D thread.start_new_thread(launch_gui, (sel=
f, GuiApp))

def killGui(self):
if self.m__gui_running:
print ‘killing gui’

def getStatus(self):
if self.m__gui_running:
return True
else:
return False

def focusItem(self, i__button_name=3DNone):
self.m__gui_running.setElementFocus(i__button_name)

def show_gui():
if g__gui_controller:
g__gui_controller.showGui()
return True
return False

def kill_gui():
if g__gui_controller:
g__gui_controller.killGui()
return True
return False

def get_status():
if g__gui_controller:
return g__gui_controller.getStatus()

def set_text(i__text=3DNone):
if g__gui_controller:
g__gui_controller.m__something =3D i__text

def set_focus(i__button_name=3DNone):
if g__gui_controller:
g__gui_controller.focusItem(i__button_name)

if name =3D=3D ‘main’:
server =3D SOAPpy.SOAPServer((‘’,12321))
g__gui_controller =3D GuiController()
server.registerFunction(show_gui)
server.registerFunction(get_status)
server.registerFunction(set_text)
server.registerFunction(set_focus)
server.serve_forever()

and a simple client:

client.py

import SOAPpy
s =3D SOAPpy.SOAPProxy(‘http://localhost:12321’)
s.show_gui()
s.set_focus(‘m__button_two’)


Windows Live=99: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=3DTXT_TAGLM_WL_t1_allup_explore_012009
-------------- next part --------------
An HTML attachment was scrubbed…
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200905=
22/2de72a35/attachment-0001.htm


Message: 3
Date: Sat, 23 May 2009 01:12:14 +0200
From: Stani spe.stani.be@gmail.com
Subject: Re: [wxpython-users] import wx behaviour on Ubuntu
To: wxpython-users@lists.wxwidgets.org
Message-ID:
2078a7ad0905221612y7caa752cg975babba8e001ddb@mail.gmail.com
Content-Type: text/plain; charset=ISO-8859-1

On Sat, May 23, 2009 at 12:14 AM, Robin Dunn robin@alldunn.com wrote:

It should be something like:

sudo update-alternatives --set NAME DEST

Where NAME is some link in /etc/alternatives (used to be just wx.pth, but
now I think it is something like wx$PYVER.pth) and DEST is the file that it
should be linked to. My packages install the DEST files in
/usr/lib/wx/python$PYVER/wx$WXVER.pth. I’m not sure if the Ubuntu packages
follow the same pattern any more, or even if they are still using
update-alternatives for that .pth file. (And I don’t have an untweaked
Ubuntu box handy to check.)

Well, very strange, if I do:
$ ls /etc/alternatives | grep wx
wx2.5.pth
wx2.6.pth

$ sudo update-alternatives --config wx2.6.pth
[sudo] password for stani:

Er zijn 2 alternatieven die ‘wx2.6.pth’ voorzien.

Selectie Alternatieven

*+ 1 /usr/lib/wx/python/wx2.8.pth
2 /usr/lib/wx/python/wx2.6.pth

It shows that 2.8 is already the default for wx2.6.pth

I noticed a bug, that in sys.path both 2.6 and 2.8 were present, so I
reported it here:
Bug #379573 “sudo update-alternatives does not configure the def...” : Bugs : wxwidgets2.8 package : Ubuntu


Message: 4
Date: Fri, 22 May 2009 17:18:52 -0700
From: Qui Le qle@extron.com
Subject: [wxpython-users] same mediactrl instance on multiple frame?
To: wxpython-users@lists.wxwidgets.org
Message-ID:
7E5F99BC557C0B42B6F3BB7BED701D4E1D5FCEE4@EXCH-USA.extron.com
Content-Type: text/plain; charset=“us-ascii”

Hi,

I have a mediactrl instance that has a video file playing. I want to be
able to show the same video on another frame simutaneously, is it
possible?

Statement Of Confidentiality:

This electronic message transmission, and all attachments, contains information from Extron Electronics which is confidential and privileged. The information is for the exclusive viewing or use of the intended recipient. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic transmission in error, please notify the sender immediately by a “reply to sender only” message and destroy all electronic and hard copies of the communication, including attachments.
-------------- next part --------------
An HTML attachment was scrubbed…
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20090522/97620007/attachment.htm



wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

End of wxpython-users Digest, Vol 15, Issue 108



Windows Live™: Keep your life in sync. Check it out!