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