~doctormo/python-snippets/lp-merge-request-example

« back to all changes in this revision

Viewing changes to pygtk/wheelbarrow.py

  • Committer: Jono Bacon
  • Date: 2009-12-31 01:32:01 UTC
  • Revision ID: jono@ubuntu.com-20091231013201-0jqe2hpla824dafl
Initial import.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# [SNIPPET_NAME: Wheelbarrow Custom Window]
 
4
# [SNIPPET_CATEGORIES: PyGTK]
 
5
# [SNIPPET_DESCRIPTION: Create a custom sized wheelbarrow window]
 
6
 
 
7
# example wheelbarrow.py
 
8
 
 
9
import pygtk
 
10
pygtk.require('2.0')
 
11
import gtk
 
12
 
 
13
# XPM
 
14
WheelbarrowFull_xpm = [
 
15
"48 48 64 1",
 
16
"       c None",
 
17
".      c #DF7DCF3CC71B",
 
18
"X      c #965875D669A6",
 
19
"o      c #71C671C671C6",
 
20
"O      c #A699A289A699",
 
21
"+      c #965892489658",
 
22
"@      c #8E38410330C2",
 
23
"#      c #D75C7DF769A6",
 
24
"$      c #F7DECF3CC71B",
 
25
"%      c #96588A288E38",
 
26
"&      c #A69992489E79",
 
27
"*      c #8E3886178E38",
 
28
"=      c #104008200820",
 
29
"-      c #596510401040",
 
30
";      c #C71B30C230C2",
 
31
":      c #C71B9A699658",
 
32
">      c #618561856185",
 
33
",      c #20811C712081",
 
34
"<      c #104000000000",
 
35
"1      c #861720812081",
 
36
"2      c #DF7D4D344103",
 
37
"3      c #79E769A671C6",
 
38
"4      c #861782078617",
 
39
"5      c #41033CF34103",
 
40
"6      c #000000000000",
 
41
"7      c #49241C711040",
 
42
"8      c #492445144924",
 
43
"9      c #082008200820",
 
44
"0      c #69A618611861",
 
45
"q      c #B6DA71C65144",
 
46
"w      c #410330C238E3",
 
47
"e      c #CF3CBAEAB6DA",
 
48
"r      c #71C6451430C2",
 
49
"t      c #EFBEDB6CD75C",
 
50
"y      c #28A208200820",
 
51
"u      c #186110401040",
 
52
"i      c #596528A21861",
 
53
"p      c #71C661855965",
 
54
"a      c #A69996589658",
 
55
"s      c #30C228A230C2",
 
56
"d      c #BEFBA289AEBA",
 
57
"f      c #596545145144",
 
58
"g      c #30C230C230C2",
 
59
"h      c #8E3882078617",
 
60
"j      c #208118612081",
 
61
"k      c #38E30C300820",
 
62
"l      c #30C2208128A2",
 
63
"z      c #38E328A238E3",
 
64
"x      c #514438E34924",
 
65
"c      c #618555555965",
 
66
"v      c #30C2208130C2",
 
67
"b      c #38E328A230C2",
 
68
"n      c #28A228A228A2",
 
69
"m      c #41032CB228A2",
 
70
"M      c #104010401040",
 
71
"N      c #492438E34103",
 
72
"B      c #28A2208128A2",
 
73
"V      c #A699596538E3",
 
74
"C      c #30C21C711040",
 
75
"Z      c #30C218611040",
 
76
"A      c #965865955965",
 
77
"S      c #618534D32081",
 
78
"D      c #38E31C711040",
 
79
"F      c #082000000820",
 
80
"                                                ",
 
81
"          .XoO                                  ",
 
82
"         +@#$%o&                                ",
 
83
"         *=-;#::o+                              ",
 
84
"           >,<12#:34                            ",
 
85
"             45671#:X3                          ",
 
86
"               +89<02qwo                        ",
 
87
"e*                >,67;ro                       ",
 
88
"ty>                 459@>+&&                    ",
 
89
"$2u+                  ><ipas8*                  ",
 
90
"%$;=*                *3:.Xa.dfg>                ",
 
91
"Oh$;ya             *3d.a8j,Xe.d3g8+             ",
 
92
" Oh$;ka          *3d$a8lz,,xxc:.e3g54           ",
 
93
"  Oh$;kO       *pd$%svbzz,sxxxxfX..&wn>         ",
 
94
"   Oh$@mO    *3dthwlsslszjzxxxxxxx3:td8M4       ",
 
95
"    Oh$@g& *3d$XNlvvvlllm,mNwxxxxxxxfa.:,B*     ",
 
96
"     Oh$@,Od.czlllllzlmmqV@V#V@fxxxxxxxf:%j5&   ",
 
97
"      Oh$1hd5lllslllCCZrV#r#:#2AxxxxxxxxxcdwM*  ",
 
98
"       OXq6c.%8vvvllZZiqqApA:mq:Xxcpcxxxxxfdc9* ",
 
99
"        2r<6gde3bllZZrVi7S@SV77A::qApxxxxxxfdcM ",
 
100
"        :,q-6MN.dfmZZrrSS:#riirDSAX@Af5xxxxxfevo",
 
101
"         +A26jguXtAZZZC7iDiCCrVVii7Cmmmxxxxxx%3g",
 
102
"          *#16jszN..3DZZZZrCVSA2rZrV7Dmmwxxxx&en",
 
103
"           p2yFvzssXe:fCZZCiiD7iiZDiDSSZwwxx8e*>",
 
104
"           OA1<jzxwwc:$d%NDZZZZCCCZCCZZCmxxfd.B ",
 
105
"            3206Bwxxszx%et.eaAp77m77mmmf3&eeeg* ",
 
106
"             @26MvzxNzvlbwfpdettttttttttt.c,n&  ",
 
107
"             *;16=lsNwwNwgsvslbwwvccc3pcfu<o    ",
 
108
"              p;<69BvwwsszslllbBlllllllu<5+     ",
 
109
"              OS0y6FBlvvvzvzss,u=Blllj=54       ",
 
110
"               c1-699Blvlllllu7k96MMMg4         ",
 
111
"               *10y8n6FjvllllB<166668           ",
 
112
"                S-kg+>666<M<996-y6n<8*          ",
 
113
"                p71=4 m69996kD8Z-66698&&        ",
 
114
"                &i0ycm6n4 ogk17,0<6666g         ",
 
115
"                 N-k-<>     >=01-kuu666>        ",
 
116
"                 ,6ky&      &46-10ul,66,        ",
 
117
"                 Ou0<>       o66y<ulw<66&       ",
 
118
"                  *kk5       >66By7=xu664       ",
 
119
"                   <<M4      466lj<Mxu66o       ",
 
120
"                   *>>       +66uv,zN666*       ",
 
121
"                              566,xxj669        ",
 
122
"                              4666FF666>        ",
 
123
"                               >966666M         ",
 
124
"                                oM6668+         ",
 
125
"                                  *4            ",
 
126
"                                                ",
 
127
"                                                "
 
128
]
 
