59ea1b7a1c45254ab281808fd362f480752abff5
[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     WX_GOOD=['2.9']
36     _wxversion.select(WX_GOOD)
37     try:
38         from .interface import HookeApp as _HookeApp
39     except _wxversion.VersionError, e:
40         _wxversion = None
41         _wxversion_error = e
42
43 class GUI (_UserInterface):
44     """wxWindows graphical user interface.
45     """
46     def __init__(self):
47         super(GUI, self).__init__(name='gui')
48
49     def default_settings(self):
50         """Return a list of :class:`hooke.config.Setting`\s for any
51         configurable UI settings.
52
53         The suggested section setting is::
54
55             Setting(section=self.setting_section, help=self.__doc__)
56         """
57         return [
58             _Setting(section=self.setting_section, help=self.__doc__),
59             _Setting(section=self.setting_section, option='icon image',
60                      value=_os_path.join('doc', 'img', 'microscope.ico'),
61                      type='file',
62                      help='Path to the hooke icon image.'),
63             _Setting(section=self.setting_section, option='show splash screen',
64                      value=True, type='bool',
65                      help='Enable/disable the splash screen'),
66             _Setting(section=self.setting_section, option='splash screen image',
67                      value=_os_path.join('doc', 'img', 'hooke.jpg'),
68                      type='file',
69                      help='Path to the Hooke splash screen image.'),
70             _Setting(section=self.setting_section,
71                      option='splash screen duration',
72                      value=1000, type='int',
73                      help='Duration of the splash screen in milliseconds.'),
74             _Setting(section=self.setting_section, option='perspective path',
75                      value=_os_path.join('resources', 'gui', 'perspective'),
76                      help='Directory containing perspective files.'), # TODO: allow colon separated list, like $PATH.
77             _Setting(section=self.setting_section, option='perspective extension',
78                      value='.txt',
79                      help='Extension for perspective files.'),
80             _Setting(section=self.setting_section, option='hide extensions',
81                      value=False, type='bool',
82                      help='Hide file extensions when displaying names.'),
83             _Setting(section=self.setting_section, option='plot legend',
84                      value=True, type='bool',
85                      help='Enable/disable the plot legend.'),
86             _Setting(section=self.setting_section, option='plot SI format',
87                      value='True', type='bool',
88                      help='Enable/disable SI plot axes numbering.'),
89             _Setting(section=self.setting_section, option='plot decimals',
90                      value=2, type='int',
91                      help=('Number of decimal places to show if "plot SI '
92                            'format" is enabled.')),
93             _Setting(section=self.setting_section, option='folders-workdir',
94                      value='.', type='path',
95                      help='This should probably go...'),
96             _Setting(section=self.setting_section, option='folders-filters',
97                      value='.', type='path',
98                      help='This should probably go...'),
99             _Setting(section=self.setting_section, option='active perspective',
100                      value='Default',
101                      help='Name of active perspective file (or "Default").'),
102             _Setting(section=self.setting_section,
103                      option='folders-filter-index',
104                      value=0, type='int',
105                      help='This should probably go...'),
106             _Setting(section=self.setting_section, option='main height',
107                      value=450, type='int',
108                      help='Height of main window in pixels.'),
109             _Setting(section=self.setting_section, option='main width',
110                      value=800, type='int',
111                      help='Width of main window in pixels.'),
112             _Setting(section=self.setting_section, option='main top',
113                      value=0, type='int',
114                      help='Pixels from screen top to top of main window.'),
115             _Setting(section=self.setting_section, option='main left',
116                      value=0, type='int',
117                      help='Pixels from screen left to left of main window.'),
118             _Setting(section=self.setting_section, option='selected command',
119                      value='load playlist',
120                      help='Name of the initially selected command.'),
121             ]
122
123     def _app(self, commands, ui_to_command_queue, command_to_ui_queue):
124         if _wxversion is None:
125             raise _wxversion_error
126         redirect = True
127         if __debug__:
128             redirect=False
129         app = _HookeApp(gui=self,
130                        commands=commands,
131                        inqueue=ui_to_command_queue,
132                        outqueue=command_to_ui_queue,
133                        redirect=redirect)
134         return app
135
136     def run(self, commands, ui_to_command_queue, command_to_ui_queue):
137         app = self._app(commands, ui_to_command_queue, command_to_ui_queue)
138         app.MainLoop()