Question

Using pyGtk I created a window without decoration. The Window is hidden from task bar and top of all windows. On linux it works fine, but on MS Windows window sometimes it hides under some other window and always has "python.exe" the taskbar in windows.

Image representing my problem:

enter image description here

How can I hide this "python.exe" window from taskbar?

My code:

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()
Was it helpful?

Solution 2

You have two options to remove a window from the taskbar:

  1. Add the WS_EX_TOOLWINDOW extended window style. But this has other consequences and I cannot say whether or not they are serious.
  2. Give the window an owner that is not visible. This allows you freedom to use whatever window styles and extended styles you wish, but does involve more work.

It's natural that your window will go beneath other windows. That's how windows works. If you want to make your window appear on top, show it with HWND_TOPMOST.

I've no idea how any of this is (or is not) implemented under PyGtk. I've just given you the Win32 answer!

OTHER TIPS

Again thanks David Heffernan. Works perfect!

For people who want a full solution in python.

  • Name your windowin a characteristic way for example: 'alamakota'
  • Use find_window('alamakota'),
  • With given handler use hide_from_taskbar(handler)
  • Last use set_topmost(handler)

Window is hidden from taskbar and it's alwoays on top.

I know it's not a beatyfull code, but works fine on windows XP and above.

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

Win32 solution provided in the other answer is not very easy and it does not play well with the GtkWindow::show method. A simple solution now in Gtk3 is:

win->set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_UTILITY); //This works
win->set_skip_taskbar_hint(); //This does not guarantee to work
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top