Why wxframe isn't raised from a function called with global gtk binder?
Ok, why this simple app dosn't work. I've spent one day investigating this and got nothing.
import wx, os
import gtk
import keybinder
class FrameWithHotKey(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
keybinder.bind("<Ctrl>period", self.toggle_shown)
def toggle_shown(self):
# windowNow id
if self.IsShown():
self.Hide()
else:
开发者_StackOverflow社区 self.Show()
self.Raise()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = FrameWithHotKey(None)
app.MainLoop()
I don't know why, but sometimes (especially when I raise apps by clicking on them on panel) raising dosen't work and I got flash icon instead of raised window.
UPDATE
Ok, i return to the topic and notice these..
- above example works for me.. strange
i isolated strange behaviour which below code shows.. it's something related with wnck lib. So if my app window is deactivated by open new window (left click on window - test1) then raise works perfect, but if other window (replace 'opera' with any of Yours) is activated with wnck(by right click - test2) then actvation fails
import logging import subprocess import time import wnck import wx
logging.basicConfig(level=logging.DEBUG)
class MyFrame(wx.Frame):
def __init__(self, parent, title=''): wx.Frame.__init__(self, parent, title=title) self.Centre() self.Bind(wx.EVT_LEFT_DOWN, self.test1) self.Bind(wx.EVT_RIGHT_DOWN, self.raise_window) def test1(self, evt): logging.debug('losing..') subprocess.Popen(['xterm']) time.sleep(1) self.Raise() logging.debug('lost') def lose_focus_by_wnck(self): screen = wnck.screen_get_default() import gtk while gtk.events_pending(): gtk.main_iteration(False) wins = screen.get_windows() logging.debug('wins: {0}'.format(wins)) for win in wins: app_name = win.get_application().get_name() logging.debug('app: {0}'.format(app_name)) if 'opera' in app_name.lower(): win_id = win.get_xid() break else: win_id = None return win_id def test2(self, evt): logging.debug('losing..') win_id = self.lose_focus_by_wnck() win = wnck.window_get(win_id) TIMESTAMP = 0 win.activate(TIMESTAMP) logging.debug('lost') time.sleep(1) self.Raise() logging.debug('raised')
if name == 'main': app = wx.PySimpleApp(redirect=False) frame = MyFrame(None) frame.Show() app.MainLoop()
Does anybody understand this behaviour instead of very helpful wtf like i feel? :)
What is keybinder? Are you using an AcceleratorTable? See http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/ for more info. I don't think you can mix pyGtk with wxPython.
精彩评论