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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32gui
  5. import win32api
  6. import win32con
  7. import win32rcparser
  8. import commctrl
  9. import sys
  10. import os
  11.  
  12. try:
  13.     __file__
  14. except NameError:
  15.     __file__ = sys.argv[0]
  16.  
  17. this_dir = os.path.abspath(os.path.dirname(__file__))
  18. g_rcname = os.path.abspath(os.path.join(this_dir, '..', 'test', 'win32rcparser', 'test.rc'))
  19. if not os.path.isfile(g_rcname):
  20.     raise RuntimeError, "Can't locate test.rc (should be at '%s')" % (g_rcname,)
  21. os.path.isfile(g_rcname)
  22.  
  23. class DemoWindow:
  24.     
  25.     def __init__(self, dlg_template):
  26.         self.dlg_template = dlg_template
  27.  
  28.     
  29.     def CreateWindow(self):
  30.         self._DoCreate(win32gui.CreateDialogIndirect)
  31.  
  32.     
  33.     def DoModal(self):
  34.         return self._DoCreate(win32gui.DialogBoxIndirect)
  35.  
  36.     
  37.     def _DoCreate(self, fn):
  38.         message_map = {
  39.             win32con.WM_INITDIALOG: self.OnInitDialog,
  40.             win32con.WM_CLOSE: self.OnClose,
  41.             win32con.WM_DESTROY: self.OnDestroy,
  42.             win32con.WM_COMMAND: self.OnCommand }
  43.         return fn(0, self.dlg_template, 0, message_map)
  44.  
  45.     
  46.     def OnInitDialog(self, hwnd, msg, wparam, lparam):
  47.         self.hwnd = hwnd
  48.         desktop = win32gui.GetDesktopWindow()
  49.         (l, t, r, b) = win32gui.GetWindowRect(self.hwnd)
  50.         (dt_l, dt_t, dt_r, dt_b) = win32gui.GetWindowRect(desktop)
  51.         (centre_x, centre_y) = win32gui.ClientToScreen(desktop, ((dt_r - dt_l) / 2, (dt_b - dt_t) / 2))
  52.         win32gui.MoveWindow(hwnd, centre_x - r / 2, centre_y - b / 2, r - l, b - t, 0)
  53.  
  54.     
  55.     def OnCommand(self, hwnd, msg, wparam, lparam):
  56.         id = win32api.LOWORD(wparam)
  57.         if id in [
  58.             win32con.IDOK,
  59.             win32con.IDCANCEL]:
  60.             win32gui.EndDialog(hwnd, id)
  61.         
  62.  
  63.     
  64.     def OnClose(self, hwnd, msg, wparam, lparam):
  65.         win32gui.EndDialog(hwnd, 0)
  66.  
  67.     
  68.     def OnDestroy(self, hwnd, msg, wparam, lparam):
  69.         pass
  70.  
  71.  
  72.  
  73. def DemoModal():
  74.     resources = win32rcparser.Parse(g_rcname)
  75.     for id, ddef in resources.dialogs.items():
  76.         print 'Displaying dialog', id
  77.         w = DemoWindow(ddef)
  78.         w.DoModal()
  79.     
  80.  
  81. if __name__ == '__main__':
  82.     flags = 0
  83.     for flag in 'ICC_DATE_CLASSES ICC_ANIMATE_CLASS ICC_ANIMATE_CLASS \n                   ICC_BAR_CLASSES ICC_COOL_CLASSES ICC_DATE_CLASSES\n                   ICC_HOTKEY_CLASS ICC_INTERNET_CLASSES ICC_LISTVIEW_CLASSES\n                   ICC_PAGESCROLLER_CLASS ICC_PROGRESS_CLASS ICC_TAB_CLASSES\n                   ICC_TREEVIEW_CLASSES ICC_UPDOWN_CLASS ICC_USEREX_CLASSES\n                   ICC_WIN95_CLASSES  '.split():
  84.         flags |= getattr(commctrl, flag)
  85.     
  86.     win32gui.InitCommonControlsEx(flags)
  87.     win32api.LoadLibrary('riched20.dll')
  88.     DemoModal()
  89.  
  90.