def _setup_generalbar(self):
stock_size = gtk.ICON_SIZE_BUTTON
general_bar = gtk.HBox()
b_about = Utils.button_stock(gtk.STOCK_ABOUT,stock_size)
b_to_gif = Utils.button_stock(gtk.STOCK_CONVERT,stock_size)
b_to_sprite = Utils.button_stock(gtk.STOCK_MISSING_IMAGE,stock_size)
# TODO implement export button
b_quit = Utils.button_stock(gtk.STOCK_QUIT,stock_size)
# callbacks
b_quit.connect('clicked',self.destroy)
b_about.connect('clicked',self.on_about)
b_to_gif.connect('clicked',self.create_formated_version,'gif')
b_to_sprite.connect('clicked',self.create_formated_version,'spritesheet')
# tooltips
b_about.set_tooltip_text("About FAnim")
b_quit.set_tooltip_text("Exit")
b_to_gif.set_tooltip_text("Create a formated Image to export as gif animation")
b_to_sprite.set_tooltip_text("Create a formated Image to export as spritesheet")
# add to the disable on play list
w = [b_about, b_to_gif,b_to_sprite, b_quit]
map(lambda x: self.widgets_to_disable.append(x),w)
# packing everything in gbar
map(lambda x: general_bar.pack_start(x,False,False,0),w)
return general_bar
python类HBox()的实例源码
def make_status_bar(self):
box = gtk.HBox(False, 2)
self.sb_general = gtk.Statusbar()
self.sb_general.set_has_resize_grip(False)
self.sb_general.show()
box.pack_start(self.sb_general, 1, 1, 1)
self.sb_radio = gtk.Statusbar()
self.sb_radio.set_has_resize_grip(True)
self.sb_radio.show()
box.pack_start(self.sb_radio, 1, 1, 1)
box.show()
return box
def _build_ui(self):
self._display = gtk.Table(20, 2)
self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
self._tree = gtk.TreeView(self._store)
rend = gtk.CellRendererText()
tvc = gtk.TreeViewColumn('Element', rend, text=0)
self._tree.append_column(tvc)
self._tree.connect('button_press_event', self._tree_click)
self._tree.set_size_request(200, -1)
self.root = gtk.HBox(False, 3)
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
sw.add(self._tree)
sw.show()
self.root.pack_start(sw, 0, 0, 0)
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
sw.add_with_viewport(self._display)
sw.show()
self.root.pack_start(sw, 1, 1, 1)
self._tree.show()
self._display.show()
self.root.show()
def connect(self, signame, *args):
if signame == "item-toggled":
self.__toggle_connected = True
gtk.HBox.connect(self, signame, *args)
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 __init__(self, first_fixed=False, width=8):
gtk.HBox.__init__(self, False, 2)
self.first_fixed = first_fixed
self.listw = None
self.pack_start(self.make_list(width), 1, 1, 1)
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 make_controls(self):
hbox = gtk.HBox(False, 2)
hbox.pack_start(self.make_select(), 0, 0, 0)
hbox.pack_start(self.make_adjust(), 0, 0, 0)
# hbox.pack_start(self.make_options(), 0, 0, 0)
hbox.show()
return hbox
def __init__(self, rthread):
super(SettingsEditor, self).__init__(rthread)
# The main box
self.root = gtk.HBox(False, 0)
# The pane
paned = gtk.HPaned()
paned.show()
self.root.pack_start(paned, 1, 1, 0)
# The selection tree
self._store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_INT)
self._view = gtk.TreeView(self._store)
self._view.get_selection().connect("changed", self._view_changed_cb)
self._view.append_column(
gtk.TreeViewColumn("", gtk.CellRendererText(), text=0))
self._view.show()
scrolled_window = gtk.ScrolledWindow()
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled_window.add_with_viewport(self._view)
scrolled_window.set_size_request(200, -1)
scrolled_window.show()
paned.pack1(scrolled_window)
# The settings notebook
self._notebook = gtk.Notebook()
self._notebook.set_show_tabs(False)
self._notebook.set_show_border(False)
self._notebook.show()
paned.pack2(self._notebook)
self._changed = False
self._settings = None
job = common.RadioJob(self._get_settings_cb, "get_settings")
job.set_desc("Getting radio settings")
self.rthread.submit(job)
def make_radio_sel(self):
f = gtk.Frame("Radio")
hbox = gtk.HBox(False, 2)
hbox.set_border_width(2)
self.w_radio = make_choice(RADIOS, False, RADIOS[0])
self.w_radio.connect("changed", self.select_radio)
self.tips.set_tip(self.w_radio, "Select radio model")
self.w_radio.show()
hbox.pack_start(self.w_radio, 1, , )
l = gtk.Label(" on port ")
l.show()
hbox.pack_start(l, 0, , )
ports = platform.get_platform().list_serial_ports()
if len(ports) > 0:
default = ports[0]
else:
default = None
self.w_port = make_choice(ports, True, default)
self.w_port.connect("changed", self.select_radio)
self.tips.set_tip(self.w_port, "Select serial port")
self.w_port.show()
hbox.pack_start(self.w_port, 1, , )
f.add(hbox)
hbox.show()
f.show()
return f
def make_image_ctl(self):
self.w_imgframe = gtk.Frame("Image")
vbox = gtk.VBox(False, 2)
vbox.set_border_width(2)
self.w_imginfo = gtk.Label("No image")
self.w_imginfo.show()
vbox.pack_start(self.w_imginfo, 0, , )
hbox = gtk.HBox(True, 2)
hbox.set_border_width(2)
self.w_dli = StdButton("Download")
self.w_dli.connect("clicked", lambda x: self.fn_download())
self.tips.set_tip(self.w_dli, "Download image from radio")
self.w_dli.show()
hbox.pack_start(self.w_dli, 0, , )
self.w_uli = StdButton("Upload")
self.w_uli.set_sensitive(False)
self.w_uli.connect("clicked", lambda x: self.fn_upload())
self.tips.set_tip(self.w_uli, "Upload image to radio")
self.w_uli.show()
hbox.pack_start(self.w_uli, 0, , )
hbox.show()
vbox.pack_start(hbox, 0, , )
vbox.show()
self.w_imgframe.add(vbox)
self.w_imgframe.show()
self.w_imgframe.set_sensitive(False)
return self.w_imgframe
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 __init__(self, inifile, width, height):
gobject.GObject.__init__(self)
super(HazzyGremlin, self).__init__(inifile)
self.width = width
self.height = height
self.percent = 0
self.mouse_mode = None
self.zoom_in_pressed = False
self.zoom_out_pressed = False
self.set_display_units('in')
# Gremlin width = width - 40 to allow room for the controls
self.set_size_request(self.width - 40, self.height)
# Add gremlin back-plot
self.gremlin_view = gtk.HBox()
fixed = gtk.Fixed()
fixed.put(self, 0, 0)
self.gremlin_view.add(fixed)
self.connect('button_press_event', self.on_gremlin_clicked)
# Add touchscreen controls
gladefile = os.path.join(UIDIR, 'controls.glade')
self.builder = gtk.Builder()
self.builder.add_from_file(gladefile)
self.builder.connect_signals(self)
controls = self.builder.get_object('controls')
controls.set_size_request(40, self.height)
self.gremlin_view.add(controls)
# Add progress label
self.label = gtk.Label()
self.label.modify_font(pango.FontDescription('FreeSans 11'))
self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.Color('White'))
labelbox = gtk.EventBox()
labelbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color('Black'))
labelbox.set_size_request(-1, 20)
labelbox.add(self.label)
fixed.put(labelbox, 0 , self.height - 20)
# def fileloading(self, current_line):
# self.progressbar.show()
# percent = current_line * 100 / self.line_count
# if self.percent != percent:
# self.percent = percent
# msg = "Generating preview {}%".format(self.percent)
# self.progressbar.set_text(msg)
# self.progressbar.set_fraction(self.percent / 100)
# log.debug(msg)
# self.emit('loading_progress', percent)
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()
def __init__(self):
# Create a new window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
# Set the title of the window to "Graphic User Interface"
self.window.set_title("Graphic User Interface")
# Create a handler for delete_event that immediately quits GTK.
self.window.connect("delete_event", self.delete_event)
# Set the border width of the window.
self.window.set_border_width(6)
# Create a box to pack the widgets into. The box is an invisible
# container, which is used to arrange the widgets inside it.
self.box1 = gtk.HBox(gtk.FALSE, 0)
# Put the box into the main window.
self.window.add(self.box1)
# Create a new button with the label "Hello".
self.button1 = gtk.Button("Hello")
# Now when the button is clicked, we call the self.callback method
# with a pointer to "the Hello button" as its argument.
self.button1.connect("clicked", self.callback, "the Hello button")
# 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 to actually display the
# button.
self.button1.show()
# Do these same steps again to create a second button
self.button2 = gtk.Button("Quit")
# This time, delete_event is called and the window exits.
self.button2.connect("clicked", self.delete_event, "the Quit button")
self.box1.pack_start(self.button2, gtk.TRUE, gtk.TRUE, 0)
# The order in which the buttons are shown is not really important,
# but it is recommended to show the window last, so that everything
# displays at once.
self.button2.show()
self.box1.show()
self.window.show()