2013-10-17 115 views
3

使用pyGtk我創建了一個沒有裝飾的窗口。該窗口隱藏在任務欄和所有窗口的頂部。在Linux上它工作正常,但在MS Windows窗口有時它隱藏在其他窗口下,並且在Windows中始終具有「python.exe」任務欄。從MS窗口任務欄隱藏窗口

圖片代表我的問題:

enter image description here

如何隱藏任務欄,從這個 「python.exe」 窗口?

我的代碼:

class Infowindow(gtk.Window): 
''' 
Klasa okienka informacyjnego 
''' 
def __init__(self, json, index, destroy_cb, device): 
    gtk.Window.__init__(self) 
    self.size_x = 260+48 
    self.size_y = 85 
    self.separator_size = 10 
    self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN) 
    self.set_decorated(False) 
    self.set_property('skip-taskbar-hint', True) 
    self.set_opacity(1) 
    self.set_keep_above(True) 
    self.add_events(gtk.gdk.BUTTON_PRESS_MASK) 
    self.connect("enter-notify-event", self.__on_hover) 
    self.connect("leave-notify-event", self.__on_leave) 
    self.connect("button_press_event", self.__on_click) 
    self.set_size_request(self.size_x, self.size_y) 
    color = gtk.gdk.color_parse('#f3f3f3') 
    self.modify_bg(gtk.STATE_NORMAL, color) 

    self.expanded = False 
    self.index = index 
    self.destroy_cb = destroy_cb 
    self.json = json['data'] 
    self.system_info = False if 'system' not in self.json or not self.json['system'] else True 
    self.device = device 
    f = gtk.Frame() 
    self.move_window(index) #move window to specified place 
    self.box_area = gtk.VBox() 
    self.box_area.set_spacing(10) 
    f.add(self.box_area) 
    self.add(f) 
    self.show_all() 

回答

3

你有兩個選擇,從任務欄刪除一個窗口:

  1. 添加WS_EX_TOOLWINDOW擴展窗口風格。但是這有其他後果,我不能說他們是否認真。
  2. 給窗口一個不可見的所有者。這允許你自由地使用你想要的任何窗口樣式和擴展樣式,但確實涉及更多的工作。

很自然,你的窗戶將在其他窗戶下方。這就是窗戶的工作原理。如果您想讓窗口顯示在頂部,請使用HWND_TOPMOST進行顯示。

我不知道這是如何(或不)在PyGtk下實現的。我剛給你的Win32答案!

+0

如果不會有更多的答案我會嘗試在win32gui下創建這個窗口。謝謝。 – DrafFter

5

再次感謝David Heffernan。完美的作品!

適合想要python完整解決方案的人。

  • 名稱您windowin例如典型的方式: 'alamakota'
  • 使用find_window( 'alamakota'),
  • 按照給定的處理器使用hide_from_taskbar(處理器)
  • 最後使用set_topmost(處理器)

窗口對任務欄是隱藏的,它在頂部。

我知道這不是一個好的代碼,但在Windows XP及更高版本上運行良好。

import ctypes 
import win32gui 
import win32api 
from win32con import SWP_NOMOVE 
from win32con import SWP_NOSIZE 
from win32con import SW_HIDE 
from win32con import SW_SHOW 
from win32con import HWND_TOPMOST 
from win32con import GWL_EXSTYLE 
from win32con import WS_EX_TOOLWINDOW 

@staticmethod 
def find_window(name): 
    try: 
     return win32gui.FindWindow(None, name) 
    except win32gui.error: 
     print("Error while finding the window") 
     return None 

@staticmethod 
def hide_from_taskbar(hw): 
    try: 
     win32gui.ShowWindow(hw, SW_HIDE) 
     win32gui.SetWindowLong(hw, GWL_EXSTYLE,win32gui.GetWindowLong(hw, GWL_EXSTYLE)| WS_EX_TOOLWINDOW); 
     win32gui.ShowWindow(hw, SW_SHOW); 
    except win32gui.error: 
     print("Error while hiding the window") 
     return None 

@staticmethod 
def set_topmost(hw): 
    try: 
      win32gui.SetWindowPos(hw, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE) 
    except win32gui.error: 
     print("Error while move window on top") 
+0

'hide_from_taskbar'似乎不適用於Win7 x64。 MSDN說應該使用'SetWindowLongPtrW'來代替。 –

+0

使用'SetWindowLongPtrW'時,它在設置'SW_HIDE'時從任務欄中隱藏,但它會再次出現在任務欄中並帶有'SW_SHOW'! –

+0

我可以得到它的工作。這是我的錯字。感謝您的詳細代碼。 –