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