10 from oscopy
import factors_to_names
, abbrevs_to_factors
12 class Enter_Units_Dialog(object):
15 self
._entry
_xunits
= None
16 self
._entry
_yunits
= None
17 self
._scale
_factors
= gtk
.ListStore(gobject
.TYPE_STRING
,
19 sorted_list
= factors_to_names
.keys()
21 for factor
in sorted_list
:
22 self
._scale
_factors
.append((factors_to_names
[factor
][0],
23 factors_to_names
[factor
][1]))
25 def display(self
, units
, xy
, scale_factors
):
27 sorted_list
= factors_to_names
.keys()
30 self
._dlg
= gtk
.Dialog('Enter graph units',
31 flags
=gtk
.DIALOG_NO_SEPARATOR
,
32 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
33 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
34 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
35 table
= gtk
.Table(2, 3, False)
36 table
.set_col_spacing(0, 12)
37 table
.set_col_spacing(1, 12)
38 # Label, scale factor and entry for X axis
39 label_xunits
= gtk
.Label(xy
[0])
40 align
= gtk
.Alignment(0, 0.5)
41 align
.add(label_xunits
)
42 table
.attach(align
, 0, 1, 0, 1)
43 self
._entry
_xunits
= gtk
.Entry()
44 self
._entry
_xunits
.set_text(units
[0])
45 self
._entry
_xunits
.set_width_chars(7)
46 self
._entry
_xunits
.set_activates_default(True)
47 table
.attach(self
._entry
_xunits
, 2, 3, 0, 1)
48 self
._combox
_fact
= gtk
.ComboBox(self
._scale
_factors
)
49 self
._combox
_fact
.set_active(sorted_list
.index(scale_factors
[0]))
50 cell
= gtk
.CellRendererText()
51 self
._combox
_fact
.pack_start(cell
, True)
52 self
._combox
_fact
.add_attribute(cell
, 'text', 1)
53 table
.attach(self
._combox
_fact
, 1, 2, 0, 1)
55 # Label, scale factor and entry for Y axis
56 label_yunits
= gtk
.Label(xy
[1])
57 align
= gtk
.Alignment(0, 0.5)
58 align
.add(label_yunits
)
59 table
.attach(align
, 0, 1, 1, 2)
60 self
._entry
_yunits
= gtk
.Entry()
61 self
._entry
_yunits
.set_text(units
[1])
62 self
._entry
_yunits
.set_width_chars(7)
63 self
._entry
_yunits
.set_activates_default(True)
64 table
.attach(self
._entry
_yunits
, 2, 3, 1, 2)
65 self
._comboy
_fact
= gtk
.ComboBox(self
._scale
_factors
)
66 self
._comboy
_fact
.set_active(sorted_list
.index(scale_factors
[1]))
67 cell
= gtk
.CellRendererText()
68 self
._comboy
_fact
.pack_start(cell
, True)
69 self
._comboy
_fact
.add_attribute(cell
, 'text', 1)
70 table
.attach(self
._comboy
_fact
, 1, 2, 1, 2)
71 self
._dlg
.vbox
.pack_start(table
)
78 resp
= self
._dlg
.run()
79 if resp
== gtk
.RESPONSE_ACCEPT
:
80 units
= (self
._entry
_xunits
.get_text(),
81 self
._entry
_yunits
.get_text())
82 x_factor_index
= self
._combox
_fact
.get_active_iter()
83 y_factor_index
= self
._comboy
_fact
.get_active_iter()
84 scale_factors
= [self
._scale
_factors
.get(x_factor_index
, 0)[0],
85 self
._scale
_factors
.get(y_factor_index
, 0)[0]]
87 return units
, scale_factors
89 class Enter_Range_Dialog(object):
94 def display(self
, r
, xy
, scale_factors
, units
):
95 self
._dlg
= gtk
.Dialog('Enter graph range',
96 flags
=gtk
.DIALOG_NO_SEPARATOR
,
97 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
98 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
99 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
102 minmax
= ['From', 'To']
104 hbox
= gtk
.HBox(False)
105 for col
in range(0, 2):
106 frame
= gtk
.Frame('')
107 frame
.get_label_widget().set_markup('<b>'+ xy
[col
] +'</b>')
108 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
109 table
= gtk
.Table(1, 3, False)
111 for row
in range(0, 2):
112 label
= gtk
.Label(minmax
[row
])
113 align_lbl
= gtk
.Alignment(0, 0.5)
115 step
= abs(float(r
[col
][0] - r
[col
][1]))/100.0
117 adj
= gtk
.Adjustment(r
[col
][row
], -1e99
, 1e99
,
118 step
, step
* 10.0, 0)
119 entry
= gtk
.SpinButton(adj
, 1,
120 int(math
.ceil(abs(math
.log10(step
)))))
121 entry
.set_activates_default(True)
122 units_label
= gtk
.Label(factors_to_names
[scale_factors
[col
]][0]
124 align_units
= gtk
.Alignment(0, 0.5)
125 align_units
.add(units_label
)
126 table
.attach(align_lbl
, 0, 1, row
, row
+ 1, xpadding
=3)
127 table
.attach(entry
, 1, 2, row
, row
+ 1, xpadding
=3)
128 table
.attach(align_units
, 2, 3, row
, row
+ 1, xpadding
=3)
129 table
.set_row_spacing(row
, 6)
130 entries_row
.append(entry
)
131 self
._entries
.append(entries_row
)
132 box
= gtk
.HBox(False)
133 box
.pack_start(table
, False, False, 12)
135 hbox
.pack_start(frame
, False, False, 0)
136 self
._dlg
.vbox
.pack_start(hbox
, False, False, 6)
142 resp
= self
._dlg
.run()
143 if resp
== gtk
.RESPONSE_ACCEPT
:
144 r
= [str(self
._entries
[0][0].get_value()),
145 str(self
._entries
[0][1].get_value()),
146 str(self
._entries
[1][0].get_value()),
147 str(self
._entries
[1][1].get_value())]
151 DEFAULT_NETLISTER_COMMAND
= 'gnetlist -g spice-sdb -s -o %s.net %s.sch'
152 DEFAULT_SIMULATOR_COMMAND
= 'gnucap -b %s.net'
154 class Run_Netlister_and_Simulate_Dialog(object):
159 def _make_check_entry(self
, name
, do_run
, commands
, default_command
):
160 # returns a tuple (check_button, combo_box_entry)
161 combo
= gtk
.combo_box_entry_new_text()
163 commands
= [default_command
]
165 combo
.append_text(cmd
)
167 combo
.set_sensitive(do_run
)
169 btn
= gtk
.CheckButton('Run %s:' % name
)
170 btn
.set_active(do_run
)
171 btn
.connect('toggled', self
._check
_button
_toggled
, combo
)
174 def display(self
, actions
):
175 self
._dlg
= gtk
.Dialog("Run netlister and simulate",
176 flags
=gtk
.DIALOG_NO_SEPARATOR
,
177 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
178 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
179 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
183 do_run
, commands
= actions
['run_netlister']
184 btn
, combo
= self
._make
_check
_entry
('netlister', do_run
, commands
,
185 DEFAULT_NETLISTER_COMMAND
)
186 self
._ckbutton
_netl
, self
._entry
_netl
= btn
, combo
187 box
.pack_start(btn
, False, False, 12)
188 box
.pack_start(combo
, True, True)
189 self
._dlg
.vbox
.pack_start(box
, False, False, 6)
193 do_run
, commands
= actions
['run_simulator']
194 btn
, combo
= self
._make
_check
_entry
('simulator', do_run
, commands
,
195 DEFAULT_SIMULATOR_COMMAND
)
196 self
._ckbutton
_sim
, self
._entry
_sim
= btn
, combo
197 box
.pack_start(btn
, False, False, 12)
198 box
.pack_start(combo
, True, True)
199 self
._dlg
.vbox
.pack_start(box
, False, False, 6)
201 group
= gtk
.SizeGroup(gtk
.SIZE_GROUP_HORIZONTAL
)
202 group
.add_widget(self
._ckbutton
_netl
)
203 group
.add_widget(self
._ckbutton
_sim
)
205 frame
= gtk
.Frame('')
206 frame
.get_label_widget().set_markup('<b>Options</b>')
207 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
209 box
= gtk
.HBox(False, 12)
211 label
.set_markup('Run from directory:')
212 box
.pack_start(label
, False, False, 12)
213 dialog
= gtk
.FileChooserDialog('Choose directory',
215 gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
216 buttons
=(gtk
.STOCK_CANCEL
,
219 gtk
.RESPONSE_ACCEPT
))
220 dialog
.set_filename(actions
['run_from'])
221 self
._filechoose
= gtk
.FileChooserButton(dialog
)
222 box
.pack_start(self
._filechoose
)
223 vbox
.pack_start(box
, False)
225 self
._ckbutton
_upd
= gtk
.CheckButton('Update readers once terminated')
226 self
._ckbutton
_upd
.set_active(actions
['update'])
227 box
.pack_start(self
._ckbutton
_upd
, False, False, 12)
228 vbox
.pack_start(box
, False, False, 6)
230 self
._dlg
.vbox
.pack_start(frame
, False, False, 6)
232 self
._dlg
.resize(400, 100)
235 def _collect_data(self
):
236 # make sure that the command to run is always the first
237 # element of the list (more recent commands are at the
238 # beginning of the list) and eliminate duplicates
239 netlister_cmds
= [row
[0] for row
in self
._entry
_netl
.get_model()]
240 if self
._entry
_netl
.get_active_text() in netlister_cmds
:
241 netlister_cmds
.remove(self
._entry
_netl
.get_active_text())
242 netlister_cmds
.insert(0, self
._entry
_netl
.get_active_text())
244 simulator_cmds
= [row
[0] for row
in self
._entry
_sim
.get_model()]
245 if self
._entry
_sim
.get_active_text() in simulator_cmds
:
246 simulator_cmds
.remove(self
._entry
_sim
.get_active_text())
247 simulator_cmds
.insert(0, self
._entry
_sim
.get_active_text())
250 actions
['run_netlister'] = (self
._ckbutton
_netl
.get_active(), netlister_cmds
)
251 actions
['run_simulator'] = (self
._ckbutton
_sim
.get_active(), simulator_cmds
)
252 actions
['update'] = self
._ckbutton
_upd
.get_active()
253 actions
['run_from'] = self
._filechoose
.get_filename()
258 if self
._dlg
.run() == gtk
.RESPONSE_ACCEPT
:
259 actions
= self
._collect
_data
()
263 def _check_button_toggled(self
, button
, entry
):
264 entry
.set_sensitive(button
.get_active())
266 class TerminalWindow(gtk
.Window
):
267 def __init__(self
, prompt
, intro
, hist_file
, app_exec
):
268 gtk
.Window
.__init
__(self
)
270 self
.hist_file
= hist_file
272 # Readline configuration
273 if not os
.path
.exists(self
.hist_file
):
274 f
= open(self
.hist_file
, "w")
277 readline
.read_history_file(self
.hist_file
)
282 self
._app
_exec
= app_exec
283 self
._term
_hist
_item
= readline
.get_current_history_length() + 1
287 if self
._term
is None:
288 self
._term
= vte
.Terminal()
289 self
._term
.set_cursor_blinks(True)
290 self
._term
.set_emulation('xterm')
291 self
._term
.set_font_from_string('monospace 9')
292 self
._term
.set_scrollback_lines(1000)
293 self
._term
.connect('focus-in-event', self
._term
_focus
_in
)
294 master
, slave
= pty
.openpty()
295 self
._term
.set_pty(master
)
298 sys
.stdout
= sys
.stderr
= os
.fdopen(slave
, "w")
301 scrollbar
= gtk
.VScrollbar()
302 scrollbar
.set_adjustment(self
._term
.get_adjustment())
305 termbox
.pack_start(self
._term
)
306 termbox
.pack_start(scrollbar
)
308 entrybox
= gtk
.HBox(False)
309 label
= gtk
.Label('Command:')
310 self
._entry
= gtk
.Entry()
311 self
._entry
.connect('activate', self
._entry
_activate
)
312 self
._entry
.connect('key-press-event', self
._entry
_key
_pressed
)
313 entrybox
.pack_start(label
, False, False, 12)
314 entrybox
.pack_start(self
._entry
, True, True, 12)
317 box
.pack_start(termbox
)
318 box
.pack_start(entrybox
)
322 def _term_focus_in(self
, widget
, event
):
323 self
._entry
.grab_focus()
325 def _entry_activate(self
, entry
, data
=None):
326 if isinstance(entry
, gtk
.Entry
):
327 line
= entry
.get_text()
329 print self
.prompt
+ line
331 readline
.add_history(line
)
332 self
._term
_hist
_item
= readline
.get_current_history_length() + 1
335 def _entry_key_pressed(self
, entry
, event
):
336 if gtk
.gdk
.keyval_name(event
.keyval
) == "Up":
337 line
= readline
.get_history_item(self
._term
_hist
_item
- 1)
339 self
._term
_hist
_item
= self
._term
_hist
_item
- 1
342 elif gtk
.gdk
.keyval_name(event
.keyval
) == "Down":
343 line
= readline
.get_history_item(self
._term
_hist
_item
+ 1)
345 self
._term
_hist
_item
= self
._term
_hist
_item
+ 1