~ubuntu-branches/ubuntu/raring/wxwidgets2.8/raring

« back to all changes in this revision

Viewing changes to .pc/xrced_bitmaps.dpatch/wxPython/wx/tools/XRCed/misc/maketools.py

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2012-05-27 17:32:13 UTC
  • mfrom: (5.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20120527173213-e0dcxtnrefaa1if5
Tags: 2.8.12.1-9ubuntu1
* Merge from Debian unstable. Remaining changes:
  - debian/rules: re-enable mediactrl. This allows libwx_gtk2u_media-2.8 to be
    built, as this is required by some applications (LP: #632984)
  - debian/control:
    - Build-dep on libxt-dev, libgstreamer-plugins-base0.10-dev,
      and libgconf2-dev for mediactrl.
    - Add conflict on python-wxgtk2.8 (<< 2.8.12.1-6ubuntu1~) to
      python-wxversion to guarantee upgrade ordering when moving from
      pycentral to dh_python2.
  - Patches
    + fix-bashism-in-example.patch
* Backport patch to fix calling SetMenuBar() twice causes the menubar to not
  resize correctly in GTK. (LP: #996407)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Name:         maketools.py
 
2
# Purpose:      Script to create tool bitmaps by screen capture
 
3
# Author:       Roman Rolinsky <rolinsky@femagsoft.com>
 
4
# Created:      04.07.2007
 
5
# RCS-ID:       $Id$
 
6
 
 
7
import os,sys,time
 
8
import wx
 
9
import wx.xrc as xrc
 
10
import wx.grid as grid
 
11
 
 
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')
 
18
        rect = win.GetRect()
 
19
        bitmap = screen.GetSubBitmap(rect)
 
20
    else:
 
21
        context = wx.ScreenDC()
 
22
        memory = wx.MemoryDC()
 
23
        x,y = win.GetPosition()
 
24
        w,h = win.GetSize()
 
25
        x0,y0 = win.ClientToScreen((0,0))
 
26
        h += y0 - y + 5
 
27
        w += 10
 
28
        bitmap = wx.EmptyBitmap(w, h, -1)
 
29
        memory.SelectObject(bitmap)
 
30
        memory.Blit(0, 0, w, h, context, x, y)
 
31
        memory.Destroy()
 
32
        context.Destroy()
 
33
    print 'Saving bitmap ', filename
 
34
    bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG)
 
35
    bitmap.Destroy()
 
36
 
 
37
 
 
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)
 
47
    else:
 
48
        context = wx.ScreenDC()
 
49
        memory = wx.MemoryDC()
 
50
        x,y = win.GetPosition()
 
51
        w,h = win.GetSize()
 
52
        x0,y0 = win.ClientToScreen((0,0))
 
53
        h = obj.GetSize()[1]
 
54
#        h += y0 - y + 5
 
55
#        w += 10
 
56
        bitmap = wx.EmptyBitmap(128, h, -1)
 
57
        memory.SelectObject(bitmap)
 
58
        memory.Blit(0, 0, 128, h, context, x0, y + 24)
 
59
        memory.Destroy()
 
60
        context.Destroy()
 
61
    print 'Saving bitmap ', filename
 
62
    bitmap.SaveFile(filename, wx.BITMAP_TYPE_PNG)
 
63
    bitmap.Destroy()
 
64
 
 
65
 
 
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)
 
75
    else:
 
76
        context = wx.ClientDC(win)
 
77
        memory = wx.MemoryDC()
 
78
        x,y = win.GetPosition()
 
79
        w,h = win.GetSize()
 
80
        bitmap = wx.EmptyBitmap(w, h, -1)
 
81
        memory.SelectObject(bitmap)
 
82
        memory.Blit(0, 0, w, h, context, 0, 0)
 
83
        memory.Destroy()
 
84
        context.Destroy()
 
85
    for w in win.GetChildren():
 
86
        klass = w.GetClassName()
 
87
        if w.GetName() != '-1': # replace by the true name
 
88
            klass = w.GetName()
 
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)
 
93
        sub.Destroy()
 
94
    bitmap.Destroy()
 
95
 
 
96
def create_panels(main_frame):
 
97
    frame = res.LoadFrame(main_frame, 'FRAME_Panels')
 
98
    if not frame:
 
99
        print 'error loading FRAME_Panels'
 
100
        return None
 
101
    # Put some data
 
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')
 
108
            w.Expand(r)
 
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':
 
119
            w.CreateGrid(2,1)
 
120
            w.AutoSizeRows()
 
121
            w.AutoSizeColumns()
 
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)
 
128
            sizer.Add(p)
 
129
            w.SetSizer(sizer)
 
130
    frame.Fit()
 
131
    frame.Show()
 
132
    return frame
 
133
 
 
134
def create_controls(main_frame):
 
135
    frame = res.LoadFrame(main_frame, 'FRAME_Controls')
 
136
    if not frame:
 
137
        print 'error loading FRAME_Controls'
 
138
        return None
 
139
    frame.Fit()
 
140
    frame.Show()
 
141
    return frame
 
142
 
 
143
def snap(evt):
 
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'
 
154
        time.sleep(1)
 
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())
 
162
 
 
163
if __name__ == '__main__':
 
164
    try: 
 
165
        resFile = sys.argv[1]
 
166
    except:
 
167
        print 'usage: python maketools.py xrc_file'
 
168
        sys.exit(1)
 
169
    global app
 
170
    app = wx.PySimpleApp(useBestVisual=False)
 
171
    res = xrc.EmptyXmlResource()
 
172
    res.Load(resFile)
 
173
 
 
174
    # Main frame
 
175
    main_frame = res.LoadFrame(None, 'main_frame')
 
176
    assert main_frame
 
177
    app.main_frame = main_frame
 
178
 
 
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()
 
194
 
 
195
    if not os.path.exists('bitmaps'): os.mkdir('bitmaps')
 
196
 
 
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')
 
206
 
 
207
    main_frame.Show()
 
208
    app.MainLoop()