2
# Purpose: Script to create tool bitmaps by screen capture
3
# Author: Roman Rolinsky <rolinsky@femagsoft.com>
10
import wx.grid as grid
12
def WTF(win, filename):
13
"""WindowToFile: save part of the screen as 'filename'."""
14
if wx.Platform == '__WXMAC__':
15
# Blit does not write color
16
os.system('screencapture scr.png')
17
screen = wx.Bitmap('scr.png')
19
bitmap = screen.GetSubBitmap(rect)
21
context = wx.ScreenDC()
22
memory = wx.MemoryDC()
23
x,y = win.GetPosition()
25
x0,y0 = win.ClientToScreen((0,0))
28
bitmap = wx.EmptyBitmap(w, h, -1)
29
memory.SelectObject(bitmap)
30
memory.Blit(0, 0, w, h, context, x, y)
33
print 'Saving bitmap ', filename
34
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG)
38
def WTFC(win, filename, obj):
39
"""WindowToFileClient"""
40
if wx.Platform == '__WXMAC__':
41
# Blit does not write color
42
os.system('screencapture scr.png')
43
screen = wx.Bitmap('scr.png')
44
rect = win.GetClientRect()
45
rect.Offset(win.ClientToScreen((0, 0)))
46
bitmap = screen.GetSubBitmap(rect)
48
context = wx.ScreenDC()
49
memory = wx.MemoryDC()
50
x,y = win.GetPosition()
52
x0,y0 = win.ClientToScreen((0,0))
56
bitmap = wx.EmptyBitmap(128, h, -1)
57
memory.SelectObject(bitmap)
58
memory.Blit(0, 0, 128, h, context, x0, y + 24)
61
print 'Saving bitmap ', filename
62
bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG)
66
def WCTF(win, dirname):
67
"""WindowChildrenToFile: save all child windows."""
68
if wx.Platform == '__WXMAC__':
69
# Blit does not write color
70
os.system('screencapture scr.png')
71
screen = wx.Bitmap('scr.png')
72
rect = win.GetClientRect()
73
rect.Offset(win.ClientToScreen((0, 0)))
74
bitmap = screen.GetSubBitmap(rect)
76
context = wx.ClientDC(win)
77
memory = wx.MemoryDC()
78
x,y = win.GetPosition()
80
bitmap = wx.EmptyBitmap(w, h, -1)
81
memory.SelectObject(bitmap)
82
memory.Blit(0, 0, w, h, context, 0, 0)
85
for w in win.GetChildren():
86
klass = w.GetClassName()
87
if w.GetName() != '-1': # replace by the true name
89
print 'Saving bitmap for', klass
90
filename = os.path.join(dirname, klass + '.png')
91
sub = bitmap.GetSubBitmap(w.GetRect())
92
sub.SaveFile(filename, wx.BITMAP_TYPE_PNG)
96
def create_panels(main_frame):
97
frame = res.LoadFrame(main_frame, 'FRAME_Panels')
99
print 'error loading FRAME_Panels'
102
for w in frame.GetChildren():
103
klass = w.GetClassName()
104
if klass == 'wxTreeCtrl':
105
r = w.AddRoot('Items')
106
w.AppendItem(r, 'Item 1')
107
w.AppendItem(r, 'Item 2')
109
elif klass == 'wxListCtrl':
110
w.InsertStringItem(0, "Item 1")
111
w.InsertStringItem(1, "Item 2")
112
w.InsertStringItem(2, "Item 3")
113
w.InsertStringItem(3, "Item 4")
114
w.InsertStringItem(4, "Item 5")
115
w.InsertStringItem(5, "Item 6")
116
w.InsertStringItem(6, "Item 7")
117
w.InsertStringItem(7, "Item 8")
118
elif klass == 'wxGrid':
122
elif klass == 'wxScrolledWindow':
123
# w.SetVirtualSize((20,20))
124
sizer = wx.BoxSizer()
125
p = wx.Panel(w, size=(100,100), style=wx.SUNKEN_BORDER)
126
# w.SetScrollbars(1,1,10,10,1,1)
127
p.SetBackgroundColour(wx.WHITE)
134
def create_controls(main_frame):
135
frame = res.LoadFrame(main_frame, 'FRAME_Controls')
137
print 'error loading FRAME_Controls'
144
if evt.GetId() == xrc.XRCID('snap_panels'):
145
WCTF(app.frame_panels, 'bitmaps')
146
elif evt.GetId() == xrc.XRCID('snap_controls'):
147
WCTF(app.frame_controls, 'bitmaps')
148
elif evt.GetId() == xrc.XRCID('snap_frame'):
149
WTF(app.frame_frame, 'bitmaps/wxFrame.png')
150
elif evt.GetId() == xrc.XRCID('snap_dialog'):
151
WTF(app.frame_dialog, 'bitmaps/wxDialog.png')
152
elif evt.GetId() == xrc.XRCID('snap_propsheetdialog'):
153
print 'sleeping 1 sec'
155
WTF(app.frame_propsheetdialog, 'bitmaps/wxPropertySheetDialog.png')
156
elif evt.GetId() == xrc.XRCID('snap_menubar'):
157
WTFC(app.frame_menubar, 'bitmaps/wxMenuBar.png', app.frame_menubar.GetMenuBar())
158
elif evt.GetId() == xrc.XRCID('snap_menu'):
159
WTFC(app.frame_menubar, 'bitmaps/wxMenuBar.png')
160
elif evt.GetId() == xrc.XRCID('snap_toolbar'):
161
WTFC(app.frame_menubar, 'bitmaps/wxToolBar.png', app.frame_menubar.GetToolBar())
163
if __name__ == '__main__':
165
resFile = sys.argv[1]
167
print 'usage: python maketools.py xrc_file'
170
app = wx.PySimpleApp(useBestVisual=False)
171
res = xrc.EmptyXmlResource()
175
main_frame = res.LoadFrame(None, 'main_frame')
177
app.main_frame = main_frame
179
app.frame_panels = create_panels(main_frame)
180
app.frame_panels.SetPosition((0,100))
181
app.frame_controls = create_controls(main_frame)
182
app.frame_panels.SetPosition((350,100))
183
app.frame_frame = wx.Frame(main_frame, -1, '', (0,300), (128, 100))
184
app.frame_frame.Show()
185
app.frame_dialog = wx.Dialog(main_frame, -1, '', (140,300), (128, 100))
186
app.frame_dialog.SetSize((128,100))
187
app.frame_dialog.Show()
188
app.frame_propsheetdialog = res.LoadObject(main_frame, 'PROPSHEETDIALOG', 'wxPropertySheetDialog')
189
app.frame_propsheetdialog.Show()
190
app.frame_menubar = res.LoadFrame(main_frame, 'FRAME_MenuBar')
191
app.frame_menubar.Show()
192
app.frame_menubar = res.LoadFrame(main_frame, 'FRAME_ToolBar')
193
app.frame_menubar.Show()
195
if not os.path.exists('bitmaps'): os.mkdir('bitmaps')
197
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_panels'))
198
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_controls'))
199
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_frame'))
200
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_dialog'))
201
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_propsheetdialog'))
202
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_menubar'))
203
main_frame.Bind(wx.EVT_MENU, snap, id=xrc.XRCID('snap_toolbar'))
204
main_frame.Bind(wx.EVT_MENU, lambda evt: main_frame.Close(), id=wx.ID_EXIT)
205
main_frame.SetStatusText('status')