9 from oscopy
import factors_to_names
, abbrevs_to_factors
11 class Enter_Units_Dialog(object):
14 self
._entry
_xunits
= None
15 self
._entry
_yunits
= None
16 self
._scale
_factors
= gtk
.ListStore(gobject
.TYPE_STRING
,
18 sorted_list
= factors_to_names
.keys()
20 for factor
in sorted_list
:
21 self
._scale
_factors
.append((factors_to_names
[factor
][0],
22 factors_to_names
[factor
][1]))
24 def display(self
, units
, xy
, scale_factors
):
26 sorted_list
= factors_to_names
.keys()
29 self
._dlg
= gtk
.Dialog(_('Enter graph units'),
30 flags
=gtk
.DIALOG_NO_SEPARATOR
,
31 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
32 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
33 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
34 table
= gtk
.Table(2, 3, False)
35 table
.set_col_spacing(0, 12)
36 table
.set_col_spacing(1, 12)
37 # Label, scale factor and entry for X axis
38 label_xunits
= gtk
.Label(xy
[0])
39 align
= gtk
.Alignment(0, 0.5)
40 align
.add(label_xunits
)
41 table
.attach(align
, 0, 1, 0, 1)
42 self
._entry
_xunits
= gtk
.Entry()
43 self
._entry
_xunits
.set_text(units
[0])
44 self
._entry
_xunits
.set_width_chars(7)
45 self
._entry
_xunits
.set_activates_default(True)
46 table
.attach(self
._entry
_xunits
, 2, 3, 0, 1)
47 self
._combox
_fact
= gtk
.ComboBox(self
._scale
_factors
)
48 self
._combox
_fact
.set_active(sorted_list
.index(scale_factors
[0]))
49 cell
= gtk
.CellRendererText()
50 self
._combox
_fact
.pack_start(cell
, True)
51 self
._combox
_fact
.add_attribute(cell
, 'text', 1)
52 table
.attach(self
._combox
_fact
, 1, 2, 0, 1)
54 # Label, scale factor and entry for Y axis
55 label_yunits
= gtk
.Label(xy
[1])
56 align
= gtk
.Alignment(0, 0.5)
57 align
.add(label_yunits
)
58 table
.attach(align
, 0, 1, 1, 2)
59 self
._entry
_yunits
= gtk
.Entry()
60 self
._entry
_yunits
.set_text(units
[1])
61 self
._entry
_yunits
.set_width_chars(7)
62 self
._entry
_yunits
.set_activates_default(True)
63 table
.attach(self
._entry
_yunits
, 2, 3, 1, 2)
64 self
._comboy
_fact
= gtk
.ComboBox(self
._scale
_factors
)
65 self
._comboy
_fact
.set_active(sorted_list
.index(scale_factors
[1]))
66 cell
= gtk
.CellRendererText()
67 self
._comboy
_fact
.pack_start(cell
, True)
68 self
._comboy
_fact
.add_attribute(cell
, 'text', 1)
69 table
.attach(self
._comboy
_fact
, 1, 2, 1, 2)
70 self
._dlg
.vbox
.pack_start(table
)
77 resp
= self
._dlg
.run()
78 if resp
== gtk
.RESPONSE_ACCEPT
:
79 units
= (self
._entry
_xunits
.get_text(),
80 self
._entry
_yunits
.get_text())
81 x_factor_index
= self
._combox
_fact
.get_active_iter()
82 y_factor_index
= self
._comboy
_fact
.get_active_iter()
83 scale_factors
= [self
._scale
_factors
.get(x_factor_index
, 0)[0],
84 self
._scale
_factors
.get(y_factor_index
, 0)[0]]
86 return units
, scale_factors
88 class Enter_Range_Dialog(object):
93 def display(self
, r
, xy
, scale_factors
, units
):
94 self
._dlg
= gtk
.Dialog(_('Enter graph range'),
95 flags
=gtk
.DIALOG_NO_SEPARATOR
,
96 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
97 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
98 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
101 minmax
= [_('From'), _('To')]
103 hbox
= gtk
.HBox(False)
104 for col
in range(0, 2):
105 frame
= gtk
.Frame('')
106 frame
.get_label_widget().set_markup('<b>'+ xy
[col
] +'</b>')
107 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
108 table
= gtk
.Table(1, 3, False)
110 for row
in range(0, 2):
111 label
= gtk
.Label(minmax
[row
])
112 align_lbl
= gtk
.Alignment(0, 0.5)
114 step
= abs(float(r
[col
][0] - r
[col
][1]))/100.0
116 adj
= gtk
.Adjustment(r
[col
][row
], -1e99
, 1e99
,
117 step
, step
* 10.0, 0)
118 entry
= gtk
.SpinButton(adj
, 1,
119 int(math
.ceil(abs(math
.log10(step
)))))
120 entry
.set_activates_default(True)
121 units_label
= gtk
.Label(factors_to_names
[scale_factors
[col
]][0]
123 align_units
= gtk
.Alignment(0, 0.5)
124 align_units
.add(units_label
)
125 table
.attach(align_lbl
, 0, 1, row
, row
+ 1, xpadding
=3)
126 table
.attach(entry
, 1, 2, row
, row
+ 1, xpadding
=3)
127 table
.attach(align_units
, 2, 3, row
, row
+ 1, xpadding
=3)
128 table
.set_row_spacing(row
, 6)
129 entries_row
.append(entry
)
130 self
._entries
.append(entries_row
)
131 box
= gtk
.HBox(False)
132 box
.pack_start(table
, False, False, 12)
134 hbox
.pack_start(frame
, False, False, 0)
135 self
._dlg
.vbox
.pack_start(hbox
, False, False, 6)
141 resp
= self
._dlg
.run()
142 if resp
== gtk
.RESPONSE_ACCEPT
:
143 r
= [str(self
._entries
[0][0].get_value()),
144 str(self
._entries
[0][1].get_value()),
145 str(self
._entries
[1][0].get_value()),
146 str(self
._entries
[1][1].get_value())]
150 DEFAULT_NETLISTER_COMMAND
= 'gnetlist -g spice-sdb -O sort_mode -o %s.net %s.sch'
151 DEFAULT_SIMULATOR_COMMAND
= 'gnucap -b %s.net'
153 class Run_Netlister_and_Simulate_Dialog(object):
158 def _make_check_entry(self
, name
, do_run
, commands
, default_command
):
159 # returns a tuple (check_button, combo_box_entry)
160 combo
= gtk
.combo_box_entry_new_text()
162 commands
= [default_command
]
164 combo
.append_text(cmd
)
166 combo
.set_sensitive(do_run
)
168 btn
= gtk
.CheckButton(_('Run %s:') % name
)
169 btn
.set_active(do_run
)
170 btn
.connect('toggled', self
._check
_button
_toggled
, combo
)
173 def display(self
, actions
):
174 self
._dlg
= gtk
.Dialog(_("Run netlister and simulate"),
175 flags
=gtk
.DIALOG_NO_SEPARATOR
,
176 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
177 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
178 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
182 do_run
, commands
= actions
['run_netlister']
183 btn
, combo
= self
._make
_check
_entry
(_('netlister'), do_run
, commands
,
184 DEFAULT_NETLISTER_COMMAND
)
185 self
._ckbutton
_netl
, self
._entry
_netl
= btn
, combo
186 box
.pack_start(btn
, False, False, 12)
187 box
.pack_start(combo
, True, True)
188 self
._dlg
.vbox
.pack_start(box
, False, False, 6)
192 do_run
, commands
= actions
['run_simulator']
193 btn
, combo
= self
._make
_check
_entry
(_('simulator'), do_run
, commands
,
194 DEFAULT_SIMULATOR_COMMAND
)
195 self
._ckbutton
_sim
, self
._entry
_sim
= btn
, combo
196 box
.pack_start(btn
, False, False, 12)
197 box
.pack_start(combo
, True, True)
198 self
._dlg
.vbox
.pack_start(box
, False, False, 6)
200 group
= gtk
.SizeGroup(gtk
.SIZE_GROUP_HORIZONTAL
)
201 group
.add_widget(self
._ckbutton
_netl
)
202 group
.add_widget(self
._ckbutton
_sim
)
204 frame
= gtk
.Frame('')
205 frame
.get_label_widget().set_markup(_('<b>Options</b>'))
206 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
208 box
= gtk
.HBox(False, 12)
210 label
.set_markup(_('Run from directory:'))
211 box
.pack_start(label
, False, False, 12)
212 dialog
= gtk
.FileChooserDialog(_('Choose directory'),
214 gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
215 buttons
=(gtk
.STOCK_CANCEL
,
218 gtk
.RESPONSE_ACCEPT
))
219 dialog
.set_filename(actions
['run_from'])
220 self
._filechoose
= gtk
.FileChooserButton(dialog
)
221 box
.pack_start(self
._filechoose
)
222 vbox
.pack_start(box
, False)
224 self
._ckbutton
_upd
= gtk
.CheckButton(_('Update readers once terminated'))
225 self
._ckbutton
_upd
.set_active(actions
['update'])
226 box
.pack_start(self
._ckbutton
_upd
, False, False, 12)
227 vbox
.pack_start(box
, False, False, 6)
229 self
._dlg
.vbox
.pack_start(frame
, False, False, 6)
231 self
._dlg
.resize(400, 100)
234 def _collect_data(self
):
235 # make sure that the command to run is always the first
236 # element of the list (more recent commands are at the
237 # beginning of the list) and eliminate duplicates
238 netlister_cmds
= [row
[0] for row
in self
._entry
_netl
.get_model()]
239 if self
._entry
_netl
.get_active_text() in netlister_cmds
:
240 netlister_cmds
.remove(self
._entry
_netl
.get_active_text())
241 netlister_cmds
.insert(0, self
._entry
_netl
.get_active_text())
243 simulator_cmds
= [row
[0] for row
in self
._entry
_sim
.get_model()]
244 if self
._entry
_sim
.get_active_text() in simulator_cmds
:
245 simulator_cmds
.remove(self
._entry
_sim
.get_active_text())
246 simulator_cmds
.insert(0, self
._entry
_sim
.get_active_text())
249 actions
['run_netlister'] = (self
._ckbutton
_netl
.get_active(), netlister_cmds
)
250 actions
['run_simulator'] = (self
._ckbutton
_sim
.get_active(), simulator_cmds
)
251 actions
['update'] = self
._ckbutton
_upd
.get_active()
252 actions
['run_from'] = self
._filechoose
.get_filename()
257 if self
._dlg
.run() == gtk
.RESPONSE_ACCEPT
:
258 actions
= self
._collect
_data
()
262 def _check_button_toggled(self
, button
, entry
):
263 entry
.set_sensitive(button
.get_active())