Skip to content

Instantly share code, notes, and snippets.

@ethanhs
Created March 12, 2015 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanhs/85b00104c9bb52b78add to your computer and use it in GitHub Desktop.
Save ethanhs/85b00104c9bb52b78add to your computer and use it in GitHub Desktop.
Windows only GPL licensed example of a taskbar with a start button (see http://www.deviantart.com/art/Windows-8-Metro-Orbs-320240575 for button) NOTE:not currently working part of https://github.com/IronManMark20/PyExplorer
import sys
import ctypes
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PIL import Image
from PIL.ImageQt import ImageQt
import pyautogui as pg
import platform
class Main(QWidget):
def __init__(self):
QWidget.__init__(self)
'''setup code'''
self.x,self.y=pg.size()
self.HideTaskbar('hide')
with open("config.txt") as f:
self.config=f.readlines()
'''GUI CODE'''
#no need for ugly frames
self.setWindowFlags(Qt.Tool | Qt.FramelessWindowHint)
self.PlaceTaskbar()
self.start=StartButton()
self.start.setFixedSize(54,54)
self.startlayout =QHBoxLayout(self)
self.startlayout.addWidget(self.start)
self.startlayout.setAlignment(Qt.AlignLeft)
self.startlayout.setContentsMargins(0,0,0,0)
self.setLayout(self.startlayout)
def PlaceTaskbar(self):
if self.config[0]== "0\n":
self.move(0,self.y-44)
self.resize(self.x,44)
def HideTaskbar(self,command):
from ctypes import wintypes
'''for start orb'''
FindWinEx = ctypes.windll.user32.FindWindowExA
FindWinEx.restype = wintypes.HWND
FindWinEx.argtypes = [
wintypes.HWND,
wintypes.HWND,
wintypes.LPCSTR,
wintypes.LPCSTR,
]
'''for taskbar'''
FindWinA=ctypes.windll.user32.FindWindowA
FindWinA.restype=wintypes.HWND
SetPos=ctypes.windll.user32.SetWindowPos
SetPos.restype = wintypes.BOOL
SetPos.argtypes = [
wintypes.HWND,
wintypes.HWND,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int,
ctypes.c_uint,
]
tbhandle=FindWinA(b"Shell_traywnd",b"")
if command=="hide":
SetPos(tbhandle,0,0,0,0,0, 0x80)
elif command=="on":
SetPos(tbhandle,0,0,0,0,0, 0x40)
else:
self.dialog=QErrorMessage(self)
self.dialog.showMessage(QString("ERROR: invalid command (sorry)."))
startorb=wintypes.LPCSTR(0xc017)
noStart=FindWinEx(None, None, startorb, None)
if command=="hide":
SetPos(noStart,0,0,0,0,0, 0x80)
if command=="on":
SetPos(noStart,0,0,0,0,0,0x40)
def exit(self):
self.HideTaskbar("on")
sys.exit(prgrm.exec_())
class StartButton(QPushButton):
def __init__(self,parent=None):
super(StartButton,self).__init__(parent)
self.setMouseTracking(True)
self.start_state=0
with open("config.txt") as f:
self.config=f.readlines()
self.start_icon=Image.open(self.config[1][:-1])
self.start_icon.normal=self.start_icon.crop((0,0,54,54))
self.start_icon.hover=self.start_icon.crop((0,54,54,108))
self.start_icon.press=self.start_icon.crop((0,108,54,162))
self.setIcon(QIcon(ImageQt(self.start_icon.normal)))
self.pressed.connect(self.OnPress)
def OnPress(self):
self.setIcon(QIcon(self.start_icon.press))
self.startMenuTrigger()
def startMenuTrigger(self):
if self.start_state==0 and platform.release()!="8":
pg.hotkey('win')
self.start_state=1
elif self.start_state==1and platform.release()!="8":
pg.hotkey('Esc')
self.start_state=0
else:
pg.hotkey('win')
def eventFilter(self, object, event):
if event.type()==event.HoverEvent:
self.setIcon(QIcon(ImageQt(self.start_icon.hover)))
if event.type()==event.Leave:
self.setIcon(QIcon(ImageQt(self.start_icon.normal)))
if __name__=="__main__":
prgrm=QApplication(sys.argv)
app=Main()
app.show()
#De-comment and run the program again to get your Taskbar back.
#app.HideTaskbar('on')
sys.exit(prgrm.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment