test/data/vclamp_jpk/README: Document sample versions
[hooke.git] / hooke / ui / gui / panel / note.py
index 2257d8844694cf4b1a111369a9e31c910d888d9f..0a6527b75838d9e8f2c45a213c59c5bd19066838 100644 (file)
@@ -1,28 +1,53 @@
-#!/usr/bin/env python\r
-\r
-'''\r
-note.py\r
-\r
-Note panel for Hooke.\r
-\r
-Copyright 2010 by Dr. Rolf Schmidt (Concordia University, Canada)\r
-\r
-This program is released under the GNU General Public License version 2.\r
-'''\r
-import wx\r
-\r
-class Note(wx.Panel):\r
-\r
-    def __init__(self, parent):\r
-        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS|wx.NO_BORDER, size=(160, 200))\r
-\r
-        self.Editor = wx.TextCtrl(self, style=wx.TE_MULTILINE)\r
-\r
-        self.UpdateButton = wx.Button(self, -1, 'Update note')\r
-\r
-        sizer = wx.BoxSizer(wx.VERTICAL)\r
-        sizer.Add(self.Editor, 1, wx.EXPAND)\r
-        sizer.Add(self.UpdateButton, 0, wx.EXPAND)\r
-\r
-        self.SetSizer(sizer)\r
-        self.SetAutoLayout(True)\r
+# Copyright (C) 2010-2012 W. Trevor King <wking@tremily.us>
+#
+# This file is part of Hooke.
+#
+# Hooke is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with Hooke.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Note panel for Hooke.
+"""
+
+import wx
+
+from ....util.callback import callback, in_callback
+from . import Panel
+
+
+class NotePanel (Panel, wx.Panel):
+    def __init__(self, callbacks=None, **kwargs):
+        super(NotePanel, self).__init__(
+            name='note', callbacks=callbacks, **kwargs)
+
+        self._c = {
+            'editor': wx.TextCtrl(
+                parent=self,
+                style=wx.TE_MULTILINE),
+            'update': wx.Button(
+                parent=self,
+                label='Update note'),
+            }
+        sizer = wx.BoxSizer(wx.VERTICAL)
+        sizer.Add(self._c['editor'], 1, wx.EXPAND)
+        sizer.Add(self._c['update'], 0, wx.EXPAND)
+        self.SetSizer(sizer)
+        self.SetAutoLayout(True)
+
+        self.Bind(wx.EVT_BUTTON, self._on_update)
+
+    def set_text(self, text):
+        self._c['editor'].SetValue(text)
+
+    def _on_update(self, event):
+        text = self._c['editor'].GetValue()
+        in_callback(self, text)