f2f4840cc868c06b50cfc2094450c40ea5f7df2c
[hooke.git] / hooke / ui / gui / panel / note.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 """Note panel for Hooke.
19 """
20
21 import wx
22
23 from ....util.callback import callback, in_callback
24 from . import Panel
25
26
27 class NotePanel (Panel, wx.Panel):
28     def __init__(self, callbacks=None, **kwargs):
29         super(NotePanel, self).__init__(
30             name='note', callbacks=callbacks, **kwargs)
31
32         self._c = {
33             'editor': wx.TextCtrl(
34                 parent=self,
35                 style=wx.TE_MULTILINE),
36             'update': wx.Button(
37                 parent=self,
38                 label='Update note'),
39             }
40         sizer = wx.BoxSizer(wx.VERTICAL)
41         sizer.Add(self._c['editor'], 1, wx.EXPAND)
42         sizer.Add(self._c['update'], 0, wx.EXPAND)
43         self.SetSizer(sizer)
44         self.SetAutoLayout(True)
45
46         self.Bind(wx.EVT_BUTTON, self._on_update)
47
48     def set_text(self, text):
49         self._c['editor'].SetValue(text)
50
51     def _on_update(self, event):
52         text = self._c['editor'].GetValue()
53         in_callback(self, text)