added include <cstdio> statements in several files to make it compatible with g+...
[debian/gnuradio] / grc / src / gui / Dialogs.py
1 """
2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
4
5 GNU Radio Companion is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 GNU Radio Companion 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 this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18 """
19
20 import pygtk
21 pygtk.require('2.0')
22 import gtk
23 from .. platforms.base.Constants import PACKAGE, VERSION
24 import Preferences
25
26 class TextDisplay(gtk.TextView):
27         """A non editable gtk text view."""
28
29         def __init__(self, text=''):
30                 """
31                 TextDisplay constructor.
32                 @param text the text to display (string)
33                 """
34                 text_buffer = gtk.TextBuffer()
35                 text_buffer.set_text(text)
36                 self.set_text = text_buffer.set_text
37                 self.insert = lambda line: text_buffer.insert(text_buffer.get_end_iter(), line)
38                 gtk.TextView.__init__(self, text_buffer)
39                 self.set_editable(False)
40                 self.set_cursor_visible(False)
41                 self.set_wrap_mode(gtk.WRAP_WORD_CHAR)
42
43 def MessageDialogHelper(type, buttons, title=None, markup=None):
44         """
45         Create a modal message dialog and run it.
46         @param type the type of message: gtk.MESSAGE_INFO, gtk.MESSAGE_WARNING, gtk.MESSAGE_QUESTION or gtk.MESSAGE_ERROR
47         @param buttons the predefined set of buttons to use:
48                 gtk.BUTTONS_NONE, gtk.BUTTONS_OK, gtk.BUTTONS_CLOSE, gtk.BUTTONS_CANCEL, gtk.BUTTONS_YES_NO, gtk.BUTTONS_OK_CANCEL
49         @param tittle the title of the window (string)
50         @param markup the message text with pango markup
51         @return the gtk response from run()
52         """
53         message_dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type, buttons)
54         if title != None: message_dialog.set_title(title)
55         if markup != None: message_dialog.set_markup(markup)
56         response = message_dialog.run()
57         message_dialog.destroy()
58         return response
59
60 class AboutDialog(gtk.AboutDialog):
61         """A cute little about dialog."""
62
63         def __init__(self):
64                 """AboutDialog constructor."""
65                 gtk.AboutDialog.__init__(self)
66                 self.set_name(PACKAGE)
67                 self.set_version(VERSION)
68                 self.set_license(__doc__)
69                 self.set_copyright(__doc__.strip().splitlines()[0])
70                 self.set_website('http://gnuradio.org/trac/wiki/GNURadioCompanion')
71                 self.set_comments("""\
72 Thank you to all those from the mailing list who tested GNU Radio Companion and offered advice.
73 -----
74 Special Thanks:
75 A. Brinton Cooper -> starting the project
76 Patrick Mulligan -> starting the project
77 CER Technology Fellowship Grant -> initial funding
78 William R. Kenan Jr. Fund -> usrp & computers
79 Patrick Strasser -> the GRC icon
80 Achilleas Anastasopoulos -> trellis support
81 -----""")
82                 self.run()
83                 self.destroy()
84
85 def HelpDialog():
86         MessageDialogHelper(
87                 type=gtk.MESSAGE_INFO,
88                 buttons=gtk.BUTTONS_CLOSE,
89                 title='Help',
90                 markup="""\
91 <b>Usage Tips</b>
92
93 <u>Add block</u>: drag and drop or double click a block in the block selection window.
94 <u>Rotate block</u>: Select a block, press left/right on the keyboard.
95 <u>Change type</u>: Select a block, press up/down on the keyboard.
96 <u>Edit parameters</u>: double click on a block in the flow graph.
97 <u>Make connection</u>: click on the source port of one block, then click on the sink port of another block.
98 <u>Remove connection</u>: select the connection and press delete, or drag the connection.
99
100 * See the menu for other keyboard shortcuts.""")