8 class Enter_Units_Dialog(object):
11 self
._entry
_xunits
= None
12 self
._entry
_yunits
= None
15 def display(self
, units
):
16 self
._dlg
= gtk
.Dialog('Enter graph units',
17 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
18 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
19 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
20 table
= gtk
.Table(2, 2, False)
21 table
.set_col_spacing(0, 12)
22 table
.set_col_spacing(1, 12)
23 # Label and entry for X axis
24 label_xunits
= gtk
.Label('X axis unit:')
25 table
.attach(label_xunits
, 0, 1, 0, 1)
26 self
._entry
_xunits
= gtk
.Entry()
27 self
._entry
_xunits
.set_text(units
[0])
28 table
.attach(self
._entry
_xunits
, 1, 2, 0, 1)
30 # Label and entry for Y axis
31 label_yunits
= gtk
.Label('Y axis unit:')
32 table
.attach(label_yunits
, 0, 1, 1, 2)
33 self
._entry
_yunits
= gtk
.Entry()
34 self
._entry
_yunits
.set_text(units
[1])
35 table
.attach(self
._entry
_yunits
, 1, 2, 1, 2)
36 self
._dlg
.vbox
.pack_start(table
)
37 self
._dlg
.set_border_width(12)
43 resp
= self
._dlg
.run()
44 if resp
== gtk
.RESPONSE_ACCEPT
:
45 units
= (self
._entry
_xunits
.get_text(),
46 self
._entry
_yunits
.get_text())
50 class Enter_Range_Dialog(object):
55 def display(self
, r
, xy
, scale_factors
, units
):
56 self
._dlg
= gtk
.Dialog('Enter graph range',
57 flags
=gtk
.DIALOG_NO_SEPARATOR
,
58 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
59 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
60 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
63 minmax
= ['From', 'To']
65 hbox
= gtk
.HBox(False)
66 for col
in range(0, 2):
68 frame
.get_label_widget().set_markup('<b>'+ xy
[col
] +'</b>')
69 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
70 table
= gtk
.Table(1, 3, False)
72 for row
in range(0, 2):
73 label
= gtk
.Label(minmax
[row
])
74 align_lbl
= gtk
.Alignment(0, 0.5)
77 entry
.set_text(str(r
[col
][row
]))
78 entry
.set_width_chars(7)
79 entry
.set_activates_default(True)
80 units_label
= gtk
.Label(scale_factors
[col
] + units
[col
])
81 align_units
= gtk
.Alignment(0, 0.5)
82 align_units
.add(units_label
)
83 table
.attach(align_lbl
, 0, 1, row
, row
+ 1, xpadding
=3)
84 table
.attach(entry
, 1, 2, row
, row
+ 1, xpadding
=3)
85 table
.attach(align_units
, 2, 3, row
, row
+ 1, xpadding
=3)
86 table
.set_row_spacing(row
, 6)
87 entries_row
.append(entry
)
88 self
._entries
.append(entries_row
)
90 box
.pack_start(table
, False, False, 12)
92 hbox
.pack_start(frame
, False, False, 0)
93 self
._dlg
.vbox
.pack_start(hbox
, False, False, 6)
99 resp
= self
._dlg
.run()
100 if resp
== gtk
.RESPONSE_ACCEPT
:
101 r
= [self
._entries
[0][0].get_text(),
102 self
._entries
[0][1].get_text(),
103 self
._entries
[1][0].get_text(),
104 self
._entries
[1][1].get_text()]
108 class Run_Netlister_and_Simulate_Dialog
:
113 def display(self
, actions
):
114 # Define functions to enable/disable entries upon toggle buttons
115 # make window a bit larger
116 self
._dlg
= gtk
.Dialog("Run netlister and simulate",
117 flags
=gtk
.DIALOG_NO_SEPARATOR
,
118 buttons
=(gtk
.STOCK_CANCEL
, gtk
.RESPONSE_REJECT
,
119 gtk
.STOCK_OK
, gtk
.RESPONSE_ACCEPT
))
120 self
._dlg
.set_default_response(gtk
.RESPONSE_ACCEPT
)
121 frame
= gtk
.Frame('')
122 frame
.get_label_widget().set_markup('<b>Netlister</b>')
123 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
125 self
._entry
_netl
= gtk
.Entry()
126 self
._entry
_netl
.set_text(actions
['run_netlister'][1])
127 self
._ckbutton
_netl
= gtk
.CheckButton("Run")
128 self
._ckbutton
_netl
.set_active(actions
['run_netlister'][0])
129 self
._ckbutton
_netl
.connect('toggled', self
._check
_button
_toggled
,
131 self
._entry
_netl
.set_editable(self
._ckbutton
_netl
.get_active())
132 box
.pack_start(self
._ckbutton
_netl
, False, False, 12)
133 box
.pack_start(self
._entry
_netl
, True, True)
135 self
._dlg
.vbox
.pack_start(frame
, False, False, 6)
137 frame
= gtk
.Frame('')
138 frame
.get_label_widget().set_markup('<b>Simulator</b>')
139 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
141 self
._entry
_sim
= gtk
.Entry()
142 self
._entry
_sim
.set_text(actions
['run_simulator'][1])
143 self
._ckbutton
_sim
= gtk
.CheckButton('Run')
144 self
._ckbutton
_sim
.set_active(actions
['run_simulator'][0])
145 self
._ckbutton
_sim
.connect('toggled', self
._check
_button
_toggled
,
147 self
._entry
_sim
.set_editable(self
._ckbutton
_sim
.get_active())
148 box
.pack_start(self
._ckbutton
_sim
, False, False, 12)
149 box
.pack_start(self
._entry
_sim
, True, True)
151 self
._dlg
.vbox
.pack_start(frame
, False, False, 6)
153 frame
= gtk
.Frame('')
154 frame
.get_label_widget().set_markup('<b>Options</b>')
155 frame
.set_shadow_type(gtk
.SHADOW_NONE
)
157 box
= gtk
.HBox(False, 12)
159 label
.set_markup('Run from directory:')
160 box
.pack_start(label
, False, False, 12)
161 dialog
= gtk
.FileChooserDialog('Run netlister and simulator from directory...',
163 gtk
.FILE_CHOOSER_ACTION_SELECT_FOLDER
,
164 buttons
=(gtk
.STOCK_CANCEL
,
167 gtk
.RESPONSE_ACCEPT
))
168 dialog
.set_filename(actions
['run_from'])
169 self
._filechoose
= gtk
.FileChooserButton(dialog
)
170 box
.pack_start(self
._filechoose
)
171 vbox
.pack_start(box
, False)
173 self
._ckbutton
_upd
= gtk
.CheckButton('Update readers once terminated')
174 self
._ckbutton
_upd
.set_active(actions
['update'])
175 box
.pack_start(self
._ckbutton
_upd
, False, False, 12)
176 vbox
.pack_start(box
, False)
178 self
._dlg
.vbox
.pack_start(frame
, False, False, 6)
180 self
._dlg
.resize(400, 100)
184 resp
= self
._dlg
.run()
185 if resp
== gtk
.RESPONSE_ACCEPT
:
187 actions
['run_netlister'] = (self
._ckbutton
_netl
.get_active(),
188 self
._entry
_netl
.get_text())
189 actions
['run_simulator'] = (self
._ckbutton
_sim
.get_active(),
190 self
._entry
_sim
.get_text())
191 actions
['update'] = self
._ckbutton
_upd
.get_active()
192 actions
['run_from'] = self
._filechoose
.get_filename()
199 def _check_button_toggled(self
, button
, entry
=None):
200 if entry
is not None:
201 entry
.set_editable(button
.get_active())
203 class TerminalWindow
:
204 def __init__(self
, prompt
, intro
, hist_file
, app_exec
):
206 self
.hist_file
= hist_file
208 # Readline configuration
209 if not os
.path
.exists(self
.hist_file
):
210 f
= open(self
.hist_file
, "w")
213 readline
.read_history_file(self
.hist_file
)
218 self
._app
_exec
= app_exec
219 self
.is_there
= False
220 self
._term
_hist
_item
= readline
.get_current_history_length() + 1
224 if self
._term
is None:
225 self
._term
= vte
.Terminal()
226 self
._term
.set_cursor_blinks(True)
227 self
._term
.set_emulation('xterm')
228 self
._term
.set_font_from_string('monospace 9')
229 self
._term
.set_scrollback_lines(1000)
231 (master
, slave
) = pty
.openpty()
232 self
._term
.set_pty(master
)
233 sys
.stdout
= os
.fdopen(slave
, "w")
235 scrollbar
= gtk
.VScrollbar()
236 scrollbar
.set_adjustment(self
._term
.get_adjustment())
239 termbox
.pack_start(self
._term
)
240 termbox
.pack_start(scrollbar
)
242 entrybox
= gtk
.HBox(False)
243 label
= gtk
.Label('Command:')
245 entry
.connect('activate', self
._entry
_activate
)
246 entry
.connect('key-press-event', self
._entry
_key
_pressed
)
247 entrybox
.pack_start(label
, False, False, 12)
248 entrybox
.pack_start(entry
, True, True, 12)
251 box
.pack_start(termbox
)
252 box
.pack_start(entrybox
)
254 cmdw
.connect('destroy', self
._destroy
)
259 def _destroy(self
, data
=None):
260 self
.is_there
= False
263 def _entry_activate(self
, entry
, data
=None):
264 if isinstance(entry
, gtk
.Entry
):
265 line
= entry
.get_text()
267 print self
.prompt
+ line
269 readline
.add_history(line
)
270 self
._term
_hist
_item
= readline
.get_current_history_length()
273 def _entry_key_pressed(self
, entry
, event
):
274 if gtk
.gdk
.keyval_name(event
.keyval
) == "Up":
275 line
= readline
.get_history_item(self
._term
_hist
_item
- 1)
277 self
._term
_hist
_item
= self
._term
_hist
_item
- 1
280 elif gtk
.gdk
.keyval_name(event
.keyval
) == "Down":
281 line
= readline
.get_history_item(self
._term
_hist
_item
+ 1)
283 self
._term
_hist
_item
= self
._term
_hist
_item
+ 1