为什么未从全局gtk绑定程序调用的函数中引发wxframe? [英] Why wxframe isn't raised from a function called with global gtk binder?

查看:110
本文介绍了为什么未从全局gtk绑定程序调用的函数中引发wxframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,为什么这个简单的应用程序不起作用. 我花了一天时间对此进行调查,但一无所获.

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:
            self.Show()
            self.Raise()


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = FrameWithHotKey(None)
    app.MainLoop()

我不知道为什么,但是有时候(尤其是当我通过单击面板上的应用来启动应用程序时),提高无法正常工作,并且我得到了Flash图标,而不是升高的窗口.

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.

更新

好,我回到主题并注意这些..

Ok, i return to the topic and notice these..

  1. 上面的例子对我有用..奇怪
  2. 我隔离了下面的代码所示的奇怪行为..这与wnck lib有关.因此,如果通过打开新窗口(在窗口上单击鼠标左键-test1)停用了我的应用程序窗口,那么raise效果很好,但是如果其他窗口(用您的任何一个替换"opera")用wnck(通过右键单击-test2)激活,则动作失败

  1. above example works for me.. strange
  2. 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

导入日志 导入子流程 导入时间 导入wnck 导入wx

import logging import subprocess import time import wnck import wx

logging.basicConfig(level = logging.DEBUG)

logging.basicConfig(level=logging.DEBUG)

MyFrame类(wx.Frame):

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')

如果名称 =='主要": 应用= wx.PySimpleApp(redirect = False) 框架= MyFrame(无) frame.Show() app.MainLoop()

if name == 'main': app = wx.PySimpleApp(redirect=False) frame = MyFrame(None) frame.Show() app.MainLoop()

有人能理解这种行为,而不是像我感觉的那样非常有用的wtf吗? :)

Does anybody understand this behaviour instead of very helpful wtf like i feel? :)

推荐答案

什么是keybinder?您正在使用AcceleratorTable吗?参见 http://www.blog.pythonlibrary.org/2010/12/02/wxpython-keyboard-shortcuts-accelerators/了解更多信息.我认为您不能将pyGtk与wxPython混合使用.

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.

这篇关于为什么未从全局gtk绑定程序调用的函数中引发wxframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