File: bitmaps.html

package info (click to toggle)
wxglade 1%3A1.1.1%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,592 kB
  • sloc: python: 30,644; javascript: 740; makefile: 169; cpp: 99; perl: 90; lisp: 62; xml: 61; sh: 3
file content (336 lines) | stat: -rw-r--r-- 20,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Bitmaps &#8212; wxGlade 1.1.1 documentation</title>
    <link rel="stylesheet" href="_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="stylesheet" href="_static/css/custom.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.1.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="Further reading" href="further_reading.html" />
    <link rel="prev" title="Menu, Status Bar, Tool Bar" href="menu_status_tool.html" /> 
  </head>
  <body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="further_reading.html" title="Further reading"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="menu_status_tool.html" title="Menu, Status Bar, Tool Bar"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">wxGlade 1.1.1 documentation</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="bitmaps">
<h1>Bitmaps<a class="headerlink" href="#bitmaps" title="Permalink to this headline">¶</a></h1>
<dl class="docutils">
<dt>For some widgets you need to specify one or more bitmaps. There are several options how to do this:</dt>
<dd><ul class="first last simple">
<li>from a bitmap file</li>
<li>from a named variable: statement <span class="guilabel">var:</span></li>
<li>empty bitmap: statement <span class="guilabel">empty:</span></li>
<li>from wxArtProvider: statement <span class="guilabel">art:</span></li>
<li>from literal code: statement <span class="guilabel">code:</span></li>
</ul>
</dd>
</dl>
<div class="section" id="from-bitmap-file-path">
<h2>From Bitmap File / Path<a class="headerlink" href="#from-bitmap-file-path" title="Permalink to this headline">¶</a></h2>
<p>Specify the absolute or relative path to the bitmap file.</p>
<p>For an absolute path, you may use the file dialog by clicking the button “…”.</p>
<p>You may drag a file to the field. If the file is located below the project file’s directory, the relative path will be entered. For the absolute path just hold the <code class="kbd docutils literal"><span class="pre">Alt</span></code> or <code class="kbd docutils literal"><span class="pre">Ctrl</span></code> key.</p>
<p>Sometimes, depending on your runtime environment, you may have to customize the loading of the bitmap files.
See below for an example.</p>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Example</strong></td>
<td><div class="first highlight-default"><div class="highlight"><pre><span></span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">icons</span><span class="o">/</span><span class="n">application</span><span class="o">.</span><span class="n">png</span>
</pre></div>
</div>
<p class="last"><img alt="BitmapPath" src="_images/BitmapPath.png" /></p>
</td>
</tr>
<tr class="row-even"><td><strong>Created code</strong> <br/>
C++</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">wxBitmap</span><span class="p">(</span><span class="s2">&quot;/usr/share/icons/application.png&quot;</span><span class="p">,</span> <span class="n">wxBITMAP_TYPE_ANY</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="from-named-variable-statement-var">
<h2>From named variable: Statement <strong>var</strong><a class="headerlink" href="#from-named-variable-statement-var" title="Permalink to this headline">¶</a></h2>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Syntax</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span><span class="p">:</span><span class="o">&lt;</span><span class="n">variable</span> <span class="n">name</span><span class="o">&gt;</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-even"><td><strong>Example</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">var</span><span class="p">:</span><span class="n">my_bitmap_path</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-odd"><td><strong>Created code</strong> <br/>
C++</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">wxBitmap</span><span class="p">(</span><span class="n">my_bitmap_path</span><span class="p">,</span> <span class="n">wxBITMAP_TYPE_ANY</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="empty-bitmap-statement-empty">
<h2>Empty Bitmap: Statement <strong>empty</strong><a class="headerlink" href="#empty-bitmap-statement-empty" title="Permalink to this headline">¶</a></h2>
<p>Creates an empty bitmap of the specified size (min. 1,1)</p>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Syntax</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">empty</span><span class="p">:</span><span class="o">&lt;</span><span class="n">width</span><span class="o">&gt;</span><span class="p">,</span><span class="o">&lt;</span><span class="n">height</span><span class="o">&gt;</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-even"><td><strong>Example</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">empty</span><span class="p">:</span><span class="mi">32</span><span class="p">,</span><span class="mi">32</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-odd"><td><strong>Created code</strong> <br/>
C++</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">wx</span><span class="o">.</span><span class="n">EmptyBitmap</span><span class="p">(</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-even"><td><br/> Python</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">wxBitmap</span><span class="p">(</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">)</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="from-wxartprovider-statement-art">
<h2>From wxArtProvider: Statement <strong>art</strong><a class="headerlink" href="#from-wxartprovider-statement-art" title="Permalink to this headline">¶</a></h2>
<p>Create a bitmap using wxArtProvider.</p>
<p>See <a class="reference external" href="https://docs.wxpython.org/wx.ArtProvider.html">https://docs.wxpython.org/wx.ArtProvider.html</a> for usage of wxArtProvider.</p>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Syntax</strong></td>
<td><div class="first highlight-default"><div class="highlight"><pre><span></span><span class="n">art</span><span class="p">:</span><span class="o">&lt;</span><span class="n">ArtID</span><span class="o">&gt;</span><span class="p">,</span><span class="o">&lt;</span><span class="n">ArtClient</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>or:</p>
<div class="last highlight-default"><div class="highlight"><pre><span></span><span class="n">art</span><span class="p">:</span><span class="o">&lt;</span><span class="n">ArtID</span><span class="o">&gt;</span><span class="p">,</span><span class="o">&lt;</span><span class="n">ArtClient</span><span class="o">&gt;</span><span class="p">,</span><span class="o">&lt;</span><span class="n">width</span><span class="o">&gt;</span><span class="p">,</span><span class="o">&lt;</span><span class="n">height</span><span class="o">&gt;</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-even"><td><strong>Example</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">art</span><span class="p">:</span><span class="n">wxART_GO_UP</span><span class="p">,</span><span class="n">wxART_OTHER</span><span class="p">,</span><span class="mi">32</span><span class="p">,</span><span class="mi">32</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-odd"><td><strong>Created code</strong> <br/>
Perl</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">Wx</span><span class="p">::</span><span class="n">ArtProvider</span><span class="p">::</span><span class="n">GetBitmap</span><span class="p">(</span><span class="n">wxART_GO_UP</span><span class="p">,</span> <span class="n">wxART_OTHER</span><span class="p">,</span> <span class="n">Wx</span><span class="p">::</span><span class="n">Size</span><span class="o">-&gt;</span><span class="n">new</span><span class="p">(</span><span class="mi">32</span><span class="p">,</span> <span class="mi">32</span><span class="p">))</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="from-code-statement-code">
<h2>From Code: Statement <strong>code</strong><a class="headerlink" href="#from-code-statement-code" title="Permalink to this headline">¶</a></h2>
<p>This just inserts the given code.</p>
<table border="1" class="colwidths-given docutils">
<colgroup>
<col width="20%" />
<col width="80%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Syntax</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">code</span><span class="p">:</span><span class="o">&lt;</span><span class="n">code</span> <span class="n">chunk</span> <span class="n">to</span> <span class="k">return</span> <span class="n">a</span> <span class="n">wxBitmap</span><span class="o">&gt;</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-even"><td><strong>Example</strong></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="n">code</span><span class="p">:</span><span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="n">get_bitmap1</span><span class="p">()</span> <span class="k">else</span> <span class="n">get_bitmap2</span><span class="p">();</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-odd"><td><strong>Created code</strong> <br/>
C++</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="n">get_bitmap1</span><span class="p">()</span> <span class="k">else</span> <span class="n">get_bitmap2</span><span class="p">();</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="customizing-bitmap-loading">
<h2>Customizing Bitmap loading<a class="headerlink" href="#customizing-bitmap-loading" title="Permalink to this headline">¶</a></h2>
<p>If at runtime the image files are at a non-standard location, you need to customize the loading of image files such
that the files will be found.</p>
<p>For example, if you use PyInstaller to create a single-file executable, then the bitmaps need to be loaded from a temporary directory <code class="code docutils literal"><span class="pre">sys._MEIPASS</span></code>.</p>
<p>This example code would replace <code class="code docutils literal"><span class="pre">wx.Bitmap</span></code> with an implementation that is aware of this remapping:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">wx</span>
<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">os</span>

