def setup_gui_preferences(self):
self.player_path = gtk.Entry()
self.player_params = gtk.Entry()
self.player_ao_model = gtk.ListStore(str)
self.player_ao = gtk.ComboBox(self.player_ao_model)
cell = gtk.CellRendererText()
self.player_ao.pack_start(cell, True)
self.player_ao.add_attribute(cell, "text", 0)
for t in ("esd", "gst"):
self.player_ao_model.append((t,))
self.player_acodec_model = gtk.ListStore(str)
self.player_acodec = gtk.ComboBox(self.player_acodec_model)
cell = gtk.CellRendererText()
self.player_acodec.pack_start(cell, True)
self.player_acodec.add_attribute(cell, "text", 0)
for t in ("ffmpeg", "dspmp3"):
self.player_acodec_model.append((t,))
hbox = gtk.HBox(homogeneous=False, spacing=2)
btn = gtk.Button(stock=gtk.STOCK_OPEN)
hbox.pack_start(self.player_path, fill=True, expand=True)
hbox.pack_start(btn, fill=True, expand=False)
btn.connect("clicked", self._choose_mplayer_path)
hbox.show_all()
wids = ("MPlayer",
("Path:", hbox),
("Parameters:", self.player_params),
("Audio Output:", self.player_ao),
("Audio Codec:", self.player_acodec),
)
self.gui_preferences = wids
# setup_gui_preferences()
python类Entry()的实例源码
def ask(self, callback):
self.callback = callback
root = Tk.Tk()
self._frame = Tk.Frame(root)
self._frame.pack()
box = Tk.Frame(self._frame)
label = Tk.Label(box, text="Preamble file:")
label.pack(pady=2, padx=5, side="left", anchor="w")
self._preamble = Tk.Entry(box)
self._preamble.pack(expand=True, fill="x", pady=2, padx=5, side="right")
self._preamble.insert(Tk.END, self.preamble_file)
box.pack(fill="x", expand=True)
box = Tk.Frame(self._frame)
label = Tk.Label(box, text="Scale factor:")
label.pack(pady=2, padx=5, side="left", anchor="w")
self._scale = Tk.Scale(box, orient="horizontal", from_=0.1, to=10, resolution=0.1)
self._scale.pack(expand=True, fill="x", pady=2, padx=5, anchor="e")
if self.scale_factor is not None:
self._scale.set(self.scale_factor)
else:
self._scale.set(1.0)
box.pack(fill="x", expand=True)
label = Tk.Label(self._frame, text="Text:")
label.pack(pady=2, padx=5, anchor="w")
self._text = Tk.Text(self._frame)
self._text.pack(expand=True, fill="both", pady=5, padx=5)
self._text.insert(Tk.END, self.text)
box = Tk.Frame(self._frame)
self._btn = Tk.Button(box, text="OK", command=self.cb_ok)
self._btn.pack(ipadx=30, ipady=4, pady=5, padx=5, side="left")
self._cancel = Tk.Button(box, text="Cancel", command=self.cb_cancel)
self._cancel.pack(ipadx=30, ipady=4, pady=5, padx=5, side="right")
box.pack(expand=False)
root.mainloop()
self.callback(self.text, self.preamble_file, self.scale_factor)
return self.text, self.preamble_file, self.scale_factor
gnome_connection_manager.py 文件源码
项目:gnome-connection-manager
作者: mjun
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def addParam(self, name, field, ptype, *args):
x = self.tblGeneral.rows
self.tblGeneral.rows += 1
value = eval(field)
if ptype==bool:
obj = gtk.CheckButton()
obj.set_label(name)
obj.set_active(value)
obj.set_alignment(0, 0.5)
obj.show()
obj.field=field
self.tblGeneral.attach(obj, 0, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
elif ptype==int:
obj = gtk.SpinButton(climb_rate=10)
if len(args)==2:
obj.set_range(args[0], args[1])
obj.set_increments(1, 10)
obj.set_numeric(True)
obj.set_value(value)
obj.show()
obj.field=field
lbl = gtk.Label(name)
lbl.set_alignment(0, 0.5)
lbl.show()
self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
elif ptype==list:
obj = gtk.combo_box_new_text()
for s in args[0]:
obj.append_text(s)
obj.set_active(value)
obj.show()
obj.field=field
lbl = gtk.Label(name)
lbl.set_alignment(0, 0.5)
lbl.show()
self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
else:
obj = gtk.Entry()
obj.set_text(value)
obj.show()
obj.field=field
lbl = gtk.Label(name)
lbl.set_alignment(0, 0.5)
lbl.show()
self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0)
self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)
def do_repeaterbook_proximity_prompt(self):
default_band = "--All--"
try:
code = int(CONF.get("band", "repeaterbook"))
for k, v in RB_BANDS.items():
if code == v:
default_band = k
break
except:
pass
fields = {"1Location": (gtk.Entry(), lambda x: x.get_text()),
"2Distance": (gtk.Entry(), lambda x: x.get_text()),
"3Band": (miscwidgets.make_choice(
sorted(RB_BANDS.keys(), key=key_bands),
False, default_band),
lambda x: RB_BANDS[x.get_active_text()]),
}
d = inputdialog.FieldDialog(title=_("RepeaterBook Query"),
parent=self)
for k in sorted(fields.keys()):
d.add_field(k[1:], fields[k][0])
if isinstance(fields[k][0], gtk.Entry):
fields[k][0].set_text(
CONF.get(k[1:].lower(), "repeaterbook") or "")
while d.run() == gtk.RESPONSE_OK:
valid = True
for k, (widget, fn) in fields.items():
try:
CONF.set(k[1:].lower(), str(fn(widget)), "repeaterbook")
continue
except:
pass
common.show_error("Invalid value for %s" % k[1:])
valid = False
break
if valid:
d.destroy()
return True
d.destroy()
return False
def do_przemienniki_prompt(self):
d = inputdialog.FieldDialog(title='przemienniki.net query',
parent=self)
fields = {
"Country":
(miscwidgets.make_choice(
['at', 'bg', 'by', 'ch', 'cz', 'de', 'dk', 'es', 'fi',
'fr', 'hu', 'it', 'lt', 'lv', 'no', 'pl', 'ro', 'se',
'sk', 'ua', 'uk'], False),
lambda x: str(x.get_active_text())),
"Band":
(miscwidgets.make_choice(['10m', '4m', '6m', '2m', '70cm',
'23cm', '13cm', '3cm'], False, '2m'),
lambda x: str(x.get_active_text())),
"Mode":
(miscwidgets.make_choice(['fm', 'dv'], False),
lambda x: str(x.get_active_text())),
"Only Working":
(miscwidgets.make_choice(['', 'yes'], False),
lambda x: str(x.get_active_text())),
"Latitude": (gtk.Entry(), lambda x: float(x.get_text())),
"Longitude": (gtk.Entry(), lambda x: float(x.get_text())),
"Range": (gtk.Entry(), lambda x: int(x.get_text())),
}
for name in sorted(fields.keys()):
value, fn = fields[name]
d.add_field(name, value)
while d.run() == gtk.RESPONSE_OK:
query = "http://przemienniki.net/export/chirp.csv?"
args = []
for name, (value, fn) in fields.items():
if isinstance(value, gtk.Entry):
contents = value.get_text()
else:
contents = value.get_active_text()
if contents:
try:
_value = fn(value)
except ValueError:
common.show_error(_("Invalid value for %s") % name)
query = None
continue
args.append("=".join((name.replace(" ", "").lower(),
contents)))
query += "&".join(args)
LOG.debug(query)
d.destroy()
return query
d.destroy()
return query
def make_file_ctl(self):
self.w_fileframe = gtk.Frame("File")
vbox = gtk.VBox(False, 2)
vbox.set_border_width(2)
hbox = gtk.HBox(False, 2)
hbox.set_border_width(2)
l = gtk.Label("File")
l.show()
hbox.pack_start(l, 0, , )
self.w_filename = gtk.Entry()
self.w_filename.connect("changed", self.file_changed)
self.tips.set_tip(self.w_filename, "Path to CSV file")
self.w_filename.show()
hbox.pack_start(self.w_filename, 1, , )
bb = StdButton("Browse")
bb.connect("clicked", self.pick_file)
bb.show()
hbox.pack_start(bb, 0, , )
hbox.show()
vbox.pack_start(hbox, 0, , )
hbox = gtk.HBox(True, 2)
hbox.set_border_width(2)
def export_handler(x):
return self.fn_eport(self.w_filename.get_text())
self.w_export = StdButton("Export")
self.w_export.set_sensitive(False)
self.w_export.connect("clicked", export_handler)
self.tips.set_tip(self.w_export,
"Export radio memories to CSV file")
self.w_export.show()
hbox.pack_start(self.w_export, 0, , )
def import_handler(x):
return self.fn_iport(self.w_filename.get_text())
self.w_import = StdButton("Import")
self.w_import.set_sensitive(False)
self.w_import.connect("clicked", import_handler)
self.tips.set_tip(self.w_import,
"Import radio memories from CSV file")
self.w_import.show()
hbox.pack_start(self.w_import, 0, , )
hbox.show()
vbox.pack_start(hbox, 0, , )
vbox.show()
self.w_fileframe.add(vbox)
self.w_fileframe.show()
return self.w_fileframe