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