55e26846b1432056e0d0e204934780e74dc70747
[debian/gnuradio] / grc / src / grc / 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 ##@package grc.gui.Dialogs
20 #Misc dialogs.
21
22 import pygtk
23 pygtk.require('2.0')
24 import gtk
25 from grc.Constants import *
26 from grc import Preferences
27
28 class TextDisplay(gtk.TextView):
29         """A non editable gtk text view."""
30
31         def __init__(self, text=''):
32                 """!
33                 TextDisplay constructor.
34                 @param text the text to display (string)
35                 """
36                 text_buffer = gtk.TextBuffer()
37                 text_buffer.set_text(text)
38                 self.set_text = text_buffer.set_text
39                 self.insert = lambda line: text_buffer.insert(text_buffer.get_end_iter(), line)
40                 gtk.TextView.__init__(self, text_buffer)
41                 self.set_editable(False)
42                 self.set_cursor_visible(False)
43                 self.set_wrap_mode(gtk.WRAP_WORD_CHAR)
44
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 ######################################################################################################
68 def MessageDialogHelper(type, buttons, title=None, markup=None):
69         """!
70         Create a modal message dialog and run it.
71         @param type the type of message: gtk.MESSAGE_INFO, gtk.MESSAGE_WARNING, gtk.MESSAGE_QUESTION or gtk.MESSAGE_ERROR
72         @param buttons the predefined set of buttons to use: 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 ######################################################################################################
85 class AboutDialog(gtk.AboutDialog):
86         """A cute little about dialog."""
87
88         def __init__(self):
89                 """AboutDialog constructor."""
90                 gtk.AboutDialog.__init__(self)
91                 self.set_version(VERSION)
92                 self.set_name(MAIN_WINDOW_PREFIX)
93                 self.set_license(__doc__)
94                 self.set_copyright('Copyright 2008 Free Software Foundation, Inc.')
95                 self.set_website('http://gnuradio.org/trac/wiki/GNURadioCompanion')
96                 self.set_comments("""\
97 Thank you to all those from the mailing list who tested GNU Radio Companion and offered advice.
98 --
99 Special Thanks:
100 A. Brinton Cooper -> starting the project
101 CER Technology Fellowship Grant -> initial funding
102 William R. Kenan Jr. Fund -> usrp & computers
103 Patrick Strasser -> the GRC icon
104 Achilleas Anastasopoulos -> trellis support
105 --""")
106                 self.run()
107                 self.destroy()
108
109 ######################################################################################################
110 class HotKeysDialog(gtk.Dialog):
111         """Display each action with the associated hotkey."""
112
113         def __init__(self):
114                 """HotKeysDialog constructor."""
115                 gtk.Dialog.__init__(self, buttons=('gtk-close', gtk.RESPONSE_CLOSE))
116                 self.set_title('Hot Keys')
117                 markup = ''
118                 for action, hotkey in (
119                         ('New Flow Graph', 'Ctrl + n'),
120                         ('Open Flow Graph', 'Ctrl + o'),
121                         ('Save Flow Graph', 'Ctrl + s'),
122                         ('Close Flow Graph', 'Ctrl + q'),
123                         ('Cut Block', 'Ctrl + x'),
124                         ('Copy Block', 'Ctrl + c'),
125                         ('Paste Block', 'Ctrl + v'),
126                         ('Undo Change', 'Ctrl + z'),
127                         ('Redo Change', 'Ctrl + y'),
128                         ('Delete Block', 'Delete'),
129                         ('Modify Parameters', 'Enter'),
130                         ('Rotate Block', 'Right'),
131                         ('Rotate Block', 'Left'),
132                         ('Enable Block', 'e'),
133                         ('Disable Block', 'd'),
134                         ('Modify Data Type', 'Up'),
135                         ('Modify Data Type', 'Down'),
136                         ('Add a Port', '+'),
137                         ('Remove a Port', '-'),
138                         ('Flow Graph Generate', 'F5'),
139                         ('Flow Graph Execute', 'F6'),
140                         ('Flow Graph Kill', 'F7'),
141                         ('Screen Shot', 'PrintScreen'),
142                 ): markup = '%s\n<b>%s:</b>%s'%(markup, action, hotkey.rjust(25-len(action), ' '))
143                 label = gtk.Label()
144                 label.set_markup('<tt>%s</tt>\n'%markup) #append newline
145                 self.vbox.pack_start(label, False)
146                 self.show_all()
147                 self.run()
148                 self.destroy()