Run update-copyright.py.
[hooke.git] / hooke / ui / gui / __init__.py
1 # Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
2 #
3 # This file is part of Hooke.
4 #
5 # Hooke is free software: you can redistribute it and/or modify it under the
6 # terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option) any
8 # later version.
9 #
10 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
17
18 """Defines :class:`GUI` providing a wxWidgets interface to Hooke.
19
20 We only define the :class:`UserInterface` here, to minimize required
21 dependencies for users who may not wish to use this interface.  The
22 bulk of the interface is defined in :mod:`interface`.
23 """
24
25 import os.path as _os_path
26
27 from ...ui import UserInterface as _UserInterface
28 from ...config import Setting as _Setting
29 try:
30     import wxversion as _wxversion
31 except ImportError, e:
32     _wxversion = None
33     _wxversion_error = e
34 else:
35     try:
36         from .interface import HookeApp as _HookeApp
37     except _wxversion.VersionError, e:
38         _wxversion = None
39         _wxversion_error = e
40
41 class GUI (_UserInterface):
42     """wxWindows graphical user interface.
43     """
44     def __init__(self):
45         super(GUI, self).__init__(name='gui')
46
47     def default_settings(self):
48         """Return a list of :class:`hooke.config.Setting`\s for any
49         configurable UI settings.
50
51         The suggested section setting is::
52
53             Setting(section=self.setting_section, help=self.__doc__)
54         """
55         return [
56             _Setting(section=self.setting_section, help=self.__doc__),
57             _Setting(section=self.setting_section, option='icon image',
58                      value=_os_path.join('doc', 'img', 'microscope.ico'),
59                      type='file',
60                      help='Path to the hooke icon image.'),
61             _Setting(section=self.setting_section, option='show splash screen',
62                      value=True, type='bool',
63                      help='Enable/disable the splash screen'),
64             _Setting(section=self.setting_section, option='splash screen image',
65                      value=_os_path.join('doc', 'img', 'hooke.jpg'),
66                      type='file',
67                      help='Path to the Hooke splash screen image.'),
68             _Setting(section=self.setting_section,
69                      option='splash screen duration',
70                      value=1000, type='int',
71                      help='Duration of the splash screen in milliseconds.'),
72             _Setting(section=self.setting_section, option='perspective path',
73                      value=_os_path.join('resources', 'gui', 'perspective'),
74                      help='Directory containing perspective files.'), # TODO: allow colon separated list, like $PATH.
75             _Setting(section=self.setting_section, option='perspective extension',
76                      value='.txt',
77                      help='Extension for perspective files.'),
78             _Setting(section=self.setting_section, option='hide extensions',
79                      value=False, type='bool',
80                      help='Hide file extensions when displaying names.'),
81             _Setting(section=self.setting_section, option='plot legend',
82                      value=True, type='bool',
83                      help='Enable/disable the plot legend.'),
84             _Setting(section=self.setting_section, option='plot SI format',
85                      value='True', type='bool',
86                      help='Enable/disable SI plot axes numbering.'),
87             _Setting(section=self.setting_section, option='plot decimals',
88                      value=2, type='int',
89                      help=('Number of decimal places to show if "plot SI '
90                            'format" is enabled.')),
91             _Setting(section=self.setting_section, option='folders-workdir',
92                      value='.', type='path',
93                      help='This should probably go...'),
94             _Setting(section=self.setting_section, option='folders-filters',
95                      value='.', type='path',
96                      help='This should probably go...'),
97             _Setting(section=self.setting_section, option='active perspective',
98                      value='Default',
99                      help='Name of active perspective file (or "Default").'),
100             _Setting(section=self.setting_section,
101                      option='folders-filter-index',
102                      value=0, type='int',
103                      help='This should probably go...'),
104             _Setting(section=self.setting_section, option='main height',
105                      value=450, type='int',
106                      help='Height of main window in pixels.'),
107             _Setting(section=self.setting_section, option='main width',
108                      value=800, type='int',
109                      help='Width of main window in pixels.'),
110             _Setting(section=self.setting_section, option='main top',
111                      value=0, type='int',
112                      help='Pixels from screen top to top of main window.'),
113             _Setting(section=self.setting_section, option='main left',
114                      value=0, type='int',
115                      help='Pixels from screen left to left of main window.'),
116             _Setting(section=self.setting_section, option='selected command',
117                      value='load playlist',
118                      help='Name of the initially selected command.'),
119             ]
120
121     def _app(self, commands, ui_to_command_queue, command_to_ui_queue):
122         if _wxversion is None:
123             raise _wxversion_error
124         redirect = True
125         if __debug__:
126             redirect=False
127         app = _HookeApp(gui=self,
128                        commands=commands,
129                        inqueue=ui_to_command_queue,
130                        outqueue=command_to_ui_queue,
131                        redirect=redirect)
132         return app
133
134     def run(self, commands, ui_to_command_queue, command_to_ui_queue):
135         app = self._app(commands, ui_to_command_queue, command_to_ui_queue)
136         app.MainLoop()