File: wx.lib.agw.flatmenu.txt

package info (click to toggle)
wxpython4.0 4.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 211,112 kB
  • sloc: cpp: 888,355; python: 223,130; makefile: 52,087; ansic: 45,780; sh: 3,012; xml: 1,534; perl: 264
file content (293 lines) | stat: -rw-r--r-- 12,077 bytes parent folder | download | duplicates (2)
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
.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2018 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc

.. module:: wx.lib.agw.flatmenu

.. currentmodule:: wx.lib.agw.flatmenu

.. highlight:: python



.. _wx.lib.agw.flatmenu:

==========================================================================================================================================
|phoenix_title|  **wx.lib.agw.flatmenu**
==========================================================================================================================================

:class:`~wx.lib.agw.flatmenu.FlatMenu` is a generic menu implementation.


Description
===========

:class:`FlatMenu`, like the name implies, it is a generic menu implementation.
I tried to provide a full functionality for menus, menubar and toolbar.


:class:`FlatMenu` supports the following features:

- Fires all the events (UI & Cmd);
- Check items;
- Separators;
- Enabled / Disabled menu items;
- Images on items;
- Toolbar support, with images and separators;
- Controls in toolbar (work in progress);
- Toolbar tools tooltips (done: thanks to Peter Kort);
- Accelerators for menus;
- Accelerators for menubar;
- Radio items in menus;
- Integration with AUI;
- Scrolling when menu is too big to fit the screen;
- Menu navigation with keyboard;
- Drop down arrow button to the right of the menu, it always contains the
  "Customize" option, which will popup an options dialog. The dialog has the
  following abilities:

  (a) Ability to add/remove menus;
  (b) Select different colour schemes for the menu bar / toolbar;
  (c) Control various options, such as: colour for highlight menu item, draw
      border around menus (classic look only);
  (d) Toolbar floating appearance.

- Allows user to specify grey bitmap for disabled menus/toolbar tools;
- If no grey bitmap is provided, it generates one from the existing bitmap;
- Hidden toolbar items / menu bar items - will appear in a small popmenu
  to the right if they are hidden;
- 4 different colour schemes for the menu bar (more can easily added);
- Scrolling is available if the menu height is greater than the screen height;
- Context menus for menu items;
- Show/hide the drop down arrow which allows the customization of :class:`FlatMenu`;
- Multiple columns menu window;
- Tooltips for menus and toolbar items on a :class:`StatusBar` (if present);
- Transparency (alpha channel) for menu windows (for platforms supporting it);
- FileHistory support through a pure-Python :class:`FileHistory` implementation;
- Possibility to set a background bitmap for a :class:`FlatMenu`;
- First attempt in adding controls to FlatToolbar;
- Added a MiniBar (thanks to Vladiuz);
- Added :class:`ToolBar` methods AddCheckTool/AddRadioTool (thanks to Vladiuz).


Usage
=====

Usage example::

    import wx
    import wx.lib.agw.flatmenu as FM

    class MyFrame(wx.Frame):

        def __init__(self, parent):

            wx.Frame.__init__(self, parent, -1, "FlatMenu Demo")

            self.CreateMenu()

            panel = wx.Panel(self, -1)
            btn = wx.Button(panel, -1, "Hello", (15, 12), (100, 120))

            main_sizer = wx.BoxSizer(wx.VERTICAL)
            main_sizer.Add(self.menubar, 0, wx.EXPAND)
            main_sizer.Add(panel, 1, wx.EXPAND)

            self.SetSizer(main_sizer)
            main_sizer.Layout()


        def CreateMenu(self):

            self.menubar = FM.FlatMenuBar(self, -1)

            f_menu = FM.FlatMenu()
            e_menu = FM.FlatMenu()
            v_menu = FM.FlatMenu()
            t_menu = FM.FlatMenu()
            w_menu = FM.FlatMenu()

            # Append the menu items to the menus
            f_menu.Append(-1, "Simple   Ctrl+N", "Text", None)
            e_menu.Append(-1, "FlatMenu", "Text", None)
            v_menu.Append(-1, "Example", "Text", None)
            t_menu.Append(-1, "Hello", "Text", None)
            w_menu.Append(-1, "World", "Text", None)

            # Append menus to the menubar
            self.menubar.Append(f_menu, "&File")
            self.menubar.Append(e_menu, "&Edit")
            self.menubar.Append(v_menu, "&View")
            self.menubar.Append(t_menu, "&Options")
            self.menubar.Append(w_menu, "&Help")


    # our normal wxApp-derived class, as usual

    app = wx.App(0)

    frame = MyFrame(None)
    app.SetTopWindow(frame)
    frame.Show()

    app.MainLoop()



