home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2515 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.5 KB  |  110 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from win32api import *
  5. from win32gui import *
  6. import win32con
  7. import sys
  8. import os
  9.  
  10. class MainWindow:
  11.     
  12.     def __init__(self):
  13.         msg_TaskbarRestart = RegisterWindowMessage('TaskbarCreated')
  14.         message_map = {
  15.             msg_TaskbarRestart: self.OnRestart,
  16.             win32con.WM_DESTROY: self.OnDestroy,
  17.             win32con.WM_COMMAND: self.OnCommand,
  18.             win32con.WM_USER + 20: self.OnTaskbarNotify }
  19.         wc = WNDCLASS()
  20.         hinst = wc.hInstance = GetModuleHandle(None)
  21.         wc.lpszClassName = 'PythonTaskbarDemo'
  22.         wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
  23.         wc.hCursor = LoadCursor(0, win32con.IDC_ARROW)
  24.         wc.hbrBackground = win32con.COLOR_WINDOW
  25.         wc.lpfnWndProc = message_map
  26.         classAtom = RegisterClass(wc)
  27.         style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
  28.         self.hwnd = CreateWindow(classAtom, 'Taskbar Demo', style, 0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None)
  29.         UpdateWindow(self.hwnd)
  30.         self._DoCreateIcons()
  31.  
  32.     
  33.     def _DoCreateIcons(self):
  34.         hinst = GetModuleHandle(None)
  35.         iconPathName = os.path.abspath(os.path.join(os.path.split(sys.executable)[0], 'pyc.ico'))
  36.         if not os.path.isfile(iconPathName):
  37.             iconPathName = os.path.abspath(os.path.join(os.path.split(sys.executable)[0], 'DLLs', 'pyc.ico'))
  38.         
  39.         if not os.path.isfile(iconPathName):
  40.             iconPathName = os.path.abspath(os.path.join(os.path.split(sys.executable)[0], '..\\PC\\pyc.ico'))
  41.         
  42.         if os.path.isfile(iconPathName):
  43.             icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
  44.             hicon = LoadImage(hinst, iconPathName, win32con.IMAGE_ICON, 0, 0, icon_flags)
  45.         else:
  46.             print "Can't find a Python icon file - using default"
  47.             hicon = LoadIcon(0, win32con.IDI_APPLICATION)
  48.         flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
  49.         nid = (self.hwnd, 0, flags, win32con.WM_USER + 20, hicon, 'Python Demo')
  50.         
  51.         try:
  52.             Shell_NotifyIcon(NIM_ADD, nid)
  53.         except error:
  54.             print 'Failed to add the taskbar icon - is explorer running?'
  55.  
  56.  
  57.     
  58.     def OnRestart(self, hwnd, msg, wparam, lparam):
  59.         self._DoCreateIcons()
  60.  
  61.     
  62.     def OnDestroy(self, hwnd, msg, wparam, lparam):
  63.         nid = (self.hwnd, 0)
  64.         Shell_NotifyIcon(NIM_DELETE, nid)
  65.         PostQuitMessage(0)
  66.  
  67.     
  68.     def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
  69.         if lparam == win32con.WM_LBUTTONUP:
  70.             print 'You clicked me.'
  71.         elif lparam == win32con.WM_LBUTTONDBLCLK:
  72.             print 'You double-clicked me - goodbye'
  73.             DestroyWindow(self.hwnd)
  74.         elif lparam == win32con.WM_RBUTTONUP:
  75.             print 'You right clicked me.'
  76.             menu = CreatePopupMenu()
  77.             AppendMenu(menu, win32con.MF_STRING, 1023, 'Display Dialog')
  78.             AppendMenu(menu, win32con.MF_STRING, 1024, 'Say Hello')
  79.             AppendMenu(menu, win32con.MF_STRING, 1025, 'Exit program')
  80.             pos = GetCursorPos()
  81.             SetForegroundWindow(self.hwnd)
  82.             TrackPopupMenu(menu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
  83.             PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
  84.         
  85.         return 1
  86.  
  87.     
  88.     def OnCommand(self, hwnd, msg, wparam, lparam):
  89.         id = LOWORD(wparam)
  90.         if id == 1023:
  91.             import win32gui_dialog
  92.             win32gui_dialog.DemoModal()
  93.         elif id == 1024:
  94.             print 'Hello'
  95.         elif id == 1025:
  96.             print 'Goodbye'
  97.             DestroyWindow(self.hwnd)
  98.         else:
  99.             print 'Unknown command -', id
  100.  
  101.  
  102.  
  103. def main():
  104.     w = MainWindow()
  105.     PumpMessages()
  106.  
  107. if __name__ == '__main__':
  108.     main()
  109.  
  110.