put the flow graph errors button into the toolbar
[debian/gnuradio] / grc / 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 import Preferences
24 import Utils
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: message_dialog.set_title(title)
55         if markup: message_dialog.set_markup(markup)
56         response = message_dialog.run()
57         message_dialog.destroy()
58         return response
59
60
61 ERRORS_MARKUP_TMPL="""\
62 #for $i, $err_msg in enumerate($errors)
63 <b>Error $i:</b>
64 $encode($err_msg.replace('\t', '  '))
65
66 #end for"""
67 def ErrorsDialog(flowgraph): MessageDialogHelper(
68         type=gtk.MESSAGE_ERROR,
69         buttons=gtk.BUTTONS_CLOSE,
70         title='Flow Graph Errors',
71         markup=Utils.parse_template(ERRORS_MARKUP_TMPL, errors=flowgraph.get_error_messages()),
72 )
73
74 class AboutDialog(gtk.AboutDialog):
75         """A cute little about dialog."""
76
77         def __init__(self, platform):
78                 """AboutDialog constructor."""
79                 gtk.AboutDialog.__init__(self)
80                 self.set_name(platform.get_name())
81                 self.set_version(platform.get_version())
82                 self.set_license(platform.get_license())
83                 self.set_copyright(platform.get_license().splitlines()[0])
84                 self.set_website(platform.get_website())
85                 self.run()
86                 self.destroy()
87
88 def HelpDialog(): MessageDialogHelper(
89         type=gtk.MESSAGE_INFO,
90         buttons=gtk.BUTTONS_CLOSE,
91         title='Help',
92         markup="""\
93 <b>Usage Tips</b>
94
95 <u>Add block</u>: drag and drop or double click a block in the block selection window.
96 <u>Rotate block</u>: Select a block, press left/right on the keyboard.
97 <u>Change type</u>: Select a block, press up/down on the keyboard.
98 <u>Edit parameters</u>: double click on a block in the flow graph.
99 <u>Make connection</u>: click on the source port of one block, then click on the sink port of another block.
100 <u>Remove connection</u>: select the connection and press delete, or drag the connection.
101
102 * See the menu for other keyboard shortcuts.""")
103
104 COLORS_DIALOG_MARKUP_TMPL = """\
105 <b>Color Mapping</b>
106
107 #if $colors
108         #set $max_len = max([len(color[0]) for color in $colors]) + 10
109         #for $title, $color_spec in $colors
110 <span background="$color_spec"><tt>$($encode($title).center($max_len))</tt></span>
111         #end for
112 #end if
113 """
114
115 def TypesDialog(platform): MessageDialogHelper(
116         type=gtk.MESSAGE_INFO,
117         buttons=gtk.BUTTONS_CLOSE,
118         title='Types',
119         markup=Utils.parse_template(COLORS_DIALOG_MARKUP_TMPL, colors=platform.get_colors()))