added include <cstdio> statements in several files to make it compatible with g+...
[debian/gnuradio] / grc / src / gui / Messages.py
1 """
2 Copyright 2007 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 from .. platforms.base.Constants import PACKAGE, VERSION
21 import traceback
22 import sys
23
24 ## A list of functions that can receive a message.
25 MESSENGERS_LIST = list()
26
27 def register_messenger(messenger):
28         """
29         Append the given messenger to the list of messengers.
30         @param messenger a method thats takes a string
31         """
32         MESSENGERS_LIST.append(messenger)
33
34 def send(message):
35         """
36         Give the message to each of the messengers.
37         @param message a message string
38         """
39         for messenger in MESSENGERS_LIST: messenger(message)
40
41 #register stdout by default
42 register_messenger(sys.stdout.write)
43
44 ###########################################################################
45 # Special functions for specific program functionalities
46 ###########################################################################
47 def send_init():
48         send("""<<< Welcome to %s %s >>>\n"""%(PACKAGE, VERSION))
49
50 def send_page_switch(file_path):
51         send('\nShowing: "%s"\n'%file_path)
52
53 ################# functions for loading flow graphs     ########################################
54 def send_start_load(file_path):
55         send('\nLoading: "%s"'%file_path + '\n')
56
57 def send_error_load(error):
58         send('>>> Error: %s\n'%error)
59         traceback.print_exc()
60
61 def send_end_load():
62         send('>>> Done\n')
63
64 def send_fail_load(error):
65         send('Error: %s\n'%error)
66         send('>>> Failue\n')
67         traceback.print_exc()
68
69 ################# functions for generating flow graphs  ########################################
70 def send_start_gen(file_path):
71         send('\nGenerating: "%s"'%file_path + '\n')
72
73 def send_fail_gen(error):
74         send('Generate Error: %s\n'%error)
75         send('>>> Failue\n')
76         traceback.print_exc()
77
78 ################# functions for executing flow graphs   ########################################
79 def send_start_exec(file_path):
80         send('\nExecuting: "%s"'%file_path + '\n')
81
82 def send_verbose_exec(verbose):
83         send(verbose)
84
85 def send_end_exec():
86         send('\n>>> Done\n')
87
88 ################# functions for saving flow graphs      ########################################
89 def send_fail_save(file_path):
90         send('>>> Error: Cannot save: %s\n'%file_path)
91
92 ################# functions for connections     ########################################
93 def send_fail_connection():
94         send('>>> Error: Cannot create connection.\n')
95
96 ################# functions for preferences     ########################################
97 def send_fail_load_preferences(prefs_file_path):
98         send('>>> Error: Cannot load preferences file: "%s"\n'%prefs_file_path)
99
100 def send_fail_save_preferences(prefs_file_path):
101         send('>>> Error: Cannot save preferences file: "%s"\n'%prefs_file_path)
102
103 ################# functions for warning ########################################
104 def send_warning(warning):
105         send('>>> Warning: %s\n'%warning)