2 Copyright 2008, 2009 Free Software Foundation, Inc.
3 This file is part of GNU Radio
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.
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.
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
24 from StateCache import StateCache
25 from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
26 from DrawingArea import DrawingArea
29 ############################################################
31 ############################################################
33 class NotebookPage(gtk.HBox):
34 """A page in the notebook."""
36 def __init__(self, main_window, flow_graph, file_path=''):
39 @param main_window main window
40 @param file_path path to a flow graph file
42 self._flow_graph = flow_graph
45 self.main_window = main_window
46 self.set_file_path(file_path)
47 initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
48 self.state_cache = StateCache(initial_state)
50 #import the data to the flow graph
51 self.get_flow_graph().import_data(initial_state)
53 gtk.HBox.__init__(self, False, 0)
55 #tab box to hold label and close button
56 self.tab = gtk.HBox(False, 0)
58 self.label = gtk.Label()
59 self.tab.pack_start(self.label, False)
62 image.set_from_stock('gtk-close', gtk.ICON_SIZE_MENU)
64 image_box = gtk.HBox(False, 0)
65 image_box.pack_start(image, True, False, 0)
68 button.connect("clicked", self._handle_button)
69 button.set_relief(gtk.RELIEF_NONE)
72 w, h = gtk.icon_size_lookup_for_settings(button.get_settings(), gtk.ICON_SIZE_MENU)
73 button.set_size_request(w+6, h+6)
74 self.tab.pack_start(button, False)
76 #setup scroll window and drawing area
77 self.scrolled_window = gtk.ScrolledWindow()
78 self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
79 self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
80 self.drawing_area = DrawingArea(self.get_flow_graph())
81 self.scrolled_window.add_with_viewport(self.get_drawing_area())
82 self.pack_start(self.scrolled_window)
83 #inject drawing area into flow graph
84 self.get_flow_graph().drawing_area = self.get_drawing_area()
87 def get_drawing_area(self): return self.drawing_area
89 def get_generator(self):
91 Get the generator object for this flow graph.
94 return self.get_flow_graph().get_parent().get_generator()(
95 self.get_flow_graph(),
99 def _handle_button(self, button):
101 The button was clicked.
102 Make the current page selected, then close.
105 self.main_window.page_to_be_closed = self
106 Actions.FLOW_GRAPH_CLOSE()
108 def set_markup(self, markup):
110 Set the markup in this label.
111 @param markup the new markup text
113 self.label.set_markup(markup)
117 Get the gtk widget for this page's tab.
124 Get the pid for the flow graph.
125 @return the pid number
129 def set_pid(self, pid):
132 @param pid the new pid number
136 def get_flow_graph(self):
139 @return the flow graph
141 return self._flow_graph
143 def get_read_only(self):
145 Get the read-only state of the file.
146 Always false for empty path.
147 @return true for read-only
149 if not self.get_file_path(): return False
150 return os.path.exists(self.get_file_path()) and \
151 not os.access(self.get_file_path(), os.W_OK)
153 def get_file_path(self):
155 Get the file path for the flow graph.
156 @return the file path or ''
158 return self.file_path
160 def set_file_path(self, file_path=''):
162 Set the file path, '' for no file path.
163 @param file_path file path string
165 if file_path: self.file_path = os.path.abspath(file_path)
166 else: self.file_path = ''
170 Get the saved status for the flow graph.
171 @return true if saved
175 def set_saved(self, saved=True):
177 Set the saved status.
178 @param saved boolean status
182 def get_state_cache(self):
184 Get the state cache for the flow graph.
185 @return the state cache
187 return self.state_cache