129
 
 
130
class WheelbarrowExample:
 
131
    # When invoked (via signal delete_event), terminates the application
 
132
    def close_application(self, widget, event, data=None):
 
133
        gtk.main_quit()
 
134
        return False
 
135
 
 
136
    def __init__(self):
 
137
        # Create the main window, and attach delete_event signal to terminate
 
138
        # the application.  Note that the main window will not have a titlebar
 
139
        # since we're making it a popup.
 
140
        window = gtk.Window(gtk.WINDOW_POPUP)
 
141
        window.connect("delete_event", self.close_application)
 
142
        window.set_events(window.get_events() | gtk.gdk.BUTTON_PRESS_MASK)
 
143
        window.connect("button_press_event", self.close_application)
 
144
        window.show()
 
145
 
 
146
        # Now for the pixmap and the image widget
 
147
        pixmap, mask = gtk.gdk.pixmap_create_from_xpm_d(
 
148
            window.window, None, WheelbarrowFull_xpm)
 
149
        image = gtk.Image()
 
150
        image.set_from_pixmap(pixmap, mask)
 
151
        image.show()
 
152
 
 
153
        # To display the image, we use a fixed widget to place the image
 
154
        fixed = gtk.Fixed()
 
155
        fixed.set_size_request(200, 200)
 
156
        fixed.put(image, 0, 0)
 
157
        window.add(fixed)
 
158
        fixed.show()
 
159
 
 
160
        # This masks out everything except for the image itself
 
161
        window.shape_combine_mask(mask, 0, 0)
 
162
    
 
163
        # show the window
 
164
        window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
 
165
        window.show()
 
166
 
 
167
def main():
 
168
    gtk.main()
 
169
    return 0
 
170
 
 
171
if __name__ == "__main__":
 
172
    WheelbarrowExample()
 
173
    main()