def create_stock_menu_item(stock, txt, callback, ag, accel_key, accel_mod):
box = Gtk.HBox(False, 0)
box.set_spacing(PAD_SMALL)
im = Gtk.Image()
im.set_from_stock(stock, Gtk.IconSize.MENU)
item = Gtk.ImageMenuItem(txt)
item.set_image(im)
if accel_key != 0:
item.add_accelerator('activate', ag, accel_key, accel_mod, Gtk.AccelFlags.VISIBLE)
item.connect('activate', callback)
return item
python类Image()的实例源码
def create_png_image(fn):
"""
Create an image by loading a png file from graphics dir
"""
im = Gtk.Image()
im.set_from_file(os.path.join('graphics', fn)+'.png')
im.show()
return im
def create_rhythm_image(rhythm):
"""
rhythm : a string like 'c8 c8' or 'c8 c16 c16'
The image returned is shown.
"""
im = Gtk.Image()
im.set_from_file(os.path.join('graphics', 'rhythm-%s.png' % (rhythm.replace(" ", ""))))
im.show()
return im
def make_warning(self):
im = Gtk.Image()
im.set_from_stock(Gtk.STOCK_DIALOG_WARNING, Gtk.IconSize.MENU)
self.set_image(im)
self.set_alignment(0.0, 0.5)
def __init__(self, parent, app, info):
super().__init__(_('Verification..'), app.window,
Gtk.DialogFlags.MODAL,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_response(Gtk.ResponseType.OK)
self.set_default_size(320, 200)
self.set_border_width(10)
self.app = app
box = self.get_content_area()
box.set_spacing(10)
gutil.async_call(net.urlopen, info['img'],
{'Cookie': app.cookie.header_output()},
callback=self.update_img)
self.img = Gtk.Image()
box.pack_start(self.img, False, False, 0)
self.entry = Gtk.Entry()
self.entry.connect('activate',
lambda *args: self.response(Gtk.ResponseType.OK))
box.pack_start(self.entry, False, False, 0)
box.show_all()
def __create_flowbox(self, flowbox):
self.logger.info('Creating Flowbox')
start = time.perf_counter()
image_loading_queue = []
children = []
order = AbstractPlaylist.OrderBy[self.userconfig['grid']['sort']['field']]
desc = self.userconfig['grid']['sort']['desc']
image_size = self.userconfig['flowbox']['image_size']
margin = self.userconfig['flowbox']['margin']
collections = self.current_playlist.collections(order, desc, self.txt_search.get_text())
for child in flowbox.get_children():
flowbox.remove(child)
for item in collections:
image = Gtk.Image()
image.set_size_request(image_size, image_size)
image.get_style_context().add_class('cover')
image_loading_queue.append((image, item.Cover, image_size, image_size))
if isinstance(item, Album):
children.append(self.__create_album_flowboxitem(item, image, margin))
elif isinstance(item, Artist):
children.append(self.__create_artist_flowboxitem(item, image, margin))
for child in children:
flowbox.add(child)
flowbox.show_all()
image_helper.set_multiple_image(image_loading_queue)
end = time.perf_counter()
self.logger.info('Flowbox created in {:.3f} seconds'.format(end - start))
def _hide_tb_toggled(self, widget):
if widget.get_active():
self.main.tviews.term_nb.show()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_DOWN, Gtk.IconSize.MENU)
widget.set_image(i)
else:
self.main.tviews.term_nb.hide()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_UP, Gtk.IconSize.MENU)
widget.set_image(i)
def __init__(self):
self.img_static = Gtk.Image()
self.img_static.set_from_file(datafile_path('throbber_static.gif'))
self.img_static.show()
self.img_animat = Gtk.Image()
self.img_animat.set_from_file(datafile_path('throbber_animat.gif'))
self.img_animat.show()
super(Throbber,self).__init__(self.img_static, "")
self.set_sensitive(False)
def __init__(self, text, menu):
GObject.GObject.__init__(self)
self.menu = menu
hbox1 = Gtk.HBox()
hbox2 = Gtk.HBox()
icon = Gtk.Image()
icon.set_from_file(datafile_path('bokken-small.svg'))
hbox1.pack_start(icon, True, True, 3)
label = Gtk.Label()
label.set_markup("<b>"+ text + "</b>")
hbox1.pack_start(label, True, True, 3)
arrow = Gtk.Arrow(Gtk.ArrowType.DOWN, Gtk.ShadowType.IN)
hbox1.pack_start(arrow, False, False, 3)
hbox2.pack_start(hbox1, True, True, 0)
# MEOW Text settings
#attrs = Pango.AttrList()
#attrs.change(Pango.AttrWeight(Pango.Weight.SEMIBOLD, 0, -1))
#label.set_attributes(attrs)
self.add(hbox2)
self.set_relief(Gtk.ReliefStyle.NORMAL)
self.set_can_focus(True)
self.set_can_default(False)
self.connect("toggled", self.on_toggled)
for sig in "selection-done", "deactivate", "cancel":
menu.connect(sig, self.on_menu_dismiss)
def create_seek_buttons(self):
self.hbox = Gtk.HBox(False, 1)
self.back = Gtk.Button()
self.back_img = Gtk.Image()
self.back_img.set_from_stock(Gtk.STOCK_GO_BACK, Gtk.IconSize.MENU)
self.back.set_image(self.back_img)
self.back.set_relief(Gtk.ReliefStyle.NONE)
self.back.connect('clicked', self.do_seek, 'b')
self.forward = Gtk.Button()
self.forward_img = Gtk.Image()
self.forward_img.set_from_stock(Gtk.STOCK_GO_FORWARD, Gtk.IconSize.MENU)
self.forward.set_image(self.forward_img)
self.forward.set_relief(Gtk.ReliefStyle.NONE)
self.forward.connect('clicked', self.do_seek, 'f')
self.seek = Gtk.Entry()
self.seek.set_max_length(30)
self.seek.set_icon_from_stock(1, Gtk.STOCK_JUMP_TO)
self.seek.set_activates_default(True)
self.seek.connect("activate", self.goto)
self.seek.connect("icon-press", self.goto)
self.seek.set_icon_tooltip_text(1, 'Go')
self.hbox.pack_start(self.back, False, False, 0)
self.hbox.pack_start(self.forward, False, False, 0)
self.hbox.pack_start(self.seek, True, True, 0)
return self.hbox
def popup_registers(self, widget):
dialog = Gtk.Dialog('16-bit and 8-bit registers', self, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CLOSE,Gtk.ResponseType.CLOSE))
ui.gtk3.common.set_bokken_icon(dialog)
reg_img = Gtk.Image()
reg_img.set_from_file(datafile_path('registers.png'))
reg_label = Gtk.Label("The four primary general purpose registers (EAX, EBX, ECX and EDX)\nhave 16 and 8 bit overlapping aliases.")
reg_label.set_alignment(0.1, 0.1)
reg_label.set_padding (0, 3)
dialog.vbox.pack_start(reg_label, False, False, 2)
dialog.vbox.pack_start(reg_img, True, True, 2)
dialog.show_all()
dialog.run()
dialog.destroy()
def _hide_tb_toggled(self, widget):
if widget.get_active():
self.main.topbuttons.hide()
self.main.mbar.hide()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_DOWN, Gtk.IconSize.MENU)
widget.set_image(i)
else:
self.main.topbuttons.show()
self.main.mbar.show()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_UP, Gtk.IconSize.MENU)
widget.set_image(i)
def generate_thumbnail(self, dotcode):
#size = self.tree.allocation.width
size = self.side_hb.get_allocated_width()
tmp_dot = tempfile.NamedTemporaryFile(delete = False)
tmp_dot.write(dotcode)
tmp_dot.close()
cmd = "dot -Tpng " + tmp_dot.name + " > " + tmp_dot.name + ".png"
os.system(cmd)
im = Image.open(tmp_dot.name + ".png")
im.convert('RGBA')
im.thumbnail([size,size], Image.ANTIALIAS)
#im.save(tmp_dot.name + ".png.thumbnail", "JPEG")
# Add white backgound as image is transparent
offset_tuple = (im.size[0], im.size[1])
final_thumb = Image.new(mode='RGBA',size=offset_tuple, color=(255,255,255,0))
final_thumb.paste(im)
final_thumb.save(tmp_dot.name + ".png.thumbnail", "PNG")
self.fill_preview(tmp_dot.name + ".png.thumbnail")
os.remove(tmp_dot.name)
os.remove(tmp_dot.name + ".png")
os.remove(tmp_dot.name + ".png.thumbnail")
def create_preview(self):
# Create Image window for graph preview
self.preview = Gtk.Image()
self.preview.show()
def _hide_tb_toggled(self, widget):
if widget.get_active():
self.main.topbuttons.main_tb.hide()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_DOWN, Gtk.IconSize.MENU)
widget.set_image(i)
else:
self.main.topbuttons.main_tb.show()
i = Gtk.Image()
i.set_from_stock(Gtk.STOCK_GO_UP, Gtk.IconSize.MENU)
widget.set_image(i)
def __init__(self,parent):
Gtk.Grid.__init__(self)
self.set_border_width(10)
self.vbox = Gtk.VBox(spacing=6)
self.vbox = Gtk.Box(spacing=6)
self.add(self.vbox)
self.button1 = Gtk.ToggleButton("Button1")
self.button1.connect("toggled", self.on_button_toggled, "1")
self.button1.set_active(True)
#self.button1img = Gtk.Image.new_from_icon_name("filenew", Gtk.IconSize.MENU)
#self.button1.set_image(self.button1img)
self.vbox.pack_start(self.button1, True, True, 0)
self.button2 = Gtk.ToggleButton("Button 2")
self.button2.connect("toggled", self.on_button_toggled, "2")
self.vbox.pack_start(self.button2, True, True, 0)
self.button3 = Gtk.ToggleButton("Button 3")
self.button3.connect("toggled", self.on_button_toggled, "3")
self.vbox.pack_start(self.button3, True, True, 0)
self.attach(self.button1, 0, 0, 1, 1)
self.attach(self.button2, 1, 0, 3, 1)
self.attach(self.button3, 2, 0, 1, 1)
def on_button_press(self, w, e):
if e.type == Gdk.EventType.BUTTON_PRESS \
and e.button == 1: #Left Button
self.coords.append([e.x, e.y])
if e.type == Gdk.EventType.BUTTON_PRESS \
and e.button == 3: #Right Button
self.queue_draw()
# class image(Gtk.Image):
# def __init__(self, parent):
# x
def is_image_valid(file):
try: Image.open(file)
except IOError: return False
return True
def make_icon(filename):
icon = Gtk.Image()
icon.set_from_file("{}{}".format(icns, filename))
return icon
def __init__(self):
Gtk.Image.__init__(self)
self.props.icon_size = Image.SIZE