def run(self, graphic):
window = gtk.Window()
self.__window = window
window.set_default_size(200, 200)
vbox = gtk.VBox()
window.add(vbox)
render = GtkGraphicRenderer(graphic)
self.__render = render
vbox.pack_end(render, True, True, 0)
hbox = gtk.HBox()
vbox.pack_start(hbox, False, False, 0)
smaller_zoom = gtk.Button("Zoom Out")
smaller_zoom.connect("clicked", self.__set_smaller_cb)
hbox.pack_start(smaller_zoom)
bigger_zoom = gtk.Button("Zoom In")
bigger_zoom.connect("clicked", self.__set_bigger_cb)
hbox.pack_start(bigger_zoom)
output_png = gtk.Button("Output Png")
output_png.connect("clicked", self.__output_png_cb)
hbox.pack_start(output_png)
window.connect('destroy', gtk.main_quit)
window.show_all()
#gtk.bindings_activate(gtk.main_quit, 'q', 0)
gtk.main()
python类Button()的实例源码
def __init__(self, parent):
gtk.Dialog.__init__(self, "Rename", parent, 0)
self.set_default_size(150, 100)
label1=gtk.Label()
label1.set_markup("Enter New Name")
self.newname=gtk.Entry()
box = self.get_content_area()
box.add(label1)
box.add(self.newname)
self.ok_button=gtk.Button("OK")
box.add(self.ok_button)
self.ok_button.connect("clicked",self.on_rename_ok_clicked)
self.show_all()
def make_label(self):
self.label = gtk.HBox(False, 0)
self.text_label = gtk.Label("")
self.text_label.show()
self.label.pack_start(self.text_label, 1, 1, 1)
button = gtk.Button()
button.set_relief(gtk.RELIEF_NONE)
button.set_focus_on_click(False)
icon = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
icon.show()
button.add(icon)
button.connect("clicked", lambda x: self.emit("want-close"))
button.show()
self.label.pack_start(button, 0, 0, 0)
self.label.show()
def open_file():
window = main_window('toplevel', 'Flash Player', 550, 400)
vbox = gtk.VBox()
hbox = gtk.HBox()
button = gtk.Button("????")
button.set_size_request(200, 70)
button.connect("clicked", on_open_clicked, window, vbox)
vbox.pack_start(hbox, fill=False)
hbox.pack_start(button, fill=False)
window.add(vbox)
window.show_all()
def create_collector_bbox(self, collector):
frame = gtk.Frame(collector.name)
if collector.is_enabled():
layout = gtk.BUTTONBOX_SPREAD
spacing = 10
bbox = gtk.HButtonBox()
bbox.set_border_width(1)
bbox.set_layout(layout)
bbox.set_spacing(spacing)
frame.add(bbox)
startCollectorButton = gtk.Button('Start Collector')
startCollectorButton.connect("clicked", self.startIndividualCollector, collector)
startCollectorButton.set_sensitive(not isinstance(collector, engine.collector.ManualCollector))
bbox.add(startCollectorButton)
stopCollectorButton = gtk.Button('Stop Collector')
stopCollectorButton.connect("clicked", self.stopIndividualCollector, collector)
stopCollectorButton.set_sensitive(not isinstance(collector, engine.collector.ManualCollector))
bbox.add(stopCollectorButton)
parseButton = gtk.Button('Parse Data')
parseButton.connect("clicked", self.parser, collector)
bbox.add(parseButton)
else:
label = gtk.Label("Collector Disabled")
frame.add(label)
return frame
def _setup_ui_chooser(self):
self.chooser_layout = gtk.VBox(homogeneous=False, spacing=2)
self.top_layout.pack_start(self.chooser_layout, fill=True, expand=True)
msg = ("<big><b>Choose your media source</b></big>\n"
"Click one of the buttons below to be able to "
"select what to play")
info = catota.ui.MultiLineLabel(msg)
info.show()
self.chooser_layout.pack_start(info, fill=True, expand=False)
box = gtk.VBox(homogeneous=True, spacing=5)
box.show()
for o in self.sources:
btn = gtk.Button()
btn.add(o.gui_button_contents)
btn.set_size_request(-1, 40)
btn.show()
btn.connect("clicked", self._source_activated, o)
box.pack_start(btn, fill=True, expand=False)
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_NONE)
sw.set_policy(hscrollbar_policy=gtk.POLICY_NEVER,
vscrollbar_policy=gtk.POLICY_AUTOMATIC)
sw.add_with_viewport(box)
sw.show()
self.chooser_layout.pack_start(sw, fill=True, expand=True)
# _setup_ui_chooser()
def createButton(parent, text="", stock=None, name="", gridX=0, gridY=0, sizeX=1, sizeY=1, xExpand=True, yExpand=True, handler=None):
"""Creates a button widget and adds it to a parent widget."""
if stock:
temp = gtk.Button(text, stock)
else:
temp = gtk.Button(text)
temp.set_name(name)
temp.connect("clicked", handler)
parent.attach(temp, gridX, gridX+sizeX, gridY, gridY+sizeY, xoptions=gtk.EXPAND if xExpand else 0, yoptions=gtk.EXPAND if yExpand else 0)
return temp
def _main_window_add_actions(self, button_box):
for action in self.config['main_window'].get('actions', []):
if action.get('type', 'button') == 'button':
widget = gtk.Button(label=action.get('label', 'OK'))
event = "clicked"
elif action['type'] == 'checkbox':
widget = gtk.CheckButton(label=action.get('label', '?'))
event = "toggled"
else:
raise NotImplementedError('We only have buttons atm.')
if action.get('position', 'left') in ('left', 'top'):
button_box.pack_start(widget, False, True)
elif action['position'] in ('right', 'bottom'):
button_box.pack_end(widget, False, True)
else:
raise NotImplementedError('Invalid position: %s'
% action['position'])
if action.get('op'):
def activate(o, a):
return lambda d: self._do(o, a)
widget.connect(event,
activate(action['op'], action.get('args', [])))
widget.set_sensitive(action.get('sensitive', True))
self.items[action['item']] = widget
def _init_nav_buttons(self):
box = self.nav_box
btn_list = self.nav_btn_list
btn_dict = self.nav_btn_path_dict
for i in range(10):
btn = gtk.Button()
btn.connect('clicked', self.on_nav_btn_clicked)
btn.set_can_focus(False)
btn.set_use_underline(False)
btn_list.append(btn)
box.pack_start(btn, False, False, 0)
btn_dict[btn] = ''
def __init__(self, window, title='', message=''):
self.status = False
self.dialog = gtk.Dialog(title, window, gtk.DIALOG_MODAL, ())
self.dialog.set_urgency_hint(False)
self.label = gtk.Label()
self.label.set_markup(message)
self.dialog.vbox.pack_start(self.label)
self.progress = gtk.ProgressBar()
self.progress.set_pulse_step(0.01)
self.dialog.vbox.pack_start(self.progress, False, False)
self.button = gtk.Button(_("Cancel"), gtk.STOCK_CANCEL)
self.button.connect("clicked", self.callback)
self.dialog.vbox.pack_start(self.button, False, False)
self.dialog.show_all()
def add_query_widget(container, field_names, sel_qf='title', sel_comm='contains', text=''):
hbox = gtk.HBox()
cb = gtk.combo_box_new_text()
select = 0
for i, field in enumerate(QUERY_FIELDS):
if sel_qf == field:
select = i
cb.append_text(field_names[field])
cb.set_active(select)
action_cb = gtk.combo_box_new_text()
select = 0
for i, command in enumerate(QUERY_COMMANDS):
if sel_comm == command:
select = i
action_cb.append_text(QUERY_COMMAND_NAMES[command])
action_cb.set_active(select)
entry = gtk.Entry()
entry.set_text(text)
button = gtk.Button(stock=gtk.STOCK_DELETE)
button.connect("clicked", lambda w: hbox.destroy())
hbox.pack_start(cb, expand=False)
hbox.pack_start(action_cb, expand=False)
hbox.pack_start(entry, expand=True, padding=8)
hbox.pack_start(button, expand=False, fill=False)
hbox.show_all()
container.pack_start(hbox)
gnome_connection_manager.py 文件源码
项目:gnome-connection-manager
作者: mjun
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def __init__(self, title, owner_, widget_, popup_):
gtk.HBox.__init__(self, False, 0)
self.title = title
self.owner = owner_
self.eb = gtk.EventBox()
label = self.label = gtk.Label()
self.eb.connect('button-press-event', self.popupmenu, label)
label.set_alignment(0.0, 0.5)
label.set_text(title)
self.eb.add(label)
self.pack_start(self.eb)
label.show()
self.eb.show()
close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
self.widget=widget_
self.popup = popup_
close_btn = gtk.Button()
close_btn.set_relief(gtk.RELIEF_NONE)
close_btn.connect('clicked', self.on_close_tab, owner_)
close_btn.set_size_request(image_w+7, image_h+6)
close_btn.add(close_image)
style = close_btn.get_style();
self.eb2 = gtk.EventBox()
self.eb2.add(close_btn)
self.pack_start(self.eb2, False, False)
self.eb2.show()
close_btn.show_all()
self.is_active = True
self.show()
gnome_connection_manager.py 文件源码
项目:gnome-connection-manager
作者: mjun
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def __init__(self, title, message, default_text='', modal=True, mask=False):
gtk.Dialog.__init__(self)
self.set_title(title)
self.connect("destroy", self.quit)
self.connect("delete_event", self.quit)
if modal:
self.set_modal(True)
box = gtk.VBox(spacing=10)
box.set_border_width(10)
self.vbox.pack_start(box)
box.show()
if message:
label = gtk.Label(message)
box.pack_start(label)
label.show()
self.entry = gtk.Entry()
self.entry.set_text(default_text)
self.entry.set_visibility(not mask)
box.pack_start(self.entry)
self.entry.show()
self.entry.grab_focus()
button = gtk.Button(stock=gtk.STOCK_OK)
button.connect("clicked", self.click)
self.entry.connect("activate", self.click)
button.set_flags(gtk.CAN_DEFAULT)
self.action_area.pack_start(button)
button.show()
button.grab_default()
button = gtk.Button(stock=gtk.STOCK_CANCEL)
button.connect("clicked", self.quit)
button.set_flags(gtk.CAN_DEFAULT)
self.action_area.pack_start(button)
button.show()
self.ret = None
def __init__(self, parser, max_tree_depth):
self.parser = parser
self._max_tree_depth = max_tree_depth
self.search_thread = None
self.search_lock = threading.Lock()
self.name_entry = name_entry = gtk.Entry()
name_entry.connect('activate', self.on_name_entry_activate)
search_button = self.search_button = gtk.Button(stock=gtk.STOCK_FIND)
search_button.connect('clicked', self.on_search)
search_button.set_no_show_all(True)
search_button.show()
stop_button = self.stop_button = gtk.Button(stock=gtk.STOCK_STOP)
stop_button.connect('clicked', self.stop_search)
stop_button.set_no_show_all(True)
self.progress = progress = gtk.ProgressBar()
progress.set_size_request(-1, 8)
name_box = gtk.HBox(spacing=8)
name_box.set_border_width(8)
name_box.pack_start(name_entry, True, True)
name_box.pack_start(search_button, False)
name_box.pack_start(stop_button, False)
self.store = gtk.TreeStore(str, str, str, str) # name, icon, fnstyle, info
self.treeview = treeview = self._create_treeview(self.store)
scroller = gtk.ScrolledWindow()
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroller.add(treeview)
settings_view = SettingsView(max_depth_value=max_tree_depth)
settings_view.on_max_depth_changed = self.on_max_depth_changed
extension = gtk.expander_new_with_mnemonic('_Settings')
extension.add(settings_view.view)
vbox = gtk.VBox()
vbox.pack_start(name_box, False)
vbox.pack_start(progress, False)
vbox.pack_start(scroller, True, True)
vbox.pack_start(extension, False)
self.window = window = gtk.Window()
window.set_title(Application.title)
window.set_default_size(800, 600)
window.set_icon(Application.get_icon())
window.add(vbox)
def __init__(self, parent):
gtk.Dialog.__init__(self, "About ProjectX", parent, 0)
self.set_default_size(150, 100)
label1=gtk.Label()
label1.set_markup("ProjectX lets you organize files and folders on your computer :)")
label1.set_line_wrap(True)
label = gtk.Label()
label.set_markup(" Developed by Avneet Singh Saluja, Ayudh Kumar Gupta, Ayur Jain, Ayush Garg, Ayush Rohatgi ")
label2=gtk.Label()
label2.set_markup("V 1.0")
label2.set_line_wrap(True)
box = self.get_content_area()
box.add(label1)
box.add(label2)
box.add(label)
self.ok_button=gtk.Button("OK")
box.add(self.ok_button)
self.ok_button.connect("clicked",self.closer)
self.show_all()
def __init__(self, parent):
gtk.Dialog.__init__(self, "Properties", parent, 0)
self.set_default_size(150, 100)
a=os.path.getsize(selected_path_for_prop)
a=str(a/1024000.00)
b=os.path.basename(selected_path_for_prop)
label1=gtk.Label()
label1.set_markup(" Name: "+b+" ")
label1.set_line_wrap(True)
label2=gtk.Label()
label2.set_markup(" Size: "+a+"MB ")
label2.set_line_wrap(True)
label3=gtk.Label()
label3.set_markup(" Directory: "+selected_path_for_prop+" ")
label3.set_line_wrap(True)
box = self.get_content_area()
box.add(label1)
box.add(label2)
box.add(label3)
self.ok_button=gtk.Button("OK")
box.add(self.ok_button)
self.ok_button.connect("clicked",self.closer)
self.show_all()
def __init__(self, parent):
gtk.Dialog.__init__(self, "New Folder", parent, 0)
self.set_default_size(150, 100)
label1=gtk.Label()
label1.set_markup("Enter New Folder's Name")
self.newname=gtk.Entry()
box = self.get_content_area()
box.add(label1)
box.add(self.newname)
self.ok_button=gtk.Button("OK")
box.add(self.ok_button)
self.ok_button.connect("clicked",self.on_newfolder_ok_clicked)
self.show_all()
def searchfunc(self,widget):
fileName = self.searchfile.get_text()
paths = "\n"
for root, dirs, files in os.walk('/home', topdown=False):
for name in files:
if name == fileName:
paths += " " + str(os.path.join(root, name)) + " \n\n"
for name in dirs:
if name == fileName:
paths += " " + str(os.path.join(root, name)) + " \n\n"
paths = paths[:-1]
if len(paths) > 0 :
self.popup = gtk.Window()
self.popup.set_title( "Paths" )
vbox = gtk.VBox(False,0)
hbox = gtk.HBox(False)
label = gtk.Label(paths)
label.set_line_wrap( True )
label.connect( "size-allocate",self.size_allocate)
vbox.pack_start(gtk.Label(paths),True,False,0)
closeButton = gtk.Button(" Close ")
closeButton.set_sensitive(True)
closeButton.connect("clicked",self.on_destroy)
hbox.pack_start(closeButton,True,False,0)
vbox.pack_start(hbox,True,False,10)
self.popup.add(vbox)
self.popup.set_type_hint( gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.popup.show_all()
def button_stock(stock,size):
"""
Return a button with a image from stock items.
"""
b = gtk.Button()
img = gtk.Image()
img.set_from_stock(stock,size)
b.set_image(img)
return b
def __init__(self, find_dir=False, types=[]):
gtk.HBox.__init__(self, False, 0)
self.types = types
self.filename = gtk.Entry()
self.filename.show()
self.pack_start(self.filename, 1, 1, 1)
browse = gtk.Button("...")
browse.show()
self.pack_start(browse, 0, 0, 0)
self.filename.connect("changed", self.do_changed)
browse.connect("clicked", self.do_browse, find_dir)
def make_select(self):
hbox = gtk.HBox(True, 2)
all = gtk.Button(_("All"))
all.connect("clicked", self.__select_all, True)
all.set_size_request(50, 25)
all.show()
hbox.pack_start(all, 0, 0, 0)
none = gtk.Button(_("None"))
none.connect("clicked", self.__select_all, False)
none.set_size_request(50, 25)
none.show()
hbox.pack_start(none, 0, 0, 0)
inv = gtk.Button(_("Inverse"))
inv.connect("clicked", self.__select_all, None)
inv.set_size_request(50, 25)
inv.show()
hbox.pack_start(inv, 0, 0, 0)
frame = gtk.Frame(_("Select"))
frame.show()
frame.add(hbox)
hbox.show()
return frame
def __init__(self, **args):
if "parent" in args:
parent = args["parent"]
del args["parent"]
else:
parent = None
if "cancel" in args:
cancel = args["cancel"]
del args["cancel"]
else:
cancel = None
gtk.Window.__init__(self, **args)
self.set_transient_for(parent)
self.set_modal(True)
self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
vbox = gtk.VBox(False, 2)
vbox.show()
self.add(vbox)
self.set_title(_("Clone Progress"))
self.set_resizable(False)
self.infolabel = gtk.Label(_("Cloning"))
self.infolabel.show()
vbox.pack_start(self.infolabel, 1, 1, 1)
self.progbar = gtk.ProgressBar()
self.progbar.set_fraction(0.0)
self.progbar.show()
vbox.pack_start(self.progbar, 0, 0, 0)
cancel_b = gtk.Button(_("Cancel"))
cancel_b.connect("clicked", lambda b: cancel())
cancel_b.show()
vbox.pack_start(cancel_b, 0, 0, 0)
def __init__(self, width, height):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.connect("destroy", self.destroy)
self.window.set_border_width(0)
self.window.set_size_request(width, height + 30)
self.window.set_app_paintable(True)
self.screen = self.window.get_screen()
self.rgba = self.screen.get_rgba_colormap()
self.window.set_colormap(self.rgba)
self.window.connect('expose-event', self.expose)
self.vbox = gtk.VBox(False, 5)
self.hbox = gtk.HBox(False, 3)
self.bbox = gtk.HBox(True, 3)
self.entry = gtk.Entry()
self.entry.set_max_length(0)
self.entry.set_size_request(int(width / 2), 25)
self.entry.connect("activate", self.enter_callback, self.entry)
self.spr = gtk.ToggleButton(label='spr')
self.spr.connect("toggled", self.on_button_toggled, 'spr')
self.ctrl = gtk.ToggleButton(label='ctrl')
self.ctrl.connect("toggled", self.on_button_toggled, 'ctrl')
self.alt = gtk.ToggleButton(label='alt')
self.alt.connect("toggled", self.on_button_toggled, 'alt')
self.enter = gtk.Button(label='Enter')
self.enter.connect("clicked", self.on_enter_clicked)
self.backspace = gtk.Button(label='Backspace')
self.backspace.connect("clicked", self.on_backspace_clicked)
self.shell = gtk.Button(label='R-Shell')
self.shell.connect("clicked", self.on_shell_clicked, self.entry)
self.hbox.add(self.entry)
self.bbox.add(self.spr)
self.bbox.add(self.ctrl)
self.bbox.add(self.alt)
self.bbox.add(self.enter)
self.bbox.add(self.backspace)
self.bbox.add(self.shell)
self.hbox.add(self.bbox)
self.halign = gtk.Alignment(1, 0, 1, 0)
self.halign.add(self.hbox)
self.allalign = gtk.Alignment(0, 0, 1, 1)
self.clickbox = gtk.EventBox()
self.clickbox.connect('button-press-event', self.on_click)
self.clickbox.set_visible_window(False)
self.allalign.add(self.clickbox)
self.vbox.pack_start(self.allalign, True, True, 0)
self.vbox.pack_end(self.halign, False, False, 0)
self.window.add(self.vbox)
self.window.show_all()
self.window.move(100, 100)
def __init__(self, parent, plugins):
super(PluginConfigGUI, self).__init__()
self.main_gui = parent
#TODO: Add one for compression format
self.value_type_create = {
"text": self.create_text_hbox,
"number": self.create_number_hbox,
"checkbox": self.create_checkbox_hbox,
"radio": self.create_radio_hbox,
"option": self.create_option_hbox,
"options": self.create_options_hbox,
"time": self.create_time_hbox,
"netiface": self.create_netiface_hbox,
"netifaces": self.create_netifaces_hbox,
"filepath": self.create_filepath_hbox,
"path": self.create_path_hbox
}
self.set_title("Plugin Configurations")
self.set_modal(True)
self.set_transient_for(self.main_gui)
self.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
#self.set_size_request(500, 700)
self.set_border_width(6)
self.set_resizable(False)
self.plugins = plugins
plugin_names = [plugin.name for plugin in self.plugins]
vbox_main = gtk.VBox()
hbox_plugins = gtk.HBox()
frame_plugin_confs = gtk.Frame("Plugin Configurations:")
self.vbox_plugin_main = None
label_plugins = gtk.Label("Plugin")
combobox_plugins = gtk.combo_box_new_text()
for label in plugin_names:
combobox_plugins.append_text(label)
combobox_plugins.set_active(0)
combobox_plugins.connect('changed', self.select_plugin, combobox_plugins, frame_plugin_confs)
button_close = gtk.Button("Close")
button_close.connect("clicked", self.close_plugin_config_dialog)
hbox_plugins.pack_start(label_plugins)
hbox_plugins.pack_start(combobox_plugins)
vbox_main.pack_start(hbox_plugins)
vbox_main.pack_start(frame_plugin_confs)
vbox_main.pack_start(button_close)
self.show_plugin_configs(combobox_plugins.get_active_text(), frame_plugin_confs)
self.add(vbox_main)
self.show_all()
def addNotebookPage(self, title, content, path):
area = gtk.ScrolledWindow()
area.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_ALWAYS)
area.show()
txtB = gtkSourceView.Buffer()
txtB.begin_not_undoable_action()
txtB.set_style_scheme(self.style_scheme)
language = self.getLanguage(title)
txtB.set_highlight_matching_brackets(True)
if language is not None:
txtB.set_highlight_syntax(True)
txtB.set_language(language)
txtB.set_text(content)
txtB.place_cursor(txtB.get_start_iter())
txtB.set_modified(False)
txtB.end_not_undoable_action()
text = SourceView(txtB)
text.set_tab_width(self.tabWidth)
text.set_insert_spaces_instead_of_tabs(False)
text.set_show_right_margin(True)
text.set_show_line_marks(True)
text.set_auto_indent(self.autoIndent)
text.set_show_line_numbers(self.lineNumbers)
text.show()
text.modify_font(pango.FontDescription('Monospace 10'))
area.add(text)
top = gtk.HBox()
title = gtk.Label(title)
title.show()
top.set_tooltip_text(path)
top.pack_start(title, True, True, 0)
butt = gtk.Button()
img = gtk.Image()
img.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
img.show()
butt.set_image(img)
butt.connect_object("clicked", self.closePage, area)
top.pack_end(butt, False, False, 0)
butt.show()
top.show()
self.notebook.insert_page(area, top, 0)
pages = self.notebook.get_n_pages()
self.notebook.set_current_page(0)
def __init__(self, *args, **kwargs):
self.window = gtk.Window()
self.window.set_title("Create An Image")
self.window.set_icon_from_file(os.path.join(WORKINGDIR, "data", "icon.png"))
colour = gtk.gdk.color_parse(DARKCOL)
self.window.modify_bg(gtk.STATE_NORMAL, colour)
self.vvbox = gtk.VBox()
self.table = gtk.Table(5, 5)
self.table.set_border_width(2)
self.table.set_row_spacings(2)
self.table.set_col_spacings(2)
self.buttons = {}
for y in range(5):
for x in range(5):
eb = gtk.EventBox()
i = gtk.Image()
i.set_from_file(os.path.join(WORKINGDIR, "data", "selected.png"))
i.show()
eb.add(i)
eb.hide()
eb.modify_bg(gtk.STATE_NORMAL, colour)
eb.connect_object("button-press-event", self.togglePart, (x, y))
eb2 = gtk.EventBox()
i2 = gtk.Image()
i2.set_from_file(os.path.join(WORKINGDIR, "data", "unselected.png"))
i2.show()
eb2.add(i2)
eb2.show()
eb2.modify_bg(gtk.STATE_NORMAL, colour)
eb2.connect_object("button-press-event", self.togglePart, (x, y))
self.buttons[(x, y)] = (eb, eb2)
self.table.attach(eb, x, x + 1, y, y + 1)
self.table.attach(eb2, x, x + 1, y, y + 1)
self.table.show()
self.vvbox.pack_start(self.table)
hbox = gtk.HBox()
self.confirmButton = gtk.Button("Okay")
self.confirmButton.show()
self.confirmButton.connect("clicked", self.okay)
hbox.pack_start(self.confirmButton, True, False)
cancelButton = gtk.Button("Cancel")
cancelButton.connect("clicked", self.destroy)
cancelButton.show()
hbox.pack_end(cancelButton, True, False)
hbox.show()
self.vvbox.pack_start(hbox)
self.vvbox.show()
self.window.add(self.vvbox)
self.onOkay = None
self.running = True
self.destoryed = False
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()
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
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# This is a new call, which just sets the title of our
# new window to "Hello Buttons!"
self.window.set_title("Hello Buttons!")
# Here we just set a handler for delete_event that immediately
# exits GTK.
self.window.connect("delete_event", self.delete_event)
# Sets the border width of the window.
self.window.set_border_width(10)
# We create a box to pack widgets into. This is described in detail
# in the "packing" section. The box is not really visible, it
# is just used as a tool to arrange widgets.
self.box1 = gtk.HBox(gtk.FALSE, 0)
# Put the box into the main window.
self.window.add(self.box1)
# Creates a new button with the label "Button 1".
self.button1 = gtk.Button("Button 1")
# Now when the button is clicked, we call the "callback" method
# with a pointer to "button 1" as its argument
self.button1.connect("clicked", self.callback, "button 1")
# Instead of add(), we pack this button into the invisible
# box, which has been packed into the window.
self.box1.pack_start(self.button1, gtk.TRUE, gtk.TRUE, 0)
# Always remember this step, this tells GTK that our preparation for
# this button is complete, and it can now be displayed.
self.button1.show()
# Do these same steps again to create a second button
self.button2 = gtk.Button("Button 2")
# Call the same callback method with a different argument,
# passing a pointer to "button 2" instead.
self.button2.connect("clicked", self.callback, "button 2")
self.box1.pack_start(self.button2, gtk.TRUE, gtk.TRUE, 0)
# The order in which we show the buttons is not really important, but I
# recommend showing the window last, so it all pops up at once.
self.button2.show()
self.box1.show()
self.window.show()
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# This is a new call, which just sets the title of our
# new window to "Hello Buttons!"
self.window.set_title("Hello Buttons!")
# Here we just set a handler for delete_event that immediately
# exits GTK.
self.window.connect("delete_event", self.delete_event)
# Sets the border width of the window.
self.window.set_border_width(10)
# We create a box to pack widgets into. This is described in detail
# in the "packing" section. The box is not really visible, it
# is just used as a tool to arrange widgets.
self.box1 = gtk.HBox(gtk.FALSE, 0)
# Put the box into the main window.
self.window.add(self.box1)
# Creates a new button with the label "Button 1".
self.button1 = gtk.Button("Button 1")
# Now when the button is clicked, we call the "callback" method
# with a pointer to "button 1" as its argument
self.button1.connect("clicked", self.callback, "button 1")
# Instead of add(), we pack this button into the invisible
# box, which has been packed into the window.
self.box1.pack_start(self.button1, gtk.TRUE, gtk.TRUE, 0)
# Always remember this step, this tells GTK that our preparation for
# this button is complete, and it can now be displayed.
self.button1.show()
# Do these same steps again to create a second button
self.button2 = gtk.Button("Button 2")
# Call the same callback method with a different argument,
# passing a pointer to "button 2" instead.
self.button2.connect("clicked", self.callback, "button 2")
self.box1.pack_start(self.button2, gtk.TRUE, gtk.TRUE, 0)
# The order in which we show the buttons is not really important, but I
# recommend showing the window last, so it all pops up at once.
self.button2.show()
self.box1.show()
self.window.show()