4 class FigureMenu(object):
9 def create_menu(self
, store
, figure
, graph
, app_exec
):
10 self
._layout
_to
_str
= {'horiz': 'Horizontal', 'vert':'Vertical',\
14 self
._create
_figure
_menu
(menu
, figure
, graph
, app_exec
)
15 sep
= gtk
.SeparatorMenuItem()
17 self
._create
_graph
_menu
(menu
, figure
, graph
, app_exec
)
21 def _create_figure_menu(self
, menu
, fig
, graph
, app_exec
):
22 item_add
= gtk
.MenuItem('Add graph')
23 item_add
.connect('activate', self
._graph
_menu
_item
_activated
,
26 item_delete
= gtk
.MenuItem('Delete graph')
27 item_delete
.connect('activate', self
._delete
_graph
_menu
_item
_activated
,
28 (fig
, graph
, app_exec
))
29 item_delete
.set_sensitive(graph
is not None)
30 menu
.append(item_delete
)
31 item_layout
= gtk
.MenuItem('Layout')
32 item_layout
.set_submenu(self
._create
_layout
_menu
(fig
, app_exec
))
33 menu
.append(item_layout
)
36 def _graph_menu_item_activated(self
, menuitem
, user_data
):
37 fig
, app_exec
= user_data
41 def _delete_graph_menu_item_activated(self
, menuitem
, user_data
):
42 figure
, graph
, app_exec
= user_data
44 idx
= figure
.graphs
.index(graph
) + 1
45 app_exec('delete %d' % idx
)
46 if figure
.canvas
is not None:
49 def _create_layout_menu(self
, fig
, app_exec
):
51 for layout
in self
._layout
_to
_str
.keys():
52 item
= gtk
.CheckMenuItem(self
._layout
_to
_str
[layout
])
53 item
.set_active(fig
.layout
== layout
)
54 item
.connect('activate', self
._layout
_menu
_item
_activated
,
55 (fig
, layout
, app_exec
))
59 def _layout_menu_item_activated(self
, menuitem
, user_data
):
60 fig
, layout
, app_exec
= user_data
61 app_exec('layout ' + layout
)
62 if fig
.canvas
is not None:
65 def _create_graph_menu(self
, menu
, figure
, graph
, app_exec
):
66 graphmenu
= GraphMenu()
67 return graphmenu
.create_graph_menu(menu
, self
._store
, figure
, graph
,
70 class GraphMenu(object):
76 def create_graph_menu(self
, menu
, store
, figure
, graph
, app_exec
):
77 self
._scale
_to
_str
= {'lin': 'Linear', 'logx': 'LogX', 'logy': 'LogY',\
81 item_range
= gtk
.MenuItem('Range...')
82 item_range
.connect('activate', self
._range
_menu
_item
_activated
,
83 (figure
, graph
, app_exec
))
84 item_range
.set_sensitive(graph
is not None)
85 menu
.append(item_range
)
86 item_units
= gtk
.MenuItem('Units...')
87 item_units
.connect('activate', self
._units
_menu
_item
_activated
,
88 (figure
, graph
, app_exec
))
89 item_units
.set_sensitive(graph
is not None)
90 menu
.append(item_units
)
91 item_scale
= gtk
.MenuItem('Scale')
92 item_scale
.set_submenu(self
._create
_scale
_menu
((figure
, graph
,
94 item_scale
.set_sensitive(graph
is not None)
95 menu
.append(item_scale
)
96 item_add
= gtk
.MenuItem('Insert signal')
97 item_add
.set_submenu(self
._create
_filename
_menu
((figure
, graph
,
99 item_add
.set_sensitive(graph
is not None)
100 menu
.append(item_add
)
101 item_remove
= gtk
.MenuItem('Remove signal')
102 item_remove
.set_submenu(self
._create
_remove
_signal
_menu
((figure
, graph
,
104 item_remove
.set_sensitive(graph
is not None)
105 menu
.append(item_remove
)
108 def _create_units_window(self
, figure
, graph
, app_exec
):
111 unitdlg
= dialogs
.Enter_Units_Dialog()
112 unitdlg
.display(graph
.unit
, graph
.axis_names
, graph
.scale_factors
)
113 units
, scale_factors
= unitdlg
.run()
114 if units
and scale_factors
:
115 app_exec('unit %s' % ','.join(units
))
116 app_exec('factors %s,%s' % (scale_factors
[0],scale_factors
[1]))
117 if figure
.canvas
is not None:
120 def _units_menu_item_activated(self
, menuitem
, user_data
):
121 figure
, graph
, app_exec
= user_data
122 self
._create
_units
_window
(figure
, graph
, app_exec
)
124 def _create_range_window(self
, figure
, graph
, app_exec
):
127 rangedlg
= dialogs
.Enter_Range_Dialog()
128 rangedlg
.display(graph
.get_range(), graph
.axis_names
,
129 graph
.scale_factors
, graph
.unit
)
132 app_exec('range %s' % ' '.join(r
))
133 if figure
.canvas
is not None:
136 def _range_menu_item_activated(self
, menuitem
, user_data
):
137 figure
, graph
, app_exec
= user_data
138 self
._create
_range
_window
(figure
, graph
, app_exec
)
140 def _signals_menu_item_activated(self
, menuitem
, user_data
):
141 fig
, graph
, parent_it
, it
, app_exec
= user_data
142 name
, sig
= self
._store
.get(it
, 0, 1)
144 app_exec('add %s' % name
)
146 if graph
is not None:
147 app_exec('insert %s' % name
)
148 if fig
.canvas
is not None:
151 def _scale_menu_item_activated(self
, menuitem
, user_data
):
152 figure
, graph
, scale
, app_exec
= user_data
155 app_exec('scale %s' % scale
)
156 if figure
.canvas
is not None:
159 def _remove_signal_menu_item_activated(self
, menuitem
, user_data
):
160 figure
, graph
, signals
, app_exec
= user_data
163 app_exec('remove %s' % ' '.join(signals
.keys()))
164 if figure
.canvas
is not None:
167 def _create_scale_menu(self
, data
):
168 figure
, graph
, app_exec
= data
172 for scale
in self
._scale
_to
_str
.keys():
173 item
= gtk
.CheckMenuItem(self
._scale
_to
_str
[scale
])
174 item
.set_active(graph
.scale
== scale
)
175 item
.connect('activate', self
._scale
_menu
_item
_activated
,
176 (figure
, graph
, scale
, app_exec
))
180 def _create_remove_signal_menu(self
, data
):
181 figure
, graph
, app_exec
= data
184 item_nograph
= gtk
.MenuItem('No graph selected')
185 menu
.append(item_nograph
)
187 for name
, signal
in graph
.signals
.iteritems():
188 item
= gtk
.MenuItem(name
)
189 item
.connect('activate', self
._remove
_signal
_menu
_item
_activated
,
190 (figure
, graph
, {name
: signal
}, app_exec
))
194 def _create_signals_menu(self
, fig
, graph
, parent_it
, app_exec
):
196 it
= self
._store
.iter_children(parent_it
)
197 while it
is not None:
198 name
= self
._store
.get_value(it
, 0)
199 item
= gtk
.MenuItem(name
)
200 item
.connect('activate', self
._signals
_menu
_item
_activated
,
201 (fig
, graph
, parent_it
, it
, app_exec
))
203 it
= self
._store
.iter_next(it
)
206 def _create_filename_menu(self
, data
):
207 figure
, graph
, app_exec
= data
208 it
= self
._store
.get_iter_root()
213 while it
is not None:
214 filename
= self
._store
.get_value(it
, 0)
215 item
= gtk
.MenuItem(filename
)
216 item
.set_submenu(self
._create
_signals
_menu
(figure
, graph
, it
,
219 it
= self
._store
.iter_next(it
)