Ran update-copyright.py
[hooke.git] / hooke / ui / gui / handler / selection.py
1 # Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
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 """Define :class:`SelectionHandler` to handle
19 :class:`~hooke.interaction.SelectionRequest`\s.
20 """
21
22 import wx
23
24 from ..dialog.selection import Selection
25 from . import Handler
26
27
28 class SelectionHandler (Handler):
29     def __init__(self):
30         super(SelectionHandler, self).__init__(name='selection')
31
32     def run(self, hooke_frame, msg):
33         self._canceled = True
34         while self._canceled:
35             s = Selection(
36                 options=msg.options,
37                 message=msg.msg,
38                 button_id=wxID_OK,
39                 callbacks={
40                     'button': self._selection,
41                     },
42                 default=msg.default,
43                 selection_style='single',
44                 parent=self,
45                 label='Selection handler',
46                 style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
47         return self._selected
48
49     def _selection(self, _class, method, options, selected):
50         self._selected = selected
51         self._canceled = False