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