Package Gnumed :: Package timelinelib :: Package wxgui :: Package dialogs :: Module textdisplay
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.dialogs.textdisplay

 1  # Copyright (C) 2009, 2010, 2011  Rickard Lindberg, Roger Lindberg 
 2  # 
 3  # This file is part of Timeline. 
 4  # 
 5  # Timeline is free software: you can redistribute it and/or modify 
 6  # it under the terms of the GNU General Public License as published by 
 7  # the Free Software Foundation, either version 3 of the License, or 
 8  # (at your option) any later version. 
 9  # 
10  # Timeline is distributed in the hope that it will be useful, 
11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  # GNU General Public License for more details. 
14  # 
15  # You should have received a copy of the GNU General Public License 
16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>. 
17   
18   
19  import wx 
20   
21  from timelinelib.wxgui.utils import BORDER 
22  from timelinelib.wxgui.utils import _display_error_message 
23  from timelinelib.editors.textdisplay import TextDisplayEditor 
24   
25   
26 -class TextDisplayDialogGui(wx.Dialog):
27
28 - def __init__(self, title, parent=None):
29 wx.Dialog.__init__(self, parent, title=title) 30 self._create_gui()
31
32 - def _create_gui(self):
33 self._text = self._create_text_control() 34 button_box = self._create_button_box() 35 vbox = self._create_vbox(self._text, button_box) 36 self.SetSizerAndFit(vbox)
37
38 - def _create_text_control(self):
39 return wx.TextCtrl(self, size=(660, 300), style=wx.TE_MULTILINE)
40
41 - def _create_button_box(self):
42 self.btn_copy = self._create_copy_btn() 43 self.btn_close = self._create_close_btn() 44 button_box = wx.BoxSizer(wx.HORIZONTAL) 45 button_box.Add(self.btn_copy, flag=wx.RIGHT, border=BORDER) 46 button_box.AddStretchSpacer() 47 button_box.Add(self.btn_close, flag=wx.LEFT, border=BORDER) 48 return button_box
49
50 - def _create_vbox(self, text, btn_box):
51 vbox = wx.BoxSizer(wx.VERTICAL) 52 vbox.Add(text, flag=wx.ALL|wx.EXPAND, border=BORDER) 53 vbox.Add(btn_box, flag=wx.ALL|wx.EXPAND, border=BORDER) 54 return vbox
55
56 - def _create_copy_btn(self):
57 btn_copy = wx.Button(self, wx.ID_COPY) 58 return btn_copy
59
60 - def _create_close_btn(self):
61 btn_close = wx.Button(self, wx.ID_CLOSE) 62 btn_close.SetDefault() 63 btn_close.SetFocus() 64 self.SetAffirmativeId(wx.ID_CLOSE) 65 return btn_close
66 67
68 -class TextDisplayDialog(TextDisplayDialogGui):
69
70 - def __init__(self, title, text, parent=None):
71 TextDisplayDialogGui.__init__(self, title, parent) 72 self._bind_events() 73 self.controller = TextDisplayEditor(self, text) 74 self.controller.initialize()
75
76 - def set_text(self, text):
77 self._text.SetValue(text)
78
79 - def get_text(self):
80 return self._text.GetValue()
81
82 - def _bind_events(self):
83 self.Bind(wx.EVT_BUTTON, self._btn_copy_on_click, self.btn_copy) 84 self.Bind(wx.EVT_BUTTON, self._btn_close_on_click, self.btn_close)
85
86 - def _btn_copy_on_click(self, evt):
87 if wx.TheClipboard.Open(): 88 self._copy_text_to_clipboard() 89 else: 90 _display_error_message(_("Unable to copy to clipboard."))
91
92 - def _copy_text_to_clipboard(self):
93 obj = wx.TextDataObject(self.controller.get_text()) 94 wx.TheClipboard.SetData(obj) 95 wx.TheClipboard.Close()
96 - def _btn_close_on_click(self, evt):
97 self.Close()
98