def create_feed_entry(title, url, description):
container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
title_label = Gtk.Label(title)
link_button = Gtk.LinkButton(url, url)
description_view = WebKit2.WebView()
description_view.set_size_request(400, 400)
description_view.load_html(description)
container.add(title_label)
container.add(link_button)
container.add(description_view)
container.show()
title_label.show()
link_button.show()
description_view.show()
return container
python类LinkButton()的实例源码
def __init__(self, label):
"""
We are abusing the Link button by not giving it a real uri.
So let ut not even pretend to follow its api.
"""
Gtk.LinkButton.__init__(self, label, label)
self.get_children()[0].set_ellipsize(Pango.EllipsizeMode.END)
self.get_children()[0].set_alignment(0.0, 0.5)
def f(*w): return True
self.connect('activate-link', f)
def populate(self):
for link in self.item.links:
button = Gtk.LinkButton()
button.set_halign(Gtk.Align.START)
button.set_label(link[0:40])
button.set_tooltip_text(link)
button.set_uri(link)
button.connect('activate-link', lambda b: common.APPLICATION.hide())
self._box.add(button)
self._box.show_all()
def populate(self):
for file_ in self.item.raw.split('\n'):
button = Gtk.LinkButton()
button.set_halign(Gtk.Align.START)
button.set_label(file_[0:40])
button.set_tooltip_text(file_)
button.connect('activate-link', self._on_activate_file_link, file_)
self._box.add(button)
self._box.show_all()
def __init__(self):
super().__init__()
self.set_name('HistoriesManagerBox')
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_halign(Gtk.Align.END)
self.set_valign(Gtk.Align.CENTER)
self.set_hexpand(True)
self.set_vexpand(False)
self.link = Gtk.LinkButton()
self.link.connect('activate-link', self._on_activate_link)
self.link.set_label('...')
self.link.set_tooltip_text(_('Open histories manager'))
self._entry = Gtk.Entry()
self._entry.set_placeholder_text(_('New history'))
self._entry.set_icon_from_icon_name(
Gtk.EntryIconPosition.PRIMARY,
'list-add-symbolic'
)
self._entry.connect('activate', self._on_entry_activate)
self._box = Gtk.Box()
self._box.set_orientation(Gtk.Orientation.VERTICAL)
self._box.add(self._entry)
self.popover = Gtk.Popover()
self.popover.set_relative_to(self.link)
self.popover.add(self._box)
self.add(self.link)
gpaste_client.connect('SwitchHistory', self.update)
gpaste_client.connect('DeleteHistory', self.update)
self.update()
def getLinkButtonImg(img,link,toolTip):
Logbutton = Gtk.LinkButton(link)
Logbutton.add(Gtk.Image.new_from_pixbuf(img))
Logbutton.set_tooltip_text(toolTip)
return Logbutton
def create_download_window(self):
self.download_window = Gtk.Window(
title = _("Konung 2: Blood of Titans"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 360
)
self.download_window.connect('delete-event', self.quit_app)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_left = 10,
margin_right = 10,
margin_top = 10,
margin_bottom = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download resolution patch"),
uri = link_patch
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/konung_2_blood_of_titans'
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install)
box.pack_start(linkbutton_download, True, True, 0)
box.pack_start(linkbutton_put, True, True, 0)
box.pack_start(button_install, True, True, 0)
self.download_window.add(box)
def create_download_window(self):
self.download_window = Gtk.Window(
title = _("Nosferatu: The Wrath of Malachi"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 360
)
self.download_window.connect('delete-event', self.quit_app)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_left = 10,
margin_right = 10,
margin_top = 10,
margin_bottom = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download patch"),
uri = link_patch
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/nosferatu_wrath_of_malachi'
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install)
box.pack_start(linkbutton_download, True, True, 0)
box.pack_start(linkbutton_put, True, True, 0)
box.pack_start(button_install, True, True, 0)
self.download_window.add(box)
def create_download_window(self):
self.download_window = Gtk.Window(
title = _("Desperados: Wanted Dead or Alive"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 360
)
self.download_window.connect('delete-event', self.quit_app)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_left = 10,
margin_right = 10,
margin_top = 10,
margin_bottom = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download patch"),
uri = link_patch
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/desperados_wanted_dead_or_alive'
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install)
box.pack_start(linkbutton_download, True, True, 0)
box.pack_start(linkbutton_put, True, True, 0)
box.pack_start(button_install, True, True, 0)
self.download_window.add(box)
def create_download_window(self):
self.download_window = Gtk.Window(
title = _("Konung: Legends of the North"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 360
)
self.download_window.connect('delete-event', self.quit_app)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_left = 10,
margin_right = 10,
margin_top = 10,
margin_bottom = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download resolution patch"),
uri = link_patch
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/konung_legend_of_the_north'
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install)
box.pack_start(linkbutton_download, True, True, 0)
box.pack_start(linkbutton_put, True, True, 0)
box.pack_start(button_install, True, True, 0)
self.download_window.add(box)
def list_containers(self, container, container_info):
""" fill list with all docker containers """
items = {}
glade_row = Gtk.Builder()
glade_row.add_from_file('glade/label.glade')
items['row'] = glade_row.get_object("list_row")
items['row'].set_activatable(True)
items['row'].set_name(container_info['Id'])
items['title'] = glade_row.get_object("dockerTitle")
items['title'].set_label('%s - %s' % (container_info['Name'][1:], container.get('Status')))
items['image'] = glade_row.get_object("dockerStatus")
items['image'].set_size_request(64, 64) # = glade_row.get_object("dockerStatus")
items['uri_container'] = glade_row.get_object("uri_container")
for uri in get_container_forwards(container_info):
# Container Address
linkbutton = Gtk.LinkButton(uri=uri, label=uri, xalign=0)
items['uri_container'].pack_start(linkbutton, False, False, 0)
#addresslabel = Gtk.Label(uri)
#items['uri_container'].pack_start(addresslabel, False, False, 0)
if container_info['State']['Paused']:
items['image'].set_from_icon_name("gtk-media-pause", Gtk.IconSize.DIALOG) # todo: find nice image
elif container_info['State']['Running']:
items['image'].set_from_stock("gtk-media-play", Gtk.IconSize.DIALOG)
else:
items['image'].set_from_stock("gtk-media-stop", Gtk.IconSize.DIALOG)
items['switch'] = glade_row.get_object("dockerToggle")
items['switch'].set_active(True==container_info['State']['Running'])
items['switch'].connect('state-set', self.container_toggle_status, container)
items['button'] = glade_row.get_object("dockerRemove")
items['button'].connect('button_press_event', self.container_delete, items['row'], container)
self.listbox.add(items['row'])
items['row'].show_all()
self.gui_rows[container['Id']] = items
def __init__(self, item):
super().__init__()
self.set_name('Infobox')
self.set_halign(Gtk.Align.START)
self.set_valign(Gtk.Align.END)
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_margin_left(5)
self.set_margin_bottom(5)
self._weakref = weakref.ref(item)
if self.item.app_info:
name = self.item.app_info.get_display_name()
gicon = self.item.app_info.get_icon()
if gicon:
icon_theme = Gtk.IconTheme.get_default()
icon_info = icon_theme.lookup_by_gicon(
gicon,
16,
Gtk.IconLookupFlags.FORCE_SIZE
)
if icon_info:
pixbuf = icon_info.load_icon()
icon = Gtk.Image()
icon.set_margin_right(5)
icon.set_from_pixbuf(pixbuf)
self.add(icon)
if name:
app_name = Gtk.LinkButton()
app_name.connect('activate-link', self._on_activate_link)
app_name.set_halign(Gtk.Align.START)
app_name.set_name('AppNameLink')
app_name.set_label(name)
self.add(app_name)
style_context = app_name.get_style_context()
style_context.remove_class('text-button')
style_context.remove_class('button')
if self.item.info_string:
label = Gtk.Label()
label.set_margin_left(5)
label.set_halign(Gtk.Align.START)
label.set_markup(INFOSTRING_TEMPLATE % self.item.info_string)
self.add(label)
def create_co8_std_window(self):
self.co8_std_window = Gtk.Window(
title = _("The Temple of Elemental Evil"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 480
)
self.co8_std_window.connect('delete-event', self.hide_co8_std_window)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_top = 10,
margin_bottom = 10,
margin_left = 10,
margin_right = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download 'Circle of Eight Mopdack Standard Edition'"),
uri = link_co8_modpack_std,
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/the_temple_of_elemental_evil',
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install_std)
self.box_std = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
spacing = 10
)
self.box_std.pack_start(linkbutton_download, True, True, 0)
self.box_std.pack_start(linkbutton_put, True, True, 0)
self.box_std.pack_start(button_install, True, True, 0)
self.progressbar_std = Gtk.ProgressBar(
hexpand = True,
show_text = True,
text = _("Processing..."),
pulse_step = 0.1,
no_show_all = True
)
box.pack_start(self.box_std, True, True, 0)
box.pack_start(self.progressbar_std, True, True, 0)
self.co8_std_window.add(box)
def create_co8_nc_window(self):
self.co8_nc_window = Gtk.Window(
title = _("The Temple of Elemental Evil"),
type = Gtk.WindowType.TOPLEVEL,
window_position = Gtk.WindowPosition.CENTER_ALWAYS,
resizable = False,
default_width = 480
)
self.co8_nc_window.connect('delete-event', self.hide_co8_nc_window)
box = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
margin_top = 10,
margin_bottom = 10,
margin_left = 10,
margin_right = 10,
spacing = 10
)
linkbutton_download = Gtk.LinkButton(
label = _("Download 'Circle of Eight Mopdack New Content Edition'"),
uri = link_co8_modpack_nc,
)
linkbutton_put = Gtk.LinkButton(
label = _("Put it here"),
uri = 'file://' + download_dir + '/_distr/the_temple_of_elemental_evil',
)
button_install = Gtk.Button(label=_("Install"))
button_install.connect('clicked', self.cb_button_install_nc)
self.box_nc = Gtk.Box(
orientation = Gtk.Orientation.VERTICAL,
spacing = 10
)
self.box_nc.pack_start(linkbutton_download, True, True, 0)
self.box_nc.pack_start(linkbutton_put, True, True, 0)
self.box_nc.pack_start(button_install, True, True, 0)
self.progressbar_nc = Gtk.ProgressBar(
hexpand = True,
show_text = True,
text = _("Processing..."),
pulse_step = 0.1,
no_show_all = True
)
box.pack_start(self.box_nc, True, True, 0)
box.pack_start(self.progressbar_nc, True, True, 0)
self.co8_nc_window.add(box)