Supported Platforms
===================

:class:`FlatMenu` has been tested on the following platforms:
  * Windows (Windows XP, Vista);
  * Linux Ubuntu (Dapper 6.06)



Window Styles
=============

This class supports the following window styles:

========================= =========== ==================================================
Window Styles             Hex Value   Description
========================= =========== ==================================================
``FM_OPT_IS_LCD``                 0x1 Use this style if your computer uses a LCD screen.
``FM_OPT_MINIBAR``                0x2 Use this if you plan to use the toolbar only.
``FM_OPT_SHOW_CUSTOMIZE``         0x4 Show "customize link" in the `More` menu, you will need to write your own handler. See demo.
``FM_OPT_SHOW_TOOLBAR``           0x8 Set this option is you are planning to use the toolbar.
========================= =========== ==================================================


Events Processing
=================

This class processes the following events:

================================= ==================================================
Event Name                        Description
================================= ==================================================
``EVT_FLAT_MENU_DISMISSED``       Used internally.
``EVT_FLAT_MENU_ITEM_MOUSE_OUT``  Fires an event when the mouse leaves a :class:`FlatMenuItem`.
``EVT_FLAT_MENU_ITEM_MOUSE_OVER`` Fires an event when the mouse enters a :class:`FlatMenuItem`.
``EVT_FLAT_MENU_SELECTED``        Fires the :class:`EVT_MENU` event for :class:`FlatMenu`.
================================= ==================================================


License And Version
===================

:class:`FlatMenu` is distributed under the wxPython license.

Latest Revision: Andrea Gavana @ 27 Dec 2012, 21.00 GMT

Version 1.0


|function_summary| Functions Summary
====================================

================================================================================ ================================================================================
:func:`~wx.lib.agw.flatmenu.ConvertToMonochrome`                                 Converts a bitmap to monochrome colour.
:func:`~wx.lib.agw.flatmenu.GetAccelIndex`                                       Returns the mnemonic index of the label and the label stripped of the ampersand mnemonic
:func:`~wx.lib.agw.flatmenu.GetMRUEntryLabel`                                    Returns the string used for the MRU list items in the menu.
================================================================================ ================================================================================


|


|class_summary| Classes Summary
===============================

