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