def generate_widget(self, item):
if isinstance(item, Separator):
# Ignored here
return None
elif item.id is None:
# Dummies are ignored as well
return None
else:
icon_file, has_colors = find_icon(item.icon, False)
if icon_file:
# Gridmenu hides label when icon is displayed
widget = Gtk.Button()
widget.set_relief(Gtk.ReliefStyle.NONE)
widget.set_name("osd-menu-item-big-icon")
if isinstance(item, Submenu):
item.callback = self.show_submenu
icon = MenuIcon(icon_file, has_colors)
widget.add(icon)
return widget
else:
return Menu.generate_widget(self, item)
python类Button()的实例源码
def setup_widgets(self):
Editor.setup_widgets(self)
cbButtonChooser = self.builder.get_object("cbButtonChooser")
cbButtonChooser.set_row_separator_func( lambda model, iter : model.get_value(iter, 0) is None )
b = lambda a : self.builder.get_object(a)
self.action_widgets = (
# Order goes: Grid, 1st Action Button, Clear Button
# 1st group, 'pressed'
( b('grActions'), b('btDefault'), b('btClearDefault') ),
# 2nd group, 'hold'
( b('grHold'), b('btHold'), b('btClearHold') ),
# 2nd group, 'double-click'
( b('grDoubleClick'), b('btDoubleClick'), b('btClearDoubleClick') ),
)
headerbar(self.builder.get_object("header"))
def do_settings(self):
dialog = FunctionConfigureDialog(self.get_toplevel(), self.configuration, self.channels)
response = dialog.run()
if response == Gtk.ResponseType.OK:
ch = self.hbox.get_children()
for c in ch:
self.hbox.remove(c)
c.destroy()
for func in self.configuration["functions"]:
button = Gtk.Button(func["label"])
button.connect("clicked", self.on_button_clicked)
button.brick_function = func
self.hbox.pack_start(button, True, True, 0)
self.label.set_text(self.configuration["group"])
self.show_all()
dialog.destroy()
return True
else:
dialog.destroy()
return False
def on_prop_button_clicked(self, button):
if self.m_t.q_status != self.QSTATUS_NEW:
return
g = self.m_t.guess_property(button.m_property_name,
button.m_property_value)
if g:
self.g_flashbar.flash(_("Correct"))
for btn in self.g_atable.get_children():
if not isinstance(btn, Gtk.Button):
continue
if btn.m_property_name == button.m_property_name \
and btn.m_property_value == button.m_property_value:
btn.get_children()[0].set_name("BoldText")
break
if g == self.m_t.ALL_CORRECT:
self.all_guessed_correct()
else:
self.g_flashbar.flash(_("Wrong"))
def on_start_practise(self):
super(Gui, self).on_start_practise()
self.g_music_displayer.clear()
[btn.destroy() for btn in self.g_number_box.get_children()]
for n in self.m_t.m_P.header.interval_number:
xgettext_ignore = _i
b = Gtk.Button(xgettext_ignore("interval|%s" % mpd.interval.number_name(n)))
b.m_interval_number = n
b.connect('clicked', self.on_interval_number_clicked, n)
self.g_number_box.pack_start(b, True, True, 0)
b.show()
[btn.destroy() for btn in self.g_quality_box.get_children()]
for n in self.m_t.m_P.header.interval_quality:
b = Gtk.Button(mpd.Interval.nn_to_translated_quality(n))
b.m_interval_quality = n
b.connect('clicked', self.on_interval_quality_clicked, n)
self.g_quality_box.pack_start(b, True, True, 0)
b.show()
self.g_flashbar.require_size([
_("Correct, but you have already solved this question"),
_("Wrong, but you have already solved this question"),
])
self.g_flashbar.delayed_flash(self.short_delay,
_("Click 'New' to begin."))
def on_notebutton_clicked(self, btn, n, user_notename):
newb = Gtk.Button(user_notename)
newb.show()
btn.destroy()
self.m_answer.append(n)
self.g_answer.pack_end(newb, False, False, 0)
if not self.g_source.get_children():
# no children mean that the user has finished answering
if self.m_t.guess_voicing(self.m_answer):
self.g_flashbar.flash(_("Correct"))
self.show_music()
self.std_buttons_answer_correct()
self.g_redo.set_sensitive(False)
else:
self.g_flashbar.flash(_("Wrong"))
self.std_buttons_answer_wrong()
self.g_redo.grab_focus()
else:
self.g_source.get_children()[0].grab_focus()
def show_music(self):
self.clear_stacking_frame()
md = mpd.MusicDisplayer()
self.g_source.pack_start(md, True, True, 0)
md.show()
md.display(r"\staff{ \clef %s < %s >}" % (
mpd.select_clef(self.m_t.m_P.get_music_as_notename_string('music')),
self.m_t.m_P.get_music_as_notename_string('music')), 20)
# display the notenames on the buttons with octave info
v = self.m_t.m_P.get_music_as_notename_list('music')
v.sort(mpd.compare_notenames)
for n in v:
b = Gtk.Button(mpd.MusicalPitch.new_from_notename(n).get_user_octave_notename())
b.get_children()[0].set_use_markup(1)
b.show()
self.g_answer.pack_end(b, False, False, 0)
def __init__(self, statistics, heading):
Gtk.ScrolledWindow.__init__(self)
self.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
self.vbox = Gtk.VBox(False, 0)
self.vbox.set_spacing(gu.PAD)
self.vbox.set_border_width(gu.PAD)
self.add_with_viewport(self.vbox)
hbox = Gtk.HBox(False, 0)
hbox.set_spacing(gu.hig.SPACE_SMALL)
im = Gtk.Image.new_from_file("graphics/applications-system.svg")
self.g_settings_button = b = Gtk.Button()
b.connect('clicked', self.on_delete_statistics)
b.add(im)
hbox.pack_start(b, False, False, 0)
self.g_heading = Gtk.Label(label=heading)
self.g_heading.set_alignment(0.0, 0.5)
self.g_heading.set_name("StatisticsH1")
hbox.pack_start(self.g_heading, False, False, 0)
self.vbox.pack_start(hbox, False, False, 0)
self.m_statistics = statistics
self.g_tables = Gtk.VBox(False, 0)
self.g_tables.show()
self.vbox.pack_start(self.g_tables, True, True, 0)
self.show_all()
def create_statistics_config(self):
it, page_vbox = self.new_page_box(None, _("Statistics"))
box, category_vbox = gu.hig_category_vbox(_("Statistics from 3.15 and older"))
page_vbox.pack_start(box, False, False, 0)
self.g_old_stat_info = Gtk.Label()
self.g_old_stat_info.set_line_wrap(True)
self.g_old_stat_info.set_alignment(0.0, 0.5)
category_vbox.pack_start(self.g_old_stat_info, False, False, 0)
###
self.g_delete_old_statistics = Gtk.Button(stock=Gtk.STOCK_DELETE)
self.g_delete_old_statistics.connect('clicked', self.delete_obsolete_statistics)
category_vbox.pack_start(self.g_delete_old_statistics, False, False, 0)
box, category_vbox = gu.hig_category_vbox(_("Statistics"))
page_vbox.pack_start(box, False, False, 0)
self.g_stat_info = Gtk.Label()
self.g_stat_info.set_line_wrap(True)
self.g_stat_info.set_alignment(0.0, 0.5)
category_vbox.pack_start(self.g_stat_info, False, False, 0)
b = Gtk.Button(stock=Gtk.STOCK_DELETE)
b.connect('clicked', self.delete_statistics)
category_vbox.pack_start(b, False, False, 0)
self.update_statistics_info()
self.update_old_statistics_info()
def add(self, question, callback):
"""add a button and set up callback function.
there should not be created more than one button with the same
(c locale) name.
return the button created.
"""
if 'newline' in question and question.newline:
self.newline()
b = Gtk.Button()
if question.name.cval in self.m_button_dict:
print >> sys.stderr, "Warning: The lessonfile contain several questions with the same name:", question.name.cval
print >> sys.stderr, " This is a bug in the lesson file."
self.m_button_dict[question.name.cval] = b
self.m_name_list.append(question.name.cval)
b.m_cname = question.name.cval
b.set_sensitive(question.active)
b.add(lessonfilegui.new_labelobject(question.name))
b.show_all()
self.attach(b, self.m_x, self.m_x+1, self.m_y, self.m_y+1)
b.connect('clicked', callback)
b.connect('button_release_event', callback)
self.conditional_newline()
return b
def __init__(self, parent):
Gtk.Window.__init__(self)
self.set_title(_("GNU Solfege lesson file editor") )
self.set_default_size(400, 400)
self.g_parent = parent
self.vbox = Gtk.VBox()
self.vbox.set_spacing(8)
self.add(self.vbox)
self.connect('delete_event', self.delete_cb)
self.g_htmlwidget = htmlwidget.HtmlWidget(None, None)
self.vbox.pack_start(self.g_htmlwidget, True, True, 0)
self.vbox.pack_start(Gtk.HSeparator(), False)
bbox = Gtk.HButtonBox()
bbox.set_border_width(8)
self.vbox.pack_start(bbox, False)
b = Gtk.Button(stock=Gtk.STOCK_CLOSE)
b.connect('clicked', self.close_cb)
bbox.pack_start(b, True, True, 0)
self.show_all()
self.set_focus(b)
def __init__(self, exname, name, sizegroup):
Gtk.VBox.__init__(self)
cfg.ConfigUtils.__dict__['__init__'](self, exname)
self.m_name = name
hbox = gu.bHBox(self)
hbox.set_spacing(gu.PAD_SMALL)
self.g_button = Gtk.Button(
soundcard.instrument_names[self.get_int(self.m_name)])
self.g_button.connect('clicked', self.on_btnclick)
hbox.pack_start(self.g_button, True, True, 0)
g = Gtk.VolumeButton()
g.props.value = self.get_int('%s_volume' % name) / MAX_VOLUME
def ff(volumebutton, value):
self.set_int('%s_volume' % name, int(value * MAX_VOLUME))
g.connect('value-changed', ff)
hbox.pack_start(g, False, False, 0)
self.g_menu = MidiInstrumentMenu(self.on_instrument_selected)
self.m_instrument = self.get_int('preferred_instrument')
hbox = Gtk.HBox()
hbox.set_spacing(6)
self.pack_start(hbox, True, True, 0)
def __init__(self, default_value):
Gtk.Box.__init__(self)
self.m_value = mpd.notename_to_int(default_value)
self.g_entry = Gtk.Entry()
self.g_entry.set_editable(False)
self.g_entry.set_text(mpd.int_to_user_octave_notename(self.m_value))
self.pack_start(self.g_entry, False, False, 0)
# up
eb1 = Gtk.Button()
eb1.add(Gtk.Arrow(Gtk.ArrowType.UP, Gtk.ShadowType.OUT))
eb1.connect('button-press-event', self.on_up_press)
eb1.connect('button-release-event', self.on_up_release)
self.pack_start(eb1, True, True, 0)
# down
eb2 = Gtk.Button()
eb2.add(Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.IN))
eb2.connect('button-press-event', self.on_down_press)
eb2.connect('button-release-event', self.on_down_release)
self.pack_start(eb2, True, True, 0)
self.m_timeout = None
def append_button(self, abspath, name):
button = Gtk.Button()
button.abspath = abspath
button.set_tooltip_text(name)
if abspath == '/':
home_img = Gtk.Image.new_from_icon_name('user-home-symbolic',
Gtk.IconSize.SMALL_TOOLBAR)
button.set_image(home_img)
else:
button.set_label(gutil.ellipse_text(name))
if not Config.GTK_GE_312:
button.set_size_request(32, -1)
self.path_box.pack_start(button, False, False, 0)
button.connect('clicked', self.on_button_clicked)
def color_swatch_new(self, str_color):
color = Gdk.color_parse(str_color)
rgba = Gdk.RGBA.from_color(color)
button = Gtk.Button()
area = Gtk.DrawingArea()
area.set_size_request(24, 24)
area.override_background_color(0, rgba)
button.add(area)
return button
# ---------------------------------
# create_flowbox
# ---------------------------------
def color_swatch_new(self, str_color):
color = Gdk.color_parse(str_color)
rgba = Gdk.RGBA.from_color(color)
button = Gtk.Button()
area = Gtk.DrawingArea()
area.set_size_request(24, 24)
area.override_background_color(0, rgba)
button.add(area)
return button
# print("Pedro deconnected")
# ---------------------------------
# color_widget
# ---------------------------------
def create_tab(self, title, tab_child, icon=''):
tab_box = Gtk.HBox(False, 3)
close_button = Gtk.Button()
image = Gtk.Image()
image.set_from_stock(Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
label = Gtk.Label(label=title)
if icon:
i = Gtk.Image()
i.set_from_stock(eval('Gtk.STOCK_' + icon), Gtk.IconSize.MENU)
tab_box.pack_start(i, False, False, 0)
close_button.connect("clicked", self.close_tab, tab_child)
close_button.set_image(image)
close_button.set_relief(Gtk.ReliefStyle.NONE)
tab_box.pack_start(label, True, True, 0)
tab_box.pack_end(close_button, False, False, 0)
tab_box.show_all()
if title in ['Loading dasm...', 'Code', 'Callgraph', 'Flowgraph', 'Interactive', 'Strings', "Sections", 'Hexdump', 'Bindiff', 'File info']:
close_button.hide()
return tab_box
def __init__(self, part: Dict[str, Any], core: ApartCore, main_view: 'MainView'):
Gtk.Box.__init__(self)
self.part = part
self.core = core
self.main_view = main_view
self.add(key_and_val('Name', self.name()))
self.add(key_and_val('Type', self.part.get('fstype', 'unknown')))
self.add(key_and_val('Label', self.part.get('label', 'none')))
self.add(key_and_val('Size', humanize.naturalsize(self.part['size'], binary=True)))
self.clone_button = Gtk.Button("Clone", halign=Gtk.Align.END)
self.restore_button = Gtk.Button("Restore", halign=Gtk.Align.END)
if self.is_mounted():
self.clone_button.set_sensitive(False)
self.clone_button.set_tooltip_text('Partition is currently mounted')
self.restore_button.set_sensitive(False)
self.restore_button.set_tooltip_text('Partition is currently mounted')
else:
self.clone_button.connect('clicked', lambda b: self.main_view.show_new_clone())
self.restore_button.connect('clicked', lambda b: self.main_view.show_new_restore())
buttons = Gtk.Box(hexpand=True, halign=Gtk.Align.END)
buttons.add(self.clone_button)
buttons.add(self.restore_button)
self.add(buttons)
main_view.connect('notify::visible-child', self.on_main_view_change)
def on_menuitem_custom_activate(self, widget):
self.custom_window = Gtk.Window()
self.custom_window.set_default_size(640, 480)
self.custom_window.set_position(Gtk.WindowPosition.CENTER)
self.custom_window.set_title("Custom CSS")
self.custom_vbox = Gtk.VBox()
self.custom_scroller = Gtk.ScrolledWindow()
self.custom_button = Gtk.Button("Apply")
self.custom_vbox.pack_end(self.custom_button, False, False, 0)
self.custom_text_view = Gtk.TextView()
self.custom_text_buffer = Gtk.TextBuffer()
self.custom_text_buffer.set_text(self.custom_css)
self.custom_text_view.set_buffer(self.custom_text_buffer)
self.custom_scroller.add(self.custom_text_view)
self.custom_vbox.pack_start(self.custom_scroller, True, True, 0)
self.custom_window.add(self.custom_vbox)
self.custom_window.show_all()
self.custom_button.connect("clicked", self.apply_custom_css, self.custom_window, self.custom_text_buffer)
def __init__(self):
window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
window.set_title("Audio-Player")
window.set_default_size(300, -1)
window.connect("destroy", Gtk.main_quit, "WM destroy")
vbox = Gtk.VBox()
window.add(vbox)
self.entry = Gtk.Entry()
vbox.pack_start(self.entry, False, True, 0)
self.button = Gtk.Button("Start")
self.button.connect("clicked", self.start_stop)
vbox.add(self.button)
window.show_all()
self.player = Gst.ElementFactory.make("playbin", "player")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
self.player.set_property("video-sink", fakesink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
def __init__(self,parent):
Gtk.Grid.__init__(self,column_homogeneous=False, column_spacing=10,row_spacing=0)
button1 = Gtk.Button("Choose File")
button1.connect("clicked", self.on_file_clicked)
self.add(button1)
self.text_file = Gtk.Entry()
self.text_file.set_hexpand(True)
self.attach(self.text_file, 1, 0, 4, 1)
button2 = Gtk.Button("Choose Folder")
button2.connect("clicked", self.on_folder_clicked)
self.attach_next_to(button2, button1, Gtk.PositionType.BOTTOM, 1, 1)
self.text_folder = Gtk.Entry()
self.attach(self.text_folder, 1, 1, 4, 1)
def __init__(self,MainGrid):
Gtk.VBox.__init__(self)
self.btn1=Gtk.Button()
self.btn1.set_image(Gtk.Image.new_from_icon_name("filenew",Gtk.IconSize.DIALOG))
self.btn1.set_name("button1")
self.add(self.btn1)
#
# self.win_width = MainGrid.window.win_width
# self.win_height = MainGrid.window.win_height
# wid = self.win_width * 0.1
# hei = self.win_height
# print "requested width: ",wid
# print "requested height: ",hei
# print "-----------------------------"
# self.set_size_request(wid, hei)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.headerbar.set_subtitle('Group {id}'.format(id=self.model.group_id))
delete_button = Gtk.Button(label='Delete', visible=True)
delete_button.connect('clicked', self._on_delete_click)
self.headerbar.pack_end(delete_button)
self.lights_list = SelectableLightList(
self.model.bridge.lights_by_id.values(),
set(light.light_id for light in self.model.lights)
)
self.content.pack_start(self.lights_list, True, True, 6)
self.content.reorder_child(self.lights_list, 2)
def __init__(self, desc):
super(KeybindingWidget, self).__init__()
self.desc = desc
self.label = Gtk.Label(desc)
if self.desc != "":
self.pack_start(self.label, False, False, 0)
self.button = Gtk.Button()
self.button.set_tooltip_text(_("Click to set a new accelerator key for opening and closing the menu. ") +
_("Press Escape or click again to cancel the operation. ") +
_("Press Backspace to clear the existing keybinding."))
self.button.connect("clicked", self.clicked)
self.button.set_size_request(200, -1)
self.pack_start(self.button, False, False, 4)
self.show_all()
self.event_id = None
self.teaching = False
GUI.py 文件源码
项目:Simple-User-Input-Sculpture-Generation
作者: ClaireKincaid
项目源码
文件源码
阅读 32
收藏 0
点赞 0
评论 0
def __init__(self):
Gtk.Window.__init__(self, title = "Choose a method of Sculpture Generation")
self.set_border_width(10)
self.set_default_size(400, 50)
#initiates Gtk box window
self.box = Gtk.Box(spacing = 6)
self.add(self.box)
#Initializes Vector Animation Button, places in box
self.VectorButton = Gtk.Button(label = "Vector Animation")
self.VectorButton.connect("clicked", self.on_VectorButton_clicked)
self.VectorButton.connect("clicked", Gtk.main_quit)
self.box.pack_start(self.VectorButton, True, True, 0)
#Initializes Perlin Noise Button, places in box
self.PerlinButton = Gtk.Button(label = "Perlin Noise")
self.PerlinButton.connect("clicked", self.on_PerlinButton_clicked)
self.PerlinButton.connect("clicked", Gtk.main_quit)
self.box.pack_start(self.PerlinButton, True, True, 0)
#when VectorButton clicked, toggles to new GUI
def create_main_window(self):
self.main_window = Gtk.Window(
title = _("Omikron: The Nomad Soul"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
)
self.main_window.connect('delete-event', self.quit_app)
button_patch = Gtk.Button(
label = _("Old Games Widescreen Patch"),
margin_top = 10,
margin_bottom = 10,
margin_left = 10,
margin_right = 10
)
button_patch.connect('clicked', self.cb_button_patch)
self.main_window.add(button_patch)
self.main_window.show_all()
def __init__(self):
self.main_window = Gtk.Window()
self.main_window.set_border_width(5)
self.main_window.connect("destroy", self._destroy)
self.main_vbox = Gtk.VBox()
self.select_hbox = Gtk.HBox()
self.select_button = Gtk.Button("Select")
self.select_button.connect("clicked", self._select_clicked)
self.select_hbox.pack_start(self.select_button, False, True, 0)
self.file_combo = Gtk.ComboBoxText()
self.file_combo.connect("changed", self._file_combo_changed)
self.select_hbox.pack_start(self.file_combo, True, True, 0)
self.main_vbox.pack_start(self.select_hbox, False, True, 0)
self.metadata_table = Gtk.Table(1, 1)
self.metadata_table.attach(
Gtk.Label("Select a file to view metadata information..."), 0, 1, 0, 1)
self.main_vbox.pack_start(self.metadata_table, True, True, 0)
self.main_window.add(self.main_vbox)
self.main_window.show_all()
def __init__(self, files):
self.files = files
Gtk.Window.__init__(self, title="TMSU")
self.set_size_request(200, 100)
self.set_border_width(10)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(vbox)
prompt_text = 'Add (space-separated) tags to %d file%s' % (len(files), '' if len(files)==1 else 's')
self.prompt_label = Gtk.Label(label=prompt_text)
vbox.pack_start(self.prompt_label, True, True, 0)
self.entry = Gtk.Entry()
self.entry.connect("activate", self.on_entry_activated)
vbox.pack_start(self.entry, True, True, 0)
self.button = Gtk.Button(label="Add")
self.button.connect("clicked", self.on_button_clicked)
vbox.pack_start(self.button, True, True, 0)
def _build_confirm_changes_button(self, label=None, on_signal="clicked",
callback=None):
"""
Build a confirmation button used in every side bar menus.
This button triggers interaction with the backend in case of settings
changes. Otherwise it stays insensitive.
"""
if not label:
label = "Confirm"
button = Gtk.Button(label)
button.set_sensitive(False)
button.set_margin_top(12)
if callback:
button.connect(on_signal, callback)
return button
def __init__(self):
self.placeholder_image = Gtk.Image.new_from_icon_name(
Gtk.STOCK_NEW, Gtk.IconSize.DIALOG)
self.new_feed_button = Gtk.Button("New Feed")
self.new_feed_vbox = Gtk.Box(Gtk.Orientation.VERTICAL)
self.new_feed_vbox.set_halign(Gtk.Align.CENTER)
self.new_feed_vbox.set_valign(Gtk.Align.CENTER)
_pack_widgets(self.new_feed_vbox,
self.placeholder_image,
self.new_feed_button)
self._grid = Gtk.Grid()
self._grid.set_row_homogeneous(True)
self._grid.set_column_homogeneous(True)
self._grid.attach(self.new_feed_vbox, 0, 0, 1, 1)
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG1"), 1, 0, 1, 1) # DEBUG
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG2"), 0, 1, 1, 1) # DEBUG
self._grid.attach(Gtk.Label("FEED ELEMENT DEBUG3"), 1, 1, 1, 1) # DEBUG
self._grid.show_all()
self.container = self._grid