1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
"""
Copyright 2008, 2009, 2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
GNU Radio Companion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
import pygtk
pygtk.require('2.0')
import gtk
import Actions
from StateCache import StateCache
from Constants import MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT
from DrawingArea import DrawingArea
import os
############################################################
## Notebook Page
############################################################
class NotebookPage(gtk.HBox):
"""A page in the notebook."""
def __init__(self, main_window, flow_graph, file_path=''):
"""
Page constructor.
@param main_window main window
@param file_path path to a flow graph file
"""
self._flow_graph = flow_graph
self.set_proc(None)
#import the file
self.main_window = main_window
self.set_file_path(file_path)
initial_state = flow_graph.get_parent().parse_flow_graph(file_path)
self.state_cache = StateCache(initial_state)
self.set_saved(True)
#import the data to the flow graph
self.get_flow_graph().import_data(initial_state)
#initialize page gui
gtk.HBox.__init__(self, False, 0)
self.show()
#tab box to hold label and close button
self.tab = gtk.HBox(False, 0)
#setup tab label
self.label = gtk.Label()
self.tab.pack_start(self.label, False)
#setup button image
image = gtk.Image()
image.set_from_stock('gtk-close', gtk.ICON_SIZE_MENU)
#setup image box
image_box = gtk.HBox(False, 0)
image_box.pack_start(image, True, False, 0)
#setup the button
button = gtk.Button()
button.connect("clicked", self._handle_button)
button.set_relief(gtk.RELIEF_NONE)
button.add(image_box)
#button size
w, h = gtk.icon_size_lookup_for_settings(button.get_settings(), gtk.ICON_SIZE_MENU)
button.set_size_request(w+6, h+6)
self.tab.pack_start(button, False)
self.tab.show_all()
#setup scroll window and drawing area
self.scrolled_window = gtk.ScrolledWindow()
self.scrolled_window.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT)
self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.drawing_area = DrawingArea(self.get_flow_graph())
self.scrolled_window.add_with_viewport(self.get_drawing_area())
self.pack_start(self.scrolled_window)
#inject drawing area into flow graph
self.get_flow_graph().drawing_area = self.get_drawing_area()
self.show_all()
def get_drawing_area(self): return self.drawing_area
def get_generator(self):
"""
Get the generator object for this flow graph.
@return generator
"""
return self.get_flow_graph().get_parent().get_generator()(
self.get_flow_graph(),
self.get_file_path(),
)
def _handle_button(self, button):
"""
The button was clicked.
Make the current page selected, then close.
@param the button
"""
self.main_window.page_to_be_closed = self
Actions.FLOW_GRAPH_CLOSE()
def set_markup(self, markup):
"""
Set the markup in this label.
@param markup the new markup text
"""
self.label.set_markup(markup)
def get_tab(self):
"""
Get the gtk widget for this page's tab.
@return gtk widget
"""
return self.tab
def get_proc(self):
"""
Get the subprocess for the flow graph.
@return the subprocess object
"""
return self.process
def set_proc(self, process):
"""
Set the subprocess object.
@param process the new subprocess
"""
self.process = process
def get_flow_graph(self):
"""
Get the flow graph.
@return the flow graph
"""
return self._flow_graph
def get_read_only(self):
"""
Get the read-only state of the file.
Always false for empty path.
@return true for read-only
"""
if not self.get_file_path(): return False
return os.path.exists(self.get_file_path()) and \
not os.access(self.get_file_path(), os.W_OK)
def get_file_path(self):
"""
Get the file path for the flow graph.
@return the file path or ''
"""
return self.file_path
def set_file_path(self, file_path=''):
"""
Set the file path, '' for no file path.
@param file_path file path string
"""
if file_path: self.file_path = os.path.abspath(file_path)
else: self.file_path = ''
def get_saved(self):
"""
Get the saved status for the flow graph.
@return true if saved
"""
return self.saved
def set_saved(self, saved=True):
"""
Set the saved status.
@param saved boolean status
"""
self.saved = saved
def get_state_cache(self):
"""
Get the state cache for the flow graph.
@return the state cache
"""
return self.state_cache
|