What is meide

meide is a ui interface creation library. You can use it to create wxPython based user interface. It can deal with several sizer class, for example: BoxSizer, GridBagSizer, StaticBoxSizer, and it also provide an easy way to create widgets, like: StaticText, TextCtrl, CheckBox, etc. You know create ui interface manually is a hard work, and that’s why meide comes out.

What is the goals of meide

  1. Supports easily sizer creation
  2. Supports easily widgets creation
  3. Supports easily frame creation, like: Dialog, Panel, etc
  4. Supports SetValue and GetValue to value-field
  5. Supports event binding
  6. Supports validate
  7. Makes above as easy as I can

meide is still in heavy developpint, so please keep touch with it, maybe you can find something very useful or helpful.

How to use it

The step is easy:

  1. Creatint a layout
  2. Add widgets or sub-layout
  3. Binding event
  4. invoke the create method

Examples

There are some testing examples you can find in tests subdirectroy.

Example 1 – The simplest example

This example comes from test/test_simple.py, you can run all the examples in the tests directory. And below is just the main code snippet:

    import meide as ui

    self.box = box = ui.VBox()
    box.add(ui.Button('Hello'), flag=wx.ALIGN_CENTER|wx.ALL).bind('click', self.OnClickHello)

    ui.create(self, box, fit=2)

first, you shuld import meide module, you can rename it a new name ui.

`ui.VBox()’ will create a layout. So you can guess there should be a HBox, yes, you are right.

box.add will add widgets or sub-layout to current layout. For the most simplest case, you can only add widgets or sub-layout instance or even class name. For example:

    box.add(ui.Button)

this code is also right. The full add method signature is::

    def add(element, name='', proportion=None, flag=None, border=None)

So the first parameter should be a class name or instance of a widget or a layout. Other parameters could be skipped. Every element could has a name, and you can get this element back in the later via this name. If you don’t give a name, meide will automatically create one name for you, the name format will be like ‘id%d’, here the %d will automatically increase. proportion just like the proportion parameter of add method in any sizer class. and the flag and border are also the same. For more detail you can read the document of wx.Sizer Add method.

So the above example uses a flag parameter, and it means that the Hello button should be aligned center and four direction will have a border.

The next .bind will bind a click event to a function. meide will define some easily remembered event name, for example: click for EVT_BUTTON, check for EVT_CHECKBOX. So you can use these simple event name or just use EVT_CHECKBOX, meide will still deal with them. So bind('click', self.OnClickHello) means that when you click on the Hello button, it’ll raise a click event, and invoke self.OnClickHello function.

ui.create(self, box, fit=2) will initialize the layout. The first parameter is the parent window object. the second parameter is the layout object. And the third one is used to fit the window to the best size. If the fit is 0, don’t change the window size, if the fit is 1, then changes the height to the best size, if the fit is 2, then changes the width and height to the best size.


评论

该日志第一篇评论

发表评论

评论也有版权!