root/trunk/RBPrivate/Prototypes/RBwin32/Widgets.py

Revision 352, 4.4 kB (checked in by sholloway, 6 years ago)

*** empty log message ***

Line 
1 #!/usr/bin/env python
2 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ##~ License
4 ##~
5 ##- The RuneBlade Foundation library is intended to ease some
6 ##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.)
7 ##- applications, while providing the flexibility to modularly change the
8 ##- architecture. Enjoy.
9 ##~
10 ##~ Copyright (C) 2002  TechGame Networks, LLC.
11 ##~
12 ##~ This library is free software; you can redistribute it and/or
13 ##~ modify it under the terms of the BSD style License as found in the
14 ##~ LICENSE file included with this distribution.
15 ##~
16 ##~ TechGame Networks, LLC can be reached at:
17 ##~ 3578 E. Hartsel Drive #211
18 ##~ Colorado Springs, Colorado, USA, 80920
19 ##~
20 ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21
22 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 #~ Imports
24 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25
26 from WindowBase import *
27
28 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #~ Definitions
30 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
32 class Window(WindowBase):
33     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34     #~ Constants / Variables / Etc.
35     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37     windowfactory = RegisteredWindowFactory('Window')
38     pos_default = (0,0)
39     size_default = (win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT)
40     style_default = win32con.WS_CLIPCHILDREN|win32con.WS_OVERLAPPEDWINDOW|win32con.WS_SYSMENU
41
42     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43     #~ Public Methods
44     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45
46     def __init__(self, parent, title, pos=pos_default, size=size_default, style=style_default):
47         WindowBase.__init__(self, parent, title, pos, size, style)
48         Win32guiAspect.InsertAspect(self)
49
50 class Button(WindowBase):
51     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52     #~ Constants / Variables / Etc.
53     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54
55     windowfactory = WindowFactory('BUTTON')
56     pos_default = (0,0)
57     size_default = (win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT)
58     style_default = win32con.WS_CHILD | win32con.WS_TABSTOP | win32con.WS_VISIBLE | win32con.BS_DEFPUSHBUTTON
59
60     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61     #~ Public Methods
62     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63
64     def __init__(self, parent, title, pos=pos_default, size=size_default, style=style_default):
65         WindowBase.__init__(self, parent, title, pos, size, style)
66         Win32guiAspect.InsertAspect(self)
67
68 class Edit(WindowBase):
69     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70     #~ Constants / Variables / Etc.
71     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72
73     windowfactory = WindowFactory('EDIT')
74     pos_default = (0,0)
75     size_default = (win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT)
76     style_default = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | win32con.WS_TABSTOP
77
78     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79     #~ Public Methods
80     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
81
82     def __init__(self, parent, title, pos=pos_default, size=size_default, style=style_default):
83         WindowBase.__init__(self, parent, title, pos, size, style)
84         Win32guiAspect.InsertAspect(self)
85
86 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87 #~ Testing
88 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90 if __name__=='__main__':
91     win32gui.InitCommonControls()
92     t = Window(None, 'Shane\'s Test')
93     b = Button(t, 'A button', pos=(0,0), size=(85,40))
94     b.SetText('New text')
95     e = Edit(t, 'An edit box', pos=(0,40), size=(85,40))
96     e.SetText('Funny')
97
98     print "t", t
99     print "b", b
100     print "e", e
101
102     def OnMessage(hwnd, msg, wparam, lparam):
103         if hwnd != lparam:
104             # Reflect message to lparam
105             return win32gui.SendMessage(lparam, msg, wparam, lparam)
106         else:
107             print hwnd, msg, wparam, lparam
108             return 0
109
110     e.UpdateMessageMap({win32con.WM_COMMAND: OnMessage})
111     t.UpdateMessageMap({win32con.WM_COMMAND: OnMessage})
112
113     def OnButton(hwnd, msg, wparam, lparam):
114         assert hwnd == b.WindowHandle
115         return win32gui.PostQuitMessage(0)
116
117     b.UpdateMessageMap({win32con.WM_COMMAND: OnButton})
118
119     t.Show(win32con.SW_SHOW)
120     t.Refresh()
121
122     win32gui.SetCursor(win32gui.LoadCursor(0,0))
123     win32gui.PumpMessages()
124
Note: See TracBrowser for help on using the browser.