Merged r9481:9518 on jblum/grc_reorganize into trunk. Reorganized grc source under...
[debian/gnuradio] / grc / src / gui / Dialogs.py
1 """
2 Copyright 2008 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 Constants import \
24         MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT, \
25         MAIN_WINDOW_PREFIX
26 from .. platforms.base.Constants import VERSION
27 import Preferences
28
29 class TextDisplay(gtk.TextView):
30         """A non editable gtk text view."""
31
32         def __init__(self, text=''):
33                 """
34                 TextDisplay constructor.
35                 @param text the text to display (string)
36                 """
37                 text_buffer = gtk.TextBuffer()
38                 text_buffer.set_text(text)
39                 self.set_text = text_buffer.set_text
40                 self.insert = lambda line: text_buffer.insert(text_buffer.get_end_iter(), line)
41                 gtk.TextView.__init__(self, text_buffer)
42                 self.set_editable(False)
43                 self.set_cursor_visible(False)
44                 self.set_wrap_mode(gtk.WRAP_WORD_CHAR)
45
46 class PreferencesDialog(gtk.Dialog):
47         """A dialog box to display the preferences."""
48
49         def __init__(self):
50                 """PreferencesDialog constructor."""
51                 gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE))
52                 self.set_title("Preferences")
53                 self.set_size_request(MIN_DIALOG_WIDTH, MIN_DIALOG_HEIGHT)
54                 notebook = gtk.Notebook()
55                 for title,desc,params in Preferences.get_preferences():
56                         vbox = gtk.VBox()
57                         vbox.pack_start(gtk.Label(''), False) #blank label for spacing
58                         for param in params: vbox.pack_start(param.get_input_object(), False)
59                         desc = desc.strip('\n')
60                         if desc: vbox.pack_start(TextDisplay(desc), False, padding=5)
61                         notebook.append_page(vbox, gtk.Label(title))
62                 self.vbox.pack_start(notebook, True)
63                 self.show_all()
64                 self.run()
65                 self.destroy()
66
67 def MessageDialogHelper(type, buttons, title=None, markup=None):
68         """
69         Create a modal message dialog and run it.
70         @param type the type of message: gtk.MESSAGE_INFO, gtk.MESSAGE_WARNING, gtk.MESSAGE_QUESTION or gtk.MESSAGE_ERROR
71         @param buttons the predefined set of buttons to use:
72                 gtk.BUTTONS_NONE, gtk.BUTTONS_OK, gtk.BUTTONS_CLOSE, gtk.BUTTONS_CANCEL, gtk.BUTTONS_YES_NO, gtk.BUTTONS_OK_CANCEL
73         @param tittle the title of the window (string)
74         @param markup the message text with pango markup
75         @return the gtk response from run()
76         """
77         message_dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, type, buttons)
78         if title != None: message_dialog.set_title(title)
79         if markup != None: message_dialog.set_markup(markup)
80         response = message_dialog.run()
81         message_dialog.destroy()
82         return response
83
84 class AboutDialog(gtk.AboutDialog):
85         """A cute little about dialog."""
86
87         def __init__(self):
88                 """AboutDialog constructor."""
89                 gtk.AboutDialog.__init__(self)
90                 self.set_version(VERSION)
91                 self.set_name(MAIN_WINDOW_PREFIX)
92                 self.set_license(__doc__)
93                 self.set_copyright('Copyright 2008 Free Software Foundation, Inc.')
94                 self.set_website('http://gnuradio.org/trac/wiki/GNURadioCompanion')
95                 self.set_comments("""\
96 Thank you to all those from the mailing list who tested GNU Radio Companion and offered advice.
97 --
98 Special Thanks:
99 A. Brinton Cooper -> starting the project
100 CER Technology Fellowship Grant -> initial funding
101 William R. Kenan Jr. Fund -> usrp & computers
102 Patrick Strasser -> the GRC icon
103 Achilleas Anastasopoulos -> trellis support
104 --""")
105                 self.run()
106                 self.destroy()
107
108 class HotKeysDialog(gtk.Dialog):
109         """Display each action with the associated hotkey."""
110
111         def __init__(self):
112                 """HotKeysDialog constructor."""
113                 gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE))
114                 self.set_title('Hot Keys')
115                 markup = ''
116                 for action, hotkey in (
117                         ('New Flow Graph', 'Ctrl + n'),
118                         ('Open Flow Graph', 'Ctrl + o'),
119                         ('Save Flow Graph', 'Ctrl + s'),
120                         ('Close Flow Graph', 'Ctrl + q'),
121                         ('Cut Block', 'Ctrl + x'),
122                         ('Copy Block', 'Ctrl + c'),
123                         ('Paste Block', 'Ctrl + v'),
124                         ('Undo Change', 'Ctrl + z'),
125                         ('Redo Change', 'Ctrl + y'),
126                         ('Delete Block', 'Delete'),
127                         ('Modify Parameters', 'Enter'),
128                         ('Rotate Block', 'Right'),
129                         ('Rotate Block', 'Left'),
130                         ('Enable Block', 'e'),
131                         ('Disable Block', 'd'),
132                         ('Modify Data Type', 'Up'),
133                         ('Modify Data Type', 'Down'),
134                         ('Add a Port', '+'),
135                         ('Remove a Port', '-'),
136                         ('Flow Graph Generate', 'F5'),
137                         ('Flow Graph Execute', 'F6'),
138                         ('Flow Graph Kill', 'F7'),
139                         ('Screen Shot', 'PrintScreen'),
140                 ): markup = '%s\n<b>%s:</b>%s'%(markup, action, hotkey.rjust(25-len(action), ' '))
141                 label = gtk.Label()
142                 label.set_markup('<tt>%s</tt>\n'%markup) #append newline
143                 self.vbox.pack_start(label, False)
144                 self.show_all()
145                 self.run()
146                 self.destroy()