2011-09-08 126 views
1

我正在嘗試重新構建桌面的「突出顯示選擇」功能,以便我可以在自己的應用程序中使用它。當我說「突出顯示選擇」時,我的意思是如果在桌面上單擊並拖動(所有主流操作系統都是原生的),則顯示選擇框。突出顯示Python中的選擇框

我一直在努力嘗試重新創建它,並且根本找不到方法。我已經嘗試過PyGTK,Xlib for python和其他一些奇怪的黑客。所有這些都有他們自己的問題,不會讓我前進。

我一般不要求直線上升的示例代碼,而不提供某種形式的出發點,但在這個項目中,我甚至不知道從哪裏開始。你會如何做到這一點?

這裏的要求:

  • 必須繪製根窗口(或「出現」是根透明層)
  • 必須返回選擇的座標上(X,Y,高度寬)

更新:忘記一些細節。

  • 我使用Ubuntu 10.10
  • 我有雙顯示器(不過,我不認爲應該的問題)
  • 我不介意下載任何必要的額外的庫
+0

你可以用pygtk處理onclick/release處理程序嗎?你能在屏幕上畫一個盒子嗎?如果是這樣,你還需要什麼? –

+0

問題最難的部分是在根窗口上繪製一個框 - 而不是在子窗口/小部件上。我沒有使用pygtk在根窗口上繪製任何東西。 – jwegner

回答

0

我不知道這是你在找什麼,但是如果你在你的模塊中創建了另一個窗口,並且當你釋放拖拽時讓你的代碼顯示它呢?你可以獲取光標的當前位置,並在那裏繪製窗口。

This should help you get the mouse position on the root window.

所以,你的代碼可能看起來有點像這樣(這是未經測試的代碼!)我只顯示了什麼走了進去__ __初始化的相關部分。

def __init__(self): 

    ... 
    #Some of your code here. 
    ... 

    win = gtk.Window(gtk.WINDOW_TOPLEVEL) 

    #Note that I am creating a popup window separately. 
    popwin = gtk.Window(gtk.WINDOW_POPUP) 

    #I am setting "decorated" to False, so it will have no titlebar or window controls. 
    #Be sure to compensate for this by having another means of closing it. 
    popwin.set_decorated(False) 

    def ShowPopup(): 
     #You may need to put additional arguments in above if this is to be an event. 
     #For sake of example, I'm leaving this open ended. 

     #Get the cursor position.    
     rootwin = widget.get_screen().get_root_window() 
     curx, cury, mods = rootwin.get_pointer() 

     #Set the popup window position. 
     popwin.move(curx, cury) 
     popwin.show() 

    def HidePopup(): 
     #This is just an example for how to hide the popup when you're done with it. 
     popwin.hide() 

    ... 
    #More of your code here. 
    ... 

    #Of course, here is the code showing your program's main window automatically. 
    win.show() 

一個非常簡單的方法,但它應該給出你想要的外觀。