File: sampleapp.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (111 lines) | stat: -rw-r--r-- 3,613 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The sample I18N application"""

import os

import wx
import wx.lib.sized_controls as sc

class AppI18N(sc.SizedFrame):
    def __init__(self, parent, **kwds):
        """
        A sample application to demonstrate how to enable I18N support
        """
        super(AppI18N, self).__init__(parent, **kwds)
        self.SetTitle(_(u"The I18N sample application"))

        self.createMenu()
        self.createOtherCtrls()

    def createMenu(self):
        menubar = wx.MenuBar()

        # file menu
        fileMenu = wx.Menu()
        closeMenuItem = fileMenu.Append(wx.ID_ANY,
                                        _(u"Close"),
                                        _(u"Close the application"))
        self.Bind(wx.EVT_MENU, self.onClose, closeMenuItem)
        menubar.Append(fileMenu, _(u"&File"))

        # edit menu
        manageMenu = wx.Menu()
        manageSomethingMenuItem = manageMenu.Append(wx.ID_ANY,
                                            _(u"Edit something"),
                                            _(u"Edit an entry of something"))
        self.Bind(wx.EVT_MENU, self.doEditSomething, manageSomethingMenuItem)

        menubar.Append(manageMenu, _(u"&Edit"))

        # help menu
        helpMenu = wx.Menu()
        aboutMenuItem = helpMenu.Append(wx.ID_ANY,
                                        _(u"&About"),
                                        _(u"About the program"))
        self.Bind(wx.EVT_MENU, self.doAboutBox, aboutMenuItem)
        menubar.Append(helpMenu, _(u"&Help"))

        self.SetMenuBar(menubar)

    def createOtherCtrls(self):
        pane = self.GetContentsPane()

        cPane = sc.SizedPanel(pane)
        cPane.SetSizerType("grid", options={"cols": 2})
        st = wx.StaticText(cPane, wx.ID_ANY,
                           _(u"A nice label for the TextCtrl"))
        st.SetSizerProps(valign='center')
        tc = wx.TextCtrl(cPane, wx.ID_ANY)

        searchSt = wx.StaticText(cPane, wx.ID_ANY,
                            _(u"a search control"))
        searchSt.SetSizerProps(valign='center')
        searchC = wx.SearchCtrl(cPane, wx.ID_ANY)

        sline = wx.StaticLine(pane, wx.ID_ANY)
        sline.SetSizerProps(expand=True)
        bPane = sc.SizedPanel(pane)
        fB = wx.Button(bPane, wx.ID_ANY, _(u"Open a file dialog"))
        fB.SetSizerProps(align="center")
        fB.Bind(wx.EVT_BUTTON, self.onFbButton)

    def onFbButton(self, event):
        wildcard = "Python source (*.py)|*.py|"     \
                   "Compiled Python (*.pyc)|*.pyc|" \
                   "SPAM files (*.spam)|*.spam|"    \
                   "Egg file (*.egg)|*.egg|"        \
                   "All files (*.*)|*.*"

        with wx.FileDialog(
            self, message=_(u"Choose a file"),
            defaultDir=os.getcwd(),
            defaultFile="",
            wildcard=wildcard,
            style=wx.FD_OPEN | wx.FD_MULTIPLE | wx.FD_CHANGE_DIR
            ) as dlg:

            # Show the dialog and retrieve the user response. If it is the
            # OK response,
            # process the data.
            if dlg.ShowModal() == wx.ID_OK:
                # This returns a Python list of files that were selected.
                paths = dlg.GetPaths()

    def onClose(self, event):
        event.Skip()

    def doEditSomething(self, event):
        event.Skip()

    def doAboutBox(self, event):
        event.Skip()

if __name__ == '__main__':
    import app_base as ab
    app = ab.BaseApp(redirect=False)

    frame = AppI18N(None)
    frame.Show()
    app.MainLoop()