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
|
<!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>Menu, Status Bar, Tool Bar — 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="Bitmaps" href="bitmaps.html" />
<link rel="prev" title="Custom Widget" href="custom_widgets.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="bitmaps.html" title="Bitmaps"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="custom_widgets.html" title="Custom Widget"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">wxGlade 1.1.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="menu-status-bar-tool-bar">
<h1>Menu, Status Bar, Tool Bar<a class="headerlink" href="#menu-status-bar-tool-bar" title="Permalink to this headline">¶</a></h1>
<div class="section" id="menu-editor">
<h2>Menu Editor<a class="headerlink" href="#menu-editor" title="Permalink to this headline">¶</a></h2>
<p>wxGlade includes a simple menu editor.</p>
<p>To attach a menu to a frame, go to <em>Properties -> Widget</em> and check <span class="guilabel">Has MenuBar</span>. <br/>
This will add a menubar icon to the <em>Tree</em>, just below the frame’s icon. <br/>
To open the menu editor, click the “Edit menus…” button.</p>
<p>The following screenshots are from the file <a class="reference external" href="../../examples/Allwidgets_28.wxg">wxglade/examples/Allwidgets_28.wxg</a>.</p>
<table border="1" class="colwidths-given docutils align-center">
<colgroup>
<col width="40%" />
<col width="60%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Properties Window:</strong> <br/> <br/>
Example of a frame with a menu bar <br/> <br/>
<code class="docutils literal"><span class="pre">Has</span> <span class="pre">MenuBar</span></code> is checked</td>
<td><a class="reference internal" href="_images/AllWidgets_28_Properties_w_MenuBar.png"><img alt="AllWidgets_28_Properties_w_MenuBar" src="_images/AllWidgets_28_Properties_w_MenuBar.png" style="height: 140px;" /></a></td>
</tr>
<tr class="row-even"><td><strong>Tree Window:</strong> <br/> <br/>
Example of a frame with a menu bar</td>
<td><a class="reference internal" href="_images/AllWidgets_28_Tree_w_MenuBar.png"><img alt="AllWidgets_28_Tree_w_MenuBar" src="_images/AllWidgets_28_Tree_w_MenuBar.png" style="height: 140px;" /></a></td>
</tr>
<tr class="row-odd"><td><strong>Properties Window:</strong> <br/>
<br/> Press the “Edit menus…” button <br/>
to open the menu editor</td>
<td><a class="reference internal" href="_images/AllWidgets_28_Properties_EditMenus.png"><img alt="AllWidgets_28_Properties_EditMenus" src="_images/AllWidgets_28_Properties_EditMenus.png" style="height: 140px;" /></a></td>
</tr>
<tr class="row-even"><td><strong>Menu Editor</strong> <br/> <br/>
The bottom part just lists the items, <br/> where the hierarchy is visualized by indentation.</td>
<td><a class="reference internal" href="_images/AllWidgets_28_MenuEditor.png"><img alt="AllWidgets_28_MenuEditor" src="_images/AllWidgets_28_MenuEditor.png" style="height: 220px;" /></a></td>
</tr>
<tr class="row-odd"><td><strong>The Menu</strong> <br/> <br/>
(In the example, “Unix” and Windows” <br/> are radio type menu items.)</td>
<td><img alt="AllWidgets_28_MenuPreview" src="_images/AllWidgets_28_MenuPreview.png" /></td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<p>As an exercise, we will now add a “File” menu with two entries to our calculator window.</p>
<blockquote>
<div><ul class="simple">
<li>When you hit “Edit menus…” for the first time, the bottom part of the editor window is almost empty. It will just contain a default entry “item”.</li>
<li>To create the required menu structure, change the label to <span class="guilabel">File</span>.</li>
<li>To create the first item, hit “Add” and then the “>” button to turn it into a submenu item and then change the label to <span class="guilabel">Reset</span>. Give this item a name <span class="guilabel">i_reset</span>. The item will then be stored with this attribute name, such that it can e.g. enabled and disabled programmatically.</li>
<li>Create an item <span class="guilabel">Exit</span> with event handler <span class="guilabel">on_menu_File_Exit</span></li>
</ul>
</div></blockquote>
<p>As of now, these items would not yet call any code when selected. So the “Event Handler” field needs to be filled with e.g. <span class="guilabel">on_menu_File_Reset</span> and <span class="guilabel">on_menu_File_Exit</span> for the two items.</p>
<p>When done and after hitting the “Start generating source files”, the editor and the created code should look like this:</p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Menu Editor</strong> <br/> <br/>
with two items: <br/> <br/>
For the <span class="guilabel">Reset</span> item, <br/>
we set a name <span class="guilabel">i_reset</span>.</td>
<td><a class="first last reference internal image-reference" href="_images/Calculator07_Menu_Editor.png"><img alt="_images/Calculator07_Menu_Editor.png" src="_images/Calculator07_Menu_Editor.png" style="height: 200px;" /></a>
</td>
</tr>
<tr class="row-even"><td><strong>Generated code</strong> <br/> <br/>
including two event handlers <br/> <br/> <br/>
The <span class="guilabel">Reset</span> menu item is assigned to <br/>
<code class="code docutils literal"><span class="pre">self.frame_menubar.i_reset</span></code> <br/>
such that it can be accessed easily, <br/>
e.g. for disabling it.</td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CalculatorFrame</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">Frame</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">kwds</span><span class="p">):</span>
<span class="c1"># begin wxGlade: CalculatorFrame.__init__</span>
<span class="n">kwds</span><span class="p">[</span><span class="s2">"style"</span><span class="p">]</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">DEFAULT_FRAME_STYLE</span>
<span class="n">wx</span><span class="o">.</span><span class="n">Frame</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">kwds</span><span class="p">)</span>
<span class="o">...</span>
<span class="c1"># Menu Bar</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">MenuBar</span><span class="p">()</span>
<span class="n">wxglade_tmp_menu</span> <span class="o">=</span> <span class="n">wx</span><span class="o">.</span><span class="n">Menu</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span> <span class="o">=</span> \
<span class="n">wxglade_tmp_menu</span><span class="o">.</span><span class="n">Append</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">ID_ANY</span><span class="p">,</span> <span class="s2">"Reset"</span><span class="p">,</span> <span class="s2">"Reset results"</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Bind</span><span class="p">(</span> <span class="n">wx</span><span class="o">.</span><span class="n">EVT_MENU</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">on_menu_File_Reset</span><span class="p">,</span>
<span class="nb">id</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span><span class="o">.</span><span class="n">GetId</span><span class="p">()</span> <span class="p">)</span>
<span class="n">item</span> <span class="o">=</span> <span class="n">wxglade_tmp_menu</span><span class="o">.</span><span class="n">Append</span><span class="p">(</span><span class="n">wx</span><span class="o">.</span><span class="n">ID_ANY</span><span class="p">,</span> <span class="s2">"Exit"</span><span class="p">,</span> <span class="s2">"Exit application"</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Bind</span><span class="p">(</span> <span class="n">wx</span><span class="o">.</span><span class="n">EVT_MENU</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">on_menu_File_Exit</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="n">item</span><span class="o">.</span><span class="n">GetId</span><span class="p">()</span> <span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">Append</span><span class="p">(</span><span class="n">wxglade_tmp_menu</span><span class="p">,</span> <span class="s2">"File"</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">SetMenuBar</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="p">)</span>
<span class="c1"># Menu Bar end</span>
<span class="o">...</span>
<span class="k">def</span> <span class="nf">on_menu_File_Reset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span> <span class="c1"># wxGlade: MyFrame.<event_handler></span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Event handler 'on_menu_File_Reset' not implemented!"</span><span class="p">)</span>
<span class="n">event</span><span class="o">.</span><span class="n">Skip</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">on_menu_File_Exit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span> <span class="c1"># wxGlade: MyFrame.<event_handler></span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"Event handler 'on_menu_File_Exit' not implemented!"</span><span class="p">)</span>
<span class="n">event</span><span class="o">.</span><span class="n">Skip</span><span class="p">()</span>
</pre></div>
</div>
</td>
</tr>
<tr class="row-odd"><td><strong>Handler implementation</strong> <br/> <br/>
in derived class <br/> <br/>
including initial disabling of <br/>
<code class="code docutils literal"><span class="pre">self.frame_menubar.i_reset</span></code></td>
<td><div class="first last highlight-default"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyFrame</span><span class="p">(</span><span class="n">CalculatorFrame</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">kwds</span><span class="p">):</span>
<span class="n">CalculatorFrame</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">kwds</span><span class="p">)</span>
<span class="c1"># insert more initialization code here</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span><span class="o">.</span><span class="n">Enable</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">on_menu_File_Reset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text_result</span><span class="o">.</span><span class="n">Clear</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span><span class="o">.</span><span class="n">Enable</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span> <span class="c1"># cleared already</span>
<span class="k">def</span> <span class="nf">on_menu_File_Exit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">Close</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">on_execute_button_clicked</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
<span class="c1"># ....</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span><span class="o">.</span><span class="n">Enable</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="n">event</span><span class="o">.</span><span class="n">Skip</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">on_reset_button_clicked</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">text_result</span><span class="o">.</span><span class="n">Clear</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">frame_menubar</span><span class="o">.</span><span class="n">i_reset</span><span class="o">.</span><span class="n">Enable</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span> <span class="c1"># cleared already</span>
<span class="n">event</span><span class="o">.</span><span class="n">Skip</span><span class="p">()</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
<p>You can implement the handler either in a derived class or directly in the file that wxGlade has written. <br/>
In the latter case, you should have enabled <em>Properties -> Application -></em> <span class="guilabel">Keep user sources</span>.</p>
<dl class="docutils">
<dt>The example menu is part of the example at wxglade/examples/Calculator:</dt>
<dd><ul class="first last simple">
<li><a class="reference external" href="../../examples/Calculator/Calculator-07-Import.wxg">Calculator-07-Import.wxg</a>.</li>
<li><a class="reference external" href="../../examples/Calculator/Calculator_GUI.py">Calculator_GUI.py</a>.</li>
<li><a class="reference external" href="../../examples/Calculator/Calculator_Main.py">Calculator_Main.py</a>.</li>
</ul>
</dd>
</dl>
<div class="section" id="lambda-event-handlers">
<h3>Lambda Event Handlers<a class="headerlink" href="#lambda-event-handlers" title="Permalink to this headline">¶</a></h3>
<p>When creating Python code, you may also specify a lambda function as event handler.</p>
<p>E.g. you may want to have three menu items named <code class="code docutils literal"><span class="pre">Insert</span> <span class="pre">A</span></code>, <code class="code docutils literal"><span class="pre">Insert</span> <span class="pre">B</span></code> and <code class="code docutils literal"><span class="pre">Insert</span> <span class="pre">C</span></code>.
Instead of three separate handlers, you may enter three lambda functions that will call the same method or function
with different arguments each:</p>
<table border="1" class="docutils">
<colgroup>
<col width="100%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><img alt="lambda evt: self.on_menu_insert_abc("A")" class="first last" src="_images/MenuLambdaEventHandlers.png" />
</td>
</tr>
</tbody>
</table>
<p>Of course you need to implement a method <code class="code docutils literal"><span class="pre">on_menu_insert_abc</span></code>.</p>
</div>
</div>
<div class="section" id="status-bar-editor">
<h2>Status Bar Editor<a class="headerlink" href="#status-bar-editor" title="Permalink to this headline">¶</a></h2>
<p>To attach a status bar to a frame, go to <em>Properties -> Widget</em> and check cHas StatusBar`.
This will add a statusbar icon to the <em>Tree</em> window, just below the frame’s icon.
(Similar to <span class="guilabel">Has MenuBar</span> in the first screenshot on this page.)</p>
<p>To add/remove fields to the status bar, go to <em>Properties -> Widget -> Fields</em> and use
the “Add”/”Insert”/”Remove”/”Apply” buttons.
If you set the “Size” of a field to a negative value like <span class="guilabel">-1</span> or <span class="guilabel">-2</span>, it will <strong>grow to fill</strong> the available space.</p>
<p><strong>Example:</strong></p>
<table border="1" class="docutils">
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><strong>Statusbar: Properties / Field Editor:</strong> <br/> <br/> <br/>
two growing and two fixed size fields</td>
<td><a class="reference internal" href="_images/Calculator_06_statusbar_Properties.png"><img alt="Example Field List" class="align-middle" src="_images/Calculator_06_statusbar_Properties.png" style="height: 120px;" /></a></td>
</tr>
<tr class="row-even"><td><strong>Toolbar</strong> <br/> <br/> <br/>
two growing and two fixed size fields</td>
<td><a class="reference internal" href="_images/Calculator_06_statusbar.png"><img alt="Example Status Bar" class="align-middle" src="_images/Calculator_06_statusbar.png" style="height: 120px;" /></a></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="tool-bar-editor">
<h2>Tool Bar Editor<a class="headerlink" href="#tool-bar-editor" title="Permalink to this headline">¶</a></h2>
<p>The logic for creating and editing a toolbar is the same as with menu bars.</p>
<p>Buttons and other controls are not supported yet</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="#">Menu, Status Bar, Tool Bar</a><ul>
<li><a class="reference internal" href="#menu-editor">Menu Editor</a><ul>
<li><a class="reference internal" href="#lambda-event-handlers">Lambda Event Handlers</a></li>
</ul>
</li>
<li><a class="reference internal" href="#status-bar-editor">Status Bar Editor</a></li>
<li><a class="reference internal" href="#tool-bar-editor">Tool Bar Editor</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="custom_widgets.html"
title="previous chapter">Custom Widget</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="bitmaps.html"
title="next chapter">Bitmaps</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/menu_status_tool.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="bitmaps.html" title="Bitmaps"
>next</a> |</li>
<li class="right" >
<a href="custom_widgets.html" title="Custom Widget"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">wxGlade 1.1.1 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017-2025, Dietmar Schwertberger.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.4.
</div>
</body>
</html>
|