================================================================================ ================================================================================
:ref:`~wx.lib.agw.flatmenu.FileHistory`                                          The :class:`FileHistory` encapsulates a user interface convenience, the list of most
:ref:`~wx.lib.agw.flatmenu.FlatMenu`                                             A Flat popup menu generic implementation.
:ref:`~wx.lib.agw.flatmenu.FlatMenuBar`                                          Implements the generic owner-drawn menu bar for :class:`FlatMenu`.
:ref:`~wx.lib.agw.flatmenu.FlatMenuBase`                                         Base class for generic flat menu derived from :class:`PopupWindow`.
:ref:`~wx.lib.agw.flatmenu.FlatMenuButton`                                       A nice small class that functions like :class:`wx.BitmapButton`, the reason I did
:ref:`~wx.lib.agw.flatmenu.FlatMenuEvent`                                        Event class that supports the :class:`FlatMenu`-compatible event called
:ref:`~wx.lib.agw.flatmenu.FlatMenuItem`                                         A class that represents an item in a menu.
:ref:`~wx.lib.agw.flatmenu.FlatMenuItemGroup`                                    A class that manages a group of radio menu items.
:ref:`~wx.lib.agw.flatmenu.FlatToolbarItem`                                      This class represents a toolbar item.
:ref:`~wx.lib.agw.flatmenu.FMRenderer`                                           Base class for the :class:`FlatMenu` renderers. This class implements the common
:ref:`~wx.lib.agw.flatmenu.FMRendererMgr`                                        This class represents a manager that handles all the renderers defined.
:ref:`~wx.lib.agw.flatmenu.FMRendererMSOffice2007`                               Windows Office 2007 style.
:ref:`~wx.lib.agw.flatmenu.FMRendererVista`                                      Windows Vista-like style.
:ref:`~wx.lib.agw.flatmenu.FMRendererXP`                                         Xp-Style renderer.
:ref:`~wx.lib.agw.flatmenu.FocusHandler`                                         A focus event handler.
:ref:`~wx.lib.agw.flatmenu.mcPopupWindow`                                        Since Max OS does not support :class:`PopupWindow`, this is an alternative.
:ref:`~wx.lib.agw.flatmenu.MenuEntryInfo`                                        Internal class which holds information about a menu.
:ref:`~wx.lib.agw.flatmenu.MenuKbdRedirector`                                    A keyboard event handler.
:ref:`~wx.lib.agw.flatmenu.ShadowPopupWindow`                                    Base class for generic :class:`FlatMenu` derived from :class:`PopupWindow`.
:ref:`~wx.lib.agw.flatmenu.StatusBarTimer`                                       Timer used for deleting :class:`StatusBar` long help after ``_DELAY`` seconds.
:ref:`~wx.lib.agw.flatmenu.ToolBarItem`                                          A simple class that holds information about a toolbar item.
================================================================================ ================================================================================


|


.. toctree::
   :maxdepth: 1
   :hidden:

   wx.lib.agw.flatmenu.FileHistory
   wx.lib.agw.flatmenu.FlatMenu
   wx.lib.agw.flatmenu.FlatMenuBar
   wx.lib.agw.flatmenu.FlatMenuBase
   wx.lib.agw.flatmenu.FlatMenuButton
   wx.lib.agw.flatmenu.FlatMenuEvent
   wx.lib.agw.flatmenu.FlatMenuItem
   wx.lib.agw.flatmenu.FlatMenuItemGroup
   wx.lib.agw.flatmenu.FlatToolbarItem
   wx.lib.agw.flatmenu.FMRenderer
   wx.lib.agw.flatmenu.FMRendererMgr
   wx.lib.agw.flatmenu.FMRendererMSOffice2007
   wx.lib.agw.flatmenu.FMRendererVista
   wx.lib.agw.flatmenu.FMRendererXP
   wx.lib.agw.flatmenu.FocusHandler
   wx.lib.agw.flatmenu.mcPopupWindow
   wx.lib.agw.flatmenu.MenuEntryInfo
   wx.lib.agw.flatmenu.MenuKbdRedirector
   wx.lib.agw.flatmenu.ShadowPopupWindow
   wx.lib.agw.flatmenu.StatusBarTimer
   wx.lib.agw.flatmenu.ToolBarItem





Functions
------------

.. function:: ConvertToMonochrome(bmp)

   Converts a bitmap to monochrome colour.
   
   :param `bmp`: a valid :class:`wx.Bitmap` object.


.. function:: GetAccelIndex(label)

   Returns the mnemonic index of the label and the label stripped of the ampersand mnemonic
   (e.g. 'lab&el' ==> will result in 3 and labelOnly = label).
   
   :param string `label`: a string possibly containining an ampersand.


.. function:: GetMRUEntryLabel(n, path)

   Returns the string used for the MRU list items in the menu.
   
   :param integer `n`: the index of the file name in the MRU list;
   :param string `path`: the full path of the file name.
   
   :note: The index `n` is 0-based, as usual, but the strings start from 1.