<span class="c1"># taken from stackoverflow re accessing data files within pyinstaller bundle.</span>
<span class="k">def</span> <span class="nf">resource_path</span><span class="p">(</span><span class="n">relative_path</span><span class="p">):</span>
    <span class="s2">&quot;Get absolute path to resource, works for dev and for PyInstaller.&quot;</span>
    <span class="n">base_path</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">sys</span><span class="p">,</span> <span class="s1">&#39;_MEIPASS&#39;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)))</span>
    <span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">base_path</span><span class="p">,</span> <span class="n">relative_path</span><span class="p">)</span>

<span class="c1"># get a reference to original wx.Bitmap (just in case)</span>
<span class="n">wxBitmap</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Bitmap</span>

<span class="c1"># customised wx.Bitmap, which obtains the location of the bitmap</span>
<span class="c1"># using the `resource_path` function above.</span>
<span class="k">class</span> <span class="nc">MyBitmap</span><span class="p">(</span><span class="n">wxBitmap</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">resource_path</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;name&#39;</span><span class="p">])</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">args</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
            <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">resource_path</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="c1"># call original wx.Bitmap</span>
        <span class="n">wxBitmap</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

<span class="c1"># Remap wx.Bitmap to our customised version.</span>
<span class="n">wx</span><span class="o">.</span><span class="n">Bitmap</span> <span class="o">=</span> <span class="n">MyBitmap</span>
</pre></div>
</div>
<p>(Courtesy of Brendan Simon)</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/wxglade.png" alt="Logo"/>
            </a></p>
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Bitmaps</a><ul>
<li><a class="reference internal" href="#from-bitmap-file-path">From Bitmap File / Path</a></li>
<li><a class="reference internal" href="#from-named-variable-statement-var">From named variable: Statement <strong>var</strong></a></li>
<li><a class="reference internal" href="#empty-bitmap-statement-empty">Empty Bitmap: Statement <strong>empty</strong></a></li>
<li><a class="reference internal" href="#from-wxartprovider-statement-art">From wxArtProvider: Statement <strong>art</strong></a></li>
<li><a class="reference internal" href="#from-code-statement-code">From Code: Statement <strong>code</strong></a></li>
<li><a class="reference internal" href="#customizing-bitmap-loading">Customizing Bitmap loading</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="menu_status_tool.html"
                        title="previous chapter">Menu, Status Bar, Tool Bar</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="further_reading.html"
                        title="next chapter">Further reading</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="_sources/bitmaps.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="further_reading.html" title="Further reading"
             >next</a> |</li>
        <li class="right" >
          <a href="menu_status_tool.html" title="Menu, Status Bar, Tool Bar"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="index.html">wxGlade 1.1.1 documentation</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2017-2025, Dietmar Schwertberger.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.4.
    </div>
  </body>
</html>