def popular_controles(self): pb = Pixbuf.new_from_file_at_scale("imagem_dia.jpg", width=50, height=50,preserve_aspect_ratio=False) self.imagem.set_from_pixbuf(pb) self.cidade.set_text(self.conteudo['cidade']) self.descricao.set_text(self.conteudo['agora']['descricao']) self.temperatura.set_text('Temperatura: ' + self.conteudo['agora']['temperatura'] + ' graus') self.umidade.set_text('Umidade: ' + self.conteudo['agora']['umidade']) for num, value in enumerate(self.conteudo['previsoes']): if num == 1: self.previsao_dia1.set_text(value['data']) self.descricao_dia1.set_text(value['descricao']) img_url = value['imagem'] response = urllib.request.urlopen(img_url) with open("imagem_dia1.jpg", 'wb') as f: f.write(response.read()) pb = Pixbuf.new_from_file_at_scale("imagem_dia1.jpg", width=50, height=50,preserve_aspect_ratio=False) self.imagem_dia1.set_from_pixbuf(pb) self.max_min_dia1.set_text("Max: " + value['temperatura_max'] + " Min: " + value['temperatura_min']) elif num == 2: self.previsao_dia2.set_text(value['data']) self.descricao_dia2.set_text(value['descricao']) img_url = value['imagem'] response = urllib.request.urlopen(img_url) with open("imagem_dia2.jpg", 'wb') as f: f.write(response.read()) pb = Pixbuf.new_from_file_at_scale("imagem_dia2.jpg", width=50, height=50,preserve_aspect_ratio=False) self.imagem_dia2.set_from_pixbuf(pb) self.max_min_dia2.set_text("Max: " + value['temperatura_max'] + " Min: " + value['temperatura_min']) elif num == 3: self.previsao_dia3.set_text(value['data']) self.descricao_dia3.set_text(value['descricao']) img_url = value['imagem'] response = urllib.request.urlopen(img_url) with open("imagem_dia3.jpg", 'wb') as f: f.write(response.read()) pb = Pixbuf.new_from_file_at_scale("imagem_dia3.jpg", width=50, height=50,preserve_aspect_ratio=False) self.imagem_dia3.set_from_pixbuf(pb) self.max_min_dia3.set_text("Max: " + value['temperatura_max'] + " Min: " + value['temperatura_min']) elif num == 4: self.previsao_dia4.set_text(value['data']) self.descricao_dia4.set_text(value['descricao']) img_url = value['imagem'] response = urllib.request.urlopen(img_url) with open("imagem_dia4.jpg", 'wb') as f: f.write(response.read()) pb = Pixbuf.new_from_file_at_scale("imagem_dia4.jpg", width=50, height=50,preserve_aspect_ratio=False) self.imagem_dia4.set_from_pixbuf(pb) self.max_min_dia4.set_text("Max: " + value['temperatura_max'] + " Min: " + value['temperatura_min'])
def _try_init_icon(self) -> bool: liststore = Gtk.ListStore(Pixbuf, str) iconview = Gtk.IconView.new() iconview.set_model(liststore) iconview.set_pixbuf_column(0) iconview.set_text_column(1) iconview.set_selection_mode(Gtk.SelectionMode.NONE) iconview.set_item_orientation(Gtk.Orientation.HORIZONTAL) iconview.set_item_padding(0) # TODO: Deal with errors ap = os.path.abspath(self.icon_path) print(f"Loading icon from {ap}") # TODO: Icon dimensions should be configurable try: liststore.append([ Pixbuf.new_from_file_at_scale(ap, width=24, height=24, preserve_aspect_ratio=True), self.application ]) except Exception as e: warn( f"Could not load icon {self.icon_path} abspath {ap}. Exception: {e}" ) return False self.hbox.pack_start(iconview, False, False, 0) return True
def on_open_image2(self, widget, path, img_pop): # paths = self.get_selected_items() model = self.get_model() # if paths: # path = paths[0] iter = model.get_iter(path) pixbuf_format, width, height = Pixbuf.get_file_info(model[iter][0]) if height > 1080 or width > 1900: pixbuf = Pixbuf.new_from_file_at_scale(model[iter][0], 1900, 1080, True) else: pixbuf = Pixbuf.new_from_file(model[iter][0]) # img = Gtk.Image.new_from_pixbuf(pixbuf) # img.show_all() # pb = img.get_pixbuf() # if pb.get_height() > 1080 # scroll = Gtk.ScrolledWindow() # scroll.set_pre # scroll.add(img) # pop = Gtk.Window.new(1) # pop.add(img) # pop.set_position(3) # pop.show_all() # pop.connect('button-release-event', self.on_pop_click) # self.img_menu_item.set_image(img) img_pop.set_pixbuf(pixbuf) img_pop.popup()
def stop_pressed(self, wdg=None): # Aborting playback cur = self.gst.getnow() self.gst.stop() # Update global vars self.current_song = False self.current_album = False # Update file current_playing = join(self.userconf.datadir, 'current-playing') if exists(current_playing): os_remove(current_playing) # Update user interface self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon( name='media-playback-start-symbolic'), IconSize.BUTTON)) self.headerbar.props.subtitle = '' default = join(self.functions.datadir, 'image', 'logo_head_big.png') cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True) self.player_button_img.set_from_pixbuf(cover_px) self.player_event.set_sensitive(False) self.lyrics_button.set_sensitive(False) self.player_sca.set_sensitive(False) # Do we have to send the signal? if wdg is not None: self.extensions.load_event('OnStopPressed')
def setImage(self, fileName): if not self.settingsManager.resizeImage: mpixbuf = Pixbuf.new_from_file(fileName) else: mpixbuf = Pixbuf.new_from_file_at_scale(fileName, self.iCurWidth, self.iCurHeight, True) self.currentFile = fileName Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.GtkSetImage, mpixbuf)
def resizeImage(self, widget, rectangle): if self.settingsManager.resizeImage and self.currentBooru.getCurrentFile(): iWidth = rectangle.width - 15 iHeight = rectangle.height - 15 mpixbuf = Pixbuf.new_from_file_at_scale(self.currentBooru.getCurrentFile(), iWidth, iHeight, True) self.iCurHeight = iHeight self.iCurWidth = iWidth Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.GtkSetImage, mpixbuf)
def on_about(self, action, param): about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True) about_dialog.set_authors(AUTHORS) about_dialog.set_program_name(APP_NAME) about_dialog.set_website(WEBSITE) about_dialog.set_comments(APP_COMMENTS) about_dialog.set_version(APP_VERSION) about_dialog.set_logo(Pixbuf.new_from_file_at_scale(APP_ICON, width=48, height=48, preserve_aspect_ratio=True)) about_dialog.present()
def getIcon(name, mime = None, size = None): d = os.path.join(r, 'icons') if mime == None: mime = 'png' n = ".".join([name, mime]) p = os.path.join(d, n) if size == None: i = Pixbuf.new_from_file(p) else: i = Pixbuf.new_from_file_at_scale(p, size, size, False) return i
def getIcon(name, mime=None, size=None): d = os.path.join(r, 'icons') if mime == None: mime = 'png' n = ".".join([name, mime]) p = os.path.join(d, n) if size == None: i = Pixbuf.new_from_file(p) else: i = Pixbuf.new_from_file_at_scale(p, size, size, False) return i
def _create_thumbnail(self, source_file, thumbnail_filename): # Cannot access source; create neither thumbnail nor fail file if not os.access(source_file, os.R_OK): return False try: image = Pixbuf.new_from_file_at_scale(source_file, self.thumb_size, self.thumb_size, True) dest_path = self._get_thumbnail_path(thumbnail_filename) success = True except GError: image = Pixbuf.new(GdkPixbuf.Colorspace.RGB, False, 8, 1, 1) dest_path = self._get_fail_path(thumbnail_filename) success = False width = 0 height = 0 try: with Image.open(source_file) as img: width = img.size[0] height = img.size[1] except IOError: pass options = { "tEXt::" + self.KEY_URI: str(self._get_source_uri(source_file)), "tEXt::" + self.KEY_MTIME: str(self._get_source_mtime(source_file)), "tEXt::" + self.KEY_SIZE: str(os.path.getsize(source_file)) } if width > 0 and height > 0: options["tEXt::" + self.KEY_WIDTH] = str(width) options["tEXt::" + self.KEY_HEIGHT] = str(height) # First create temporary file and then move it. This avoids problems # with concurrent access of the thumbnail cache, since "move" is an # atomic operation handle, tmp_filename = tempfile.mkstemp(dir=self.base_dir) os.close(handle) os.chmod(tmp_filename, 0o600) image.savev(tmp_filename, "png", list(options.keys()), list(options.values())) os.replace(tmp_filename, dest_path) return success
def __init__(self, cache_path, stamp_id, name, country, series, emission, face_value, issued_on, stamp_image, dist): super().__init__() self.__cache_path = cache_path self.stamp_id = stamp_id self.card_title.set_text(name) self.card_country.set_text(country) self.card_series.set_text(series) self.card_emission.set_text(emission) self.card_face_value.set_text(face_value) self.card_issued_on.set_text(issued_on) self.card_image.set_from_pixbuf( Pixbuf.new_from_file_at_scale(self.__cache_path + stamp_image[0]['path'], width=-1, height=200, preserve_aspect_ratio=True)) self.connect("event", self.hover)
def add_to_model(self, filepath): """Add an image to the model associated to the PyWebP.IconView Args: filepath: full file path of the image """ if not self.is_duplicate(filepath, 2): _basename = os.path.basename(filepath) _filesize = sizeof_fmt(os.path.getsize(filepath)) self.append([ _basename + "\nSize: " + _filesize, Pixbuf.new_from_file_at_scale( filepath, settings.get_integer_list("default_thumbsize")[0], settings.get_integer_list("default_thumbsize")[1], True), filepath, _basename, _filesize ])
def get_image(self): path = "" if os.path.exists("cache/%i.jpg" % self.id): path = "cache/%i.jpg" % self.id elif os.path.exists("cache/temp_%i.jpg" % self.id): path = "cache/temp_%i.jpg" % self.id elif os.path.exists("cache/no-image.jpg"): path = "cache/no-image.jpg" else: self.store.cache_image( 'https://static.tvmaze.com/images/no-img/no-img-portrait-text.png', "cache/no-image.jpg") path = "cache/no-image.jpg" pb = Pixbuf.new_from_file_at_scale(filename=path, width=300, height=300, preserve_aspect_ratio=True) self.image.set_from_pixbuf(pb)
def set_manga_cover_image(overlay, width, height, update=False): if overlay._pixbuf is None or update: manga = overlay.manga if manga.cover_fs_path is None: overlay._pixbuf = Pixbuf.new_from_resource('/info/febvre/Komikku/images/missing_file.png') else: if get_file_mime_type(manga.cover_fs_path) != 'image/gif': overlay._pixbuf = Pixbuf.new_from_file_at_scale(manga.cover_fs_path, 200, -1, True) else: overlay._pixbuf = scale_pixbuf_animation(PixbufAnimation.new_from_file(manga.cover_fs_path), 200, -1, True) overlay.set_size_request(width, height) image = overlay.get_children()[0] if isinstance(overlay._pixbuf, PixbufAnimation): image.set_from_animation(scale_pixbuf_animation(overlay._pixbuf, width, height, False, loop=True)) else: image.set_from_pixbuf(overlay._pixbuf.scale_simple(width, height, InterpType.BILINEAR))
def populate(self): manga = self.card.manga if manga.cover_fs_path is None: pixbuf = Pixbuf.new_from_resource_at_scale('/info/febvre/Komikku/images/missing_file.png', 174, -1, True) else: if get_file_mime_type(manga.cover_fs_path) != 'image/gif': pixbuf = Pixbuf.new_from_file_at_scale(manga.cover_fs_path, 174, -1, True) else: pixbuf = scale_pixbuf_animation(PixbufAnimation.new_from_file(manga.cover_fs_path), 174, -1, True, True) if isinstance(pixbuf, PixbufAnimation): self.cover_image.set_from_animation(pixbuf) else: self.cover_image.set_from_pixbuf(pixbuf) authors = html_escape(', '.join(manga.authors)) if manga.authors else '-' self.authors_value_label.set_markup('<span size="small">{0}</span>'.format(authors)) genres = html_escape(', '.join(manga.genres)) if manga.genres else '-' self.genres_value_label.set_markup('<span size="small">{0}</span>'.format(genres)) status = _(manga.STATUSES[manga.status]) if manga.status else '-' self.status_value_label.set_markup('<span size="small">{0}</span>'.format(status)) scanlators = html_escape(', '.join(manga.scanlators)) if manga.scanlators else '-' self.scanlators_value_label.set_markup('<span size="small">{0}</span>'.format(scanlators)) self.server_value_label.set_markup( '<span size="small">{0} [{1}] - {2} chapters</span>'.format( html_escape(manga.server.name), manga.server.lang.upper(), len(manga.chapters) ) ) self.last_update_value_label.set_markup( '<span size="small">{0}</span>'.format(manga.last_update.strftime('%m/%d/%Y')) if manga.last_update else '-') self.synopsis_value_label.set_text(manga.synopsis or '-') self.set_disk_usage()
def regenerate_thumb(): new_album = [] for alb in self.album_nf: if isfile(alb[0]): item_iter = alb[1] cover_md5 = md5(open(alb[0], 'rb').read()).hexdigest() if alb[2] == None or alb[2] != cover_md5: cover_px = Pixbuf.new_from_file_at_scale(alb[0], 150, 150, True) self.albummodel.set_value(item_iter, 0, cover_px) alb[2] = cover_md5 new_album.append(alb) else: new_album.append(alb) if len(new_album) > 0: self.album_nf = new_album return True
def show_dialog(wdg): dialog = AboutDialog() dialog.set_transient_for(self.main_window) dialog.set_artists(['Thomas Julien <*****@*****.**>']) dialog.set_authors([ 'Erwan Briand <*****@*****.**>', 'Vincent Berset <*****@*****.**>', 'Thibaut Girka <*****@*****.**>', 'Ľubomír Remák <*****@*****.**>', 'Anaël Verrier <*****@*****.**>' ]) dialog.set_translator_credits( 'Bruno Conde <*****@*****.**>\n' + 'Niklas Grahn <*****@*****.**>\n' + 'Ľubomír Remák <*****@*****.**>\n' + 'Salvatore Tomarchio <*****@*****.**>\n' + 'Shang Yuanchun <*****@*****.**>') dialog.set_copyright('Copyright © 2007-2016 Erwan Briand ' + '<*****@*****.**>') dialog.set_comments( _('Ergonomic and modern music player ' + 'designed for audiophiles.')) dialog.set_license('GNU General Public License (v3)') dialog.set_license_type(10) dialog.set_program_name('Bluemindo') dialog.set_version('1.0RC1') dialog.set_website('http://bluemindo.codingteam.net') pxbf = Pixbuf.new_from_file_at_scale( join(functions.datadir, 'image', 'logo_head_big.png'), 60, 60, True) dialog.set_logo(pxbf) dialog.show_all()
def update_preview(self, dialog, image): """Handle preview image widget inside FileChooserDialog Args: dialog: parent FileChooserDialog of the preview component image: not used """ dialog.set_preview_widget_active(False) filename = dialog.get_preview_filename() try: if filename is not None: if os.path.isfile(filename): # TODO fix error if file is not handled by pixbuf or filter by extension/data correctness _pixbuf = Pixbuf.new_from_file_at_scale( filename, 256, -1, True) have_preview = (_pixbuf != None) img = Gtk.Image.new_from_pixbuf(_pixbuf) dialog.set_preview_widget(img) dialog.set_preview_widget_active(have_preview) except GLib.GError as error: context_id = self._app.statusbar.get_context_id( "error-from-filechooser") self._app.push_status_message(error, context_id, 4)
def populate(self): manga = self.card.manga if manga.cover_fs_path is not None: pixbuf = Pixbuf.new_from_file_at_scale(manga.cover_fs_path, 174, -1, True) else: pixbuf = Pixbuf.new_from_resource_at_scale( '/info/febvre/Komikku/images/missing_file.png', 174, -1, True) self.cover_image.set_from_pixbuf(pixbuf) self.authors_value_label.set_markup( '<span size="small">{0}</span>'.format( ', '.join(manga.authors) if manga.authors else '-')) self.genres_value_label.set_markup( '<span size="small">{0}</span>'.format( ', '.join(manga.genres) if manga.genres else '-')) self.status_value_label.set_markup( '<span size="small">{0}</span>'. format(_(manga.STATUSES[manga.status])) if manga.status else '-') self.scanlators_value_label.set_markup( '<span size="small">{0}</span>'.format( ', '.join(manga.scanlators) if manga.scanlators else '-')) self.server_value_label.set_markup( '<span size="small">{0} [{1}] - {2} chapters</span>'.format( html.escape(manga.server.name), manga.server.lang.upper(), len(manga.chapters))) self.last_update_value_label.set_markup( '<span size="small">{0}</span>'. format(manga.last_update.strftime('%m/%d/%Y') ) if manga.last_update else '-') self.synopsis_value_label.set_text(manga.synopsis or '-') self.set_disk_usage()
def change_cover(wdg, ka, album): artist_name = album.artist album_name = album.name fcdialog = FileChooserDialog( title=_('Change the cover picture for this album'), buttons=(_('Select'), ResponseType.OK)) fcdialog.set_transient_for(self.widgets[0][11]) response = fcdialog.run() if response == ResponseType.OK: filename = fcdialog.get_filename() datadir = self.userconf.datadir hash_a = self.functions.get_hash(album_name, artist_name) pictures_dir = join(datadir, 'modules', 'player', 'covers') album_file = join(pictures_dir, hash_a) copyfile(filename, album_file) new = Pixbuf.new_from_file_at_scale(album_file, 180, 180, True) box.get_object('album_cover').set_from_pixbuf(new) fcdialog.destroy()
bin_path = split(argv[0])[0] icons_path = "icons/formiko.svg" share_path = join("share/formiko", icons_path) while (bin_path != '/'): # this work to /opt /usr /usr/local prefixes if exists(join(bin_path, share_path)): return join(bin_path, share_path) if exists(join(bin_path, icons_path)): return join(bin_path, icons_path) bin_path = split(bin_path)[0] ICON_PATH = get_path() if ICON_PATH: icon_16 = Pixbuf.new_from_file_at_scale(ICON_PATH, 16, 16, True) icon_32 = Pixbuf.new_from_file_at_scale(ICON_PATH, 32, 32, True) icon_48 = Pixbuf.new_from_file_at_scale(ICON_PATH, 48, 48, True) icon_64 = Pixbuf.new_from_file_at_scale(ICON_PATH, 64, 64, True) icon_128 = Pixbuf.new_from_file_at_scale(ICON_PATH, 128, 128, True) else: from gi.repository.Gtk import IconTheme from gi.repository.GLib import log_default_handler, LogLevelFlags log_default_handler("Application", LogLevelFlags.LEVEL_ERROR, "Formiko icon not found", 0) icon_theme = IconTheme.get_default() icon_16 = icon_theme.load_icon("text-editor-symbolic", 16, 0) icon_32 = icon_theme.load_icon("text-editor-symbolic", 32, 0) icon_48 = icon_theme.load_icon("text-editor-symbolic", 48, 0) icon_64 = icon_theme.load_icon("text-editor-symbolic", 64, 0)
def main(): for size in (16, 22, 24, 32, 48, 64, 128, 256, 512): icon = Pixbuf.new_from_file_at_scale("formiko.svg", size, size, True) makedirs("%dx%d" % (size, size)) icon.savev("%dx%d/formiko.png" % (size, size), "png", [], [])
def start_playback(wdg): # Create GStreamer instance self.gst = GStreamer() self.gst.set_playback('gapless') self.gst.player.connect('about-to-finish', self.song_nearly_ended) self.gst.stop() self.current_song = False self.current_album = False # Prepare buttons self.btn_playpause = wdg[0][7] self.btn_previous = wdg[0][5] self.btn_next = wdg[0][8] self.btn_stop = wdg[0][6] self.btn_previous.connect('clicked', self.previous_pressed) self.btn_stop.connect('clicked', self.stop_pressed) self.btn_playpause.connect('clicked', self.play_pressed) self.btn_next.connect('clicked', self.next_pressed) self.btn_player = wdg[0][9] self.headerbar = wdg[0][0] # Create the player box and popover gtkpla = join(self.functions.datadir, 'glade', 'playerbar.ui') win = gtk_builder() win.set_translation_domain('bluemindo') win.add_from_file(gtkpla) basebox = win.get_object('playerbox') wdg[0][0].add(basebox) self.player_event = win.get_object('player_event') self.player_event.set_size_request(32, 32) self.player_button_img = win.get_object('image_cover') self.player_event.connect('button-press-event', self.show_player) default = join(self.functions.datadir, 'image', 'logo_head_big.png') cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True) self.player_button_img.set_from_pixbuf(cover_px) self.player_event.set_sensitive(False) self.player_scalab = win.get_object('label_scale') self.player_scalab.set_markup('<span size="small">00:00</span>') self.player_sca = win.get_object('scale') self.player_sca.connect('change-value', self.on_change_value) self.player_sca.set_sensitive(False) # Create the player popover gtkpla = join(self.functions.datadir, 'glade', 'playerpopover.ui') win = gtk_builder() win.add_from_file(gtkpla) hbox = win.get_object('box-player') self.player_img = win.get_object('image') self.player_pop = Popover.new(self.player_event) self.player_pop.set_size_request(200, 200) self.player_pop.add(hbox) self.lyrics_button = wdg[1].get_object('tool-lyrics') self.lyrics_pop = Popover.new(self.lyrics_button) self.lyrics_pop.set_size_request(400, 600) box = Box(1, 0) self.lyrics_swin = ScrolledWindow() lyrics_tview = TextView() lyrics_tview.set_editable(False) self.lyrics_buffer = TextBuffer() lyrics_tview.set_buffer(self.lyrics_buffer) self.lyrics_swin.add(lyrics_tview) box.add(self.lyrics_swin) self.lyrics_wait = Spinner() self.lyrics_wait.props.active = True box.add(self.lyrics_wait) self.lyrics_pop.add(box) def show_lyrics(widget): if self.current_song: title = self.current_song.title artist = self.current_song.artist album = self.current_song.album filename = self.current_song.filename sn = self.functions.get_hash(title, artist) lyrics_file = join(self.userconf.datadir, '%s.lyrics' % sn) lyrics = self.lyrics_downloader.get_lyrics(title, artist, True) self.lyrics_pop.show_all() if lyrics is not None: self.lyrics_wait.hide() self.lyrics_swin.show() self.lyrics_buffer.set_text(lyrics) else: self.lyrics_swin.hide() self.lyrics_wait.show() self.lyrics_buffer.set_text('') self.lyrics_button.connect('clicked', show_lyrics) self.lyrics_button.set_sensitive(False)
def on_play_new_song(self, song): # Guess ReplayGain mode if hasattr(song, 'rg_mode_guess') and song.rg_mode_guess == 'album': self.gst.change_rg_mode('album') else: if not self.current_album: self.gst.change_rg_mode('track') else: if song in self.current_album.tracks: self.gst.change_rg_mode('album') else: self.current_album = False self.gst.change_rg_mode('track') # Play the song cur = self.gst.getnow() self.gst.playpause(song.filename) # Update global vars self.current_song = song # Update user interface self.btn_playpause.set_image(Image.new_from_gicon(ThemedIcon( name='media-playback-pause-symbolic'), IconSize.BUTTON)) title = song.title artist = song.artist album = song.album filename = song.filename self.headerbar.props.subtitle = title + ' - ' + artist default = join(self.functions.datadir, 'image', 'logo_head_big.png') bdir = join(self.userconf.datadir, 'modules', 'player', 'covers') cover = join(bdir, self.functions.get_hash(album, artist)) if isfile(cover): cover_px = Pixbuf.new_from_file_at_scale(cover, 32, 32, True) else: cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True) self.player_button_img.set_from_pixbuf(cover_px) self.player_event.set_sensitive(True) self.lyrics_button.set_sensitive(True) # Update file current_playing = join(self.userconf.datadir, 'current-playing') file_ = open(current_playing, 'w') file_.write(title + ' - ' + artist + ' (from: ' + album + ')') file_.close() # Update player informations if isfile(cover): cover_px = Pixbuf.new_from_file_at_scale(cover, 200, 200, True) else: cover_px = Pixbuf.new_from_file_at_scale(default, 120, 120, True) self.player_img.set_from_pixbuf(cover_px) # Create the scale self.player_sca.set_sensitive(True) self.player_sca.set_range(0, float(song.length)) timeout_add(500, self.scale_timer) # Download lyrics thread = Thread(group=None, target=self.lyrics_downloader.get_lyrics, name='lyrics', args=(title, artist)) thread.start() # Send notification to extensions about this new song self.extensions.load_event('HasStartedSong', song)
def on_about(self, button): """Create and display an about us dialog window Args: button: button who trigger the open action Returns: a modal about dialog """ about_dialog = Gtk.AboutDialog(transient_for=self.window, modal=True, decorated=True, use_header_bar=True) about_dialog.connect("response", self.on_close) about_dialog.set_logo( Pixbuf.new_from_file_at_scale(LOGO_PATH, 128, 128, True)) about_dialog.set_authors(["Nicola Tudino <https://github.com/tudo75>"]) about_dialog.set_program_name("PyWebP-Gtk") about_dialog.set_version('v0.0.1.dev0') about_dialog.set_comments( '\nPyWebP-Gtk is a utility tool developed on Python3 and PyGobject3.\n' 'Lets you convert image files to/from webp format.\n' '') about_dialog.set_website("http://github.com/tudo75/PyWebP-Gtk") about_dialog.set_website_label("Github Code Repository") about_dialog.set_copyright('Copyright \xa9 2020-2021 Tudo75') about_dialog.set_documenters([ 'Nicola Tudino <https://github.com/tudo75>', ]) about_dialog.add_credit_section( 'Webptools package', ['Sai Kumar Yava <https://github.com/scionoftech>']) about_dialog.set_license_type(Gtk.License.MIT_X11) about_dialog.set_license(''' MIT License Copyright (c) 2020-2021 Nicola Tudino a.k.a. tudo75 <https://github.com/tudo75> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ''') # hack to remove doubled buttons hbar = about_dialog.get_header_bar() for child in hbar.get_children(): if type(child) in [Gtk.Button, Gtk.ToggleButton]: child.destroy() # show the about dialog about_dialog.run() about_dialog.destroy()
def _create_window_structure(self): """Generate the Gui structure """ self.header_bar.set_title("PyWebP-Gtk") self.header_bar.set_has_subtitle(False) self.header_bar.set_show_close_button(True) # about_btn = Gtk.Button.new_from_icon_name("application-system", Gtk.IconSize.LARGE_TOOLBAR) about_btn = Gtk.Button() about_btn.set_image( Gtk.Image.new_from_pixbuf( Pixbuf.new_from_file_at_scale(LOGO_PATH, 32, 32, True))) # about_btn.set_image(Gtk.Image.new_from_file(about_icon_path)) about_btn.connect("clicked", self.on_about) self.header_bar.pack_start(about_btn) settings_btn = Gtk.Button() settings_btn.set_image( Gtk.Image.new_from_icon_name('emblem-system-symbolic', Gtk.IconSize.DND)) self.init_popover(settings_btn, SettingsPanel(self)) self.header_bar.pack_end(settings_btn) self.window.set_titlebar(self.header_bar) scroll_win = Gtk.ScrolledWindow() scroll_win.add(self.iconview) self.statusbar.set_border_width(0) self.statusbar.set_vexpand(False) self.statusbar.set_margin_left(0) self.statusbar.set_margin_top(0) self.statusbar.set_margin_right(0) self.statusbar.set_margin_bottom(0) self.statusbar.set_vexpand(False) """ v_box = Gtk.VBox() v_box.add(self.iconview) v_box.add(self.toolbar) v_box.add(self.statusbar) self.window.add(v_box) """ grid = Gtk.Grid() grid.set_column_spacing(5) grid.set_row_spacing(5) grid.set_column_homogeneous(True) grid.set_row_homogeneous(False) grid.attach(scroll_win, 0, 0, 2, 1) grid.attach(self.toolbar, 0, 1, 2, 1) grid.attach(self.statusbar, 0, 2, 2, 1) grid.set_vexpand(True) self.window.add(grid) geometry = settings.get_integer_list("geometry") self.window.resize(geometry[0], geometry[1]) self.window.set_position(Gtk.WindowPosition.CENTER) self.window.set_icon( Pixbuf.new_from_file_at_scale(LOGO_PATH, 32, 32, True)) self.window.set_default_icon( Pixbuf.new_from_file_at_scale(LOGO_PATH, 32, 32, True))
def append_autocompletion(name, kind): fnf = join(self.functions.datadir, 'image', 'logo_head_big.png') if kind == 1: # Artist icon = 'face-smile-symbolic' pic = join(self.userconf.datadir, 'modules', 'explorer', 'artists', self.functions.get_hash(name, 'picture')) try: if isfile(pic): pxbf = Pixbuf.new_from_file_at_scale(pic, 70, 70, True) else: pxbf = Pixbuf.new_from_file_at_scale(fnf, 70, 70, True) artists_without_picture.append(name) except GLIBError: pxbf = Pixbuf.new_from_file_at_scale(fnf, 70, 70, True) dname = '<b>' + self.functions.view_encode(name, 99) + '</b>' infos = ('<b>' + _('Artist') + '</b>\n' + _('%s albums in collection.' % ('<b>' + str(len(self.songs_tree[name])) + '</b>'))) add = 'blm.!ARTIST!' add_a = '' add_b = '' elif kind == 2: # Album icon = 'media-optical-symbolic' artist = name[0] name = name[1] cover = join(self.userconf.datadir, 'modules', 'player', 'covers', self.functions.get_hash(name, artist)) if isfile(cover): pxbf = Pixbuf.new_from_file_at_scale(cover, 70, 70, True) else: pxbf = Pixbuf.new_from_file_at_scale(fnf, 70, 70, True) albums_without_cover.append([artist, name]) dname = ('<b>' + self.functions.view_encode(name, 99) + '</b>\n<i>' + self.functions.view_encode(artist, 99) + '</i>') length = 0 songs = 0 for song in self.songs_tree[artist][name]: songs += 1 length += song[7] hlgth = self.functions.human_length(length) infos = (_('%s songs' % ('<b>' + str(songs) + '</b>')) + '\n' + _('Total playing time: %s.' % ('<i>' + hlgth + '</i>'))) self.cur_pxbf = pxbf add = artist add_a = '' add_b = '' elif kind == 3: # Song icon = 'media-record-symbolic' artist = name[1] album = name[2] add = name[8] add_a = artist add_b = album name = name[0] dname = ('<b>' + self.functions.view_encode(name, 99) + '</b>\n<i>' + self.functions.view_encode(artist, 99) + ' - ' + self.functions.view_encode(album, 99) + '</i>') infos = '<b>' + _('Song') + '</b>' pxbf = self.cur_pxbf self.completion_model.append( [pxbf, dname, infos, icon, name, add, add_a, add_b])
def __init__(self, game): super().__init__(game) self.timer = None self.board = [] for _ in range(0, 4): self.board.append([None] * 13) self.builder = Gtk.Builder.new() self.builder.add_objects_from_file(GameGtk.filename, [ 'win_main', 'img_move', 'img_shuffle', 'dlg_about', 'dlg_quit', 'dlg_result' ]) self.builder.connect_signals(self) self.win_main = self.builder.get_object('win_main') self.lbl_time = self.builder.get_object('lbl_time') self.lbl_shuffles = self.builder.get_object('lbl_shuffles') self.lbl_moves = self.builder.get_object('lbl_moves') self.lbl_sequence = self.builder.get_object('lbl_sequence') self.lbl_status = self.builder.get_object('lbl_status') self.lbl_result = self.builder.get_object('lbl_result') self.img_result_1 = self.builder.get_object('img_result_1') self.img_result_2 = self.builder.get_object('img_result_2') self.mitm_move = self.builder.get_object('mitm_move') self.mitm_undo = self.builder.get_object('mitm_undo') self.mitm_shuffle = self.builder.get_object('mitm_shuffle') self.btn_undo = self.builder.get_object('btn_undo') self.btn_shuffle = self.builder.get_object('btn_shuffle') self.dlg_about = self.builder.get_object('dlg_about') self.dlg_quit = self.builder.get_object('dlg_quit') self.dlg_result = self.builder.get_object('dlg_result') self.win_main.show_all() for i in range(0, 4): for j in range(0, 13): drw = self.builder.get_object('drw_{}_{}'.format(i, j)) drw.connect('button-press-event', self.action_button_press, self.game.points[i][j]) drw.connect('draw', self.draw_card, self.game.points[i][j]) self.board[i][j] = drw cards_dir = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'cards') allocation = self.board[0][0].get_allocation() self.card_width = allocation.width - 2 * self.settings.border self.card_height = allocation.height - 2 * self.settings.border self.cards = dict() for s in Suit: self.cards[s] = dict() for c in Face: filename = os.path.join(cards_dir, s.dirname, c.filename) self.cards[s][c] = \ GdkPixbuf.new_from_file_at_scale(filename, self.card_width, self.card_height, False) self.css_win = CSS('label', { 'font-weight': 'bold', 'color': 'green' }).get_provider() self.css_lose = CSS('label', { 'font-weight': 'bold', 'color': 'red' }).get_provider() self.css_stuck = CSS('label', { 'font-weight': 'bold', 'color': 'orange' }).get_provider()
bin_path = split(argv[0])[0] icons_path = "icons/formiko.svg" share_path = join("share/formiko", icons_path) while (bin_path != '/'): # this work to /opt /usr /usr/local prefixes if exists(join(bin_path, share_path)): return join(bin_path, share_path) if exists(join(bin_path, icons_path)): return join(bin_path, icons_path) bin_path = split(bin_path)[0] ICON_PATH = get_path() if ICON_PATH: icon_16 = Pixbuf.new_from_file_at_scale(ICON_PATH, 16, 16, True) icon_32 = Pixbuf.new_from_file_at_scale(ICON_PATH, 32, 32, True) icon_48 = Pixbuf.new_from_file_at_scale(ICON_PATH, 48, 48, True) icon_64 = Pixbuf.new_from_file_at_scale(ICON_PATH, 64, 64, True) icon_128 = Pixbuf.new_from_file_at_scale(ICON_PATH, 128, 128, True) else: from gi.repository.Gtk import IconTheme from gi.repository.GLib import log_default_handler, LogLevelFlags log_default_handler(None, LogLevelFlags.LEVEL_FATAL, "Formiko icon not found", 0) icon_theme = IconTheme.get_default() icon_16 = icon_theme.load_icon("text-editor-symbolic", 16, 0) icon_32 = icon_theme.load_icon("text-editor-symbolic", 32, 0) icon_48 = icon_theme.load_icon("text-editor-symbolic", 48, 0) icon_64 = icon_theme.load_icon("text-editor-symbolic", 64, 0)
import asyncio from threading import Thread from logging import getLogger from threading import RLock from urllib.request import urlopen from typing import List from gi.repository import Gio, GObject # type: ignore from gi.repository.GdkPixbuf import Pixbuf # type: ignore LOGGER = getLogger(__name__) log_debug = LOGGER.debug SOUND_PIXBUF = Pixbuf.new_from_file_at_scale('controlP/music.png', 64, 64, True) class RefreshPixbuf(Thread): def __init__(self, props, url): super().__init__() self.props = props self.url = url def run(self): log_debug('RefreshPixbuf run {}'.format(self.url)) response = urlopen(self.url) if not response: return input_stream = Gio.MemoryInputStream.new_from_data( response.read(), None) if not input_stream: return
def buildPage1(self): page1 = Gtk.Box() page1.set_name("page1") page1.border_width = 0 self.stack.add_named(page1, "page1") to_right = Gtk.Alignment.new(100, 0, 0, 0) setting_icon = Gtk.Button() setting_icon.set_image( Gtk.Image.new_from_stock("gtk-preferences", Gtk.IconSize.DND)) setting_icon.set_relief(Gtk.ReliefStyle.NONE) setting_icon.connect("button-press-event", self.event_settings) to_right.add(setting_icon) vbox = Gtk.VBox() vbox.add(to_right) alignment = Gtk.Alignment.new(0, 0, 0, 0) alignment.set_padding(10, 10, 10, 10) alignment.add(vbox) page1.pack_start(alignment, True, True, 0) try: groups = {} with open(self.config_file) as json_file: data = json.load(json_file) for group in data["groups"]: group_data = {} group_data["title"] = group["title"] group_data["commands"] = {} groups[group["id"]] = group_data for command in data["commands"]: command_data = groups[command["group"]]["commands"] command_data[command["id"]] = {} command_data[command["id"]]["title"] = command["title"] command_data[command["id"]]["command"] = command["command"] command_data[command["id"]]["image"] = command["image"] for group_id in groups: group = groups[group_id] group_title = group["title"] commands = group["commands"] padding = Gtk.Alignment() padding.set_padding(10, 10, 0, 0) label = Gtk.Label() label.set_markup("<span weight='bold' font='14'>" + group_title + "</span>") if not self.config_usesystemstyle: label.override_color(Gtk.StateType.NORMAL, self.color_text) label.set_xalign(0) padding.add(label) vbox.add(padding) listStore = Gtk.ListStore(Pixbuf, str, str) iconview = Gtk.IconView.new() if not self.config_usesystemstyle: color = Gdk.RGBA() color.alpha = 0 iconview.override_background_color(Gtk.StateType.NORMAL, color) iconview.set_model(listStore) iconview.set_columns(self.config_maxcol) iconview.set_pixbuf_column(0) iconview.set_markup_column(1) iconview.set_column_spacing(0) iconview.set_row_spacing(0) iconview.set_activate_on_single_click(True) iconview.set_item_orientation(Gtk.Orientation.VERTICAL) iconview.connect("item-activated", self.event_command) for command_id in commands: command = commands[command_id] px = Pixbuf.new_from_file_at_scale( filename=command["image"], width=self.config_imagesize, height=self.config_imagesize, preserve_aspect_ratio=True) title = command["title"] if not self.config_usesystemstyle: title = "<span weight='bold' color='" + self.config_textcolor + "'>" + command[ "title"] + "</span>" listStore.append([px, title, command["command"]]) vbox.add(iconview) except: error_label = Gtk.Label() error_label.set_markup("<span font='11'>" + "Wrong configuration file!" + "</span>") if not self.config_usesystemstyle: error_label.override_color(Gtk.StateType.NORMAL, self.color_text) vbox.pack_start(error_label, True, True, 20)
def on_selection_changed(self, icon_view, album=None): popup = Popover.new(self.albumview) popup.set_size_request(810, 240) if album is None: selection = icon_view.get_selected_items() if len(selection) != 1: return path = selection[0] treeiter = self.albumfilter.get_iter(path) isset, path, cell = icon_view.get_cursor() isset, rect = icon_view.get_cell_rect(path, cell) popup.set_pointing_to(rect) album_id = self.albumfilter.get_value(treeiter, 4) album_obj = self.albums[album_id] else: album_obj = album popup.set_relative_to(self.search_entry) # Handle double clicks def empty_dblclick(): self.dblclick = None if self.dblclick is None: self.dblclick = album_obj timeout_add(1000, empty_dblclick) elif self.dblclick == album_obj: self.play(album_obj) return album = album_obj.name artist = album_obj.artist glade_album = join(self.functions.datadir, 'glade', 'albumview.ui') box = gtk_builder() box.set_translation_domain('bluemindo') box.add_from_file(glade_album) popup.add(box.get_object('box1')) box.get_object('label_album').set_text(album) box.get_object('label_artist').set_text(artist) bdir = join(self.userconf.datadir, 'modules', 'player', 'covers') cover = join(bdir, self.functions.get_hash(album, artist)) if isfile(cover): cover_px = Pixbuf.new_from_file_at_scale(cover, 180, 180, True) else: cover_px = Pixbuf.new_from_file(join(self.functions.datadir, 'image', 'logo_head_big.png')) box.get_object('album_cover').set_from_pixbuf(cover_px) def play_album(wdg, album): self.play(album) def queue_album(wdg, album): self.queue(album) def change_cover(wdg, ka, album): artist_name = album.artist album_name = album.name fcdialog = FileChooserDialog( title=_('Change the cover picture for this album'), buttons=(_('Select'), ResponseType.OK)) fcdialog.set_transient_for(self.widgets[0][11]) response = fcdialog.run() if response == ResponseType.OK: filename = fcdialog.get_filename() datadir = self.userconf.datadir hash_a = self.functions.get_hash(album_name, artist_name) pictures_dir = join(datadir, 'modules', 'player', 'covers') album_file = join(pictures_dir, hash_a) copyfile(filename, album_file) new = Pixbuf.new_from_file_at_scale(album_file, 180, 180, True) box.get_object('album_cover').set_from_pixbuf(new) fcdialog.destroy() box.get_object('button_play').connect('clicked', play_album, album_obj) box.get_object('button_add').connect('clicked', queue_album, album_obj) box.get_object('coverevent').connect('button-press-event', change_cover, album_obj) i = 0 a = -1 previous_column = 0 grid_songs = box.get_object('grid_songs') grid_songs.set_size_request(-1, 200) grid_songs.set_column_spacing(5) try: kids = grid_songs.get_children() for kid in kids: grid_songs.remove(kid) except IndexError: pass for song in album_obj.tracks: i += 1 a += 1 def queue(wdg, song): self.queue(song) def play(wdg, song): self.play(song) song_wdg = Box(spacing=0) song_btr = Button() song_btr.connect('clicked', play, song) song_btr.set_relief(ReliefStyle.NONE) song_btr_content = Box(spacing=0) song_btr.add(song_btr_content) song_tr = Label() song_tr.set_markup('<span foreground="grey">' + str(song.track) + '</span>') song_tr.set_width_chars(3) song_btr_content.pack_start(song_tr, False, True, 0) song_ti = Label() song_ti.set_markup('<b>' + self.functions.view_encode(song.title, 22) + '</b>') song_ti.set_alignment(0.0, 0.5) song_ti.set_size_request(190, -1) song_btr_content.pack_start(song_ti, False, False, 0) length = self.functions.human_length(song.length) song_le = Label() song_le.set_markup('<span foreground="grey">' + length + '</span>') song_le.set_width_chars(5) song_btr_content.pack_start(song_le, False, True, 0) song_wdg.pack_start(song_btr, False, False, 0) song_add = Button.new_from_icon_name('list-add-symbolic', 0) song_add.set_property('relief', 2) song_add.set_size_request(14, 14) song_add.connect('clicked', queue, song) song_wdg.pack_start(song_add, False, False, 0) if i <= len(album_obj.tracks)/2: column = 0 previous_column = 0 row = a else: if previous_column == 0: a = 0 column = 1 previous_column = 1 row = a grid_songs.attach(song_wdg, column, row, 1, 1) popup.show_all()
def populate_albums(self, albums_tree, albums, songs_tree, search): self.albums_tree = albums_tree self.albums = albums self.songs_tree = songs_tree self.search_entry = search.searchentry # Clear the tree model first self.albummodel.clear() # Show albums in the main explorer view self.album_nf = [] album_id = 0 for alb in self.albums_tree: bdir = join(self.userconf.datadir, 'modules', 'player', 'covers') album = alb['album'] artist = alb['artist'] cover = join(bdir, self.functions.get_hash(album, artist)) if isfile(cover): cover_px = Pixbuf.new_from_file_at_scale(cover, 150, 150, True) else: cover_px = Pixbuf.new_from_file(join(self.functions.datadir, 'image', 'logo_head_big.png')) self.albums[album_id] = Album(artist, album, self.songs_tree) ap = self.albummodel.append([cover_px, '<b>' + self.functions.view_encode(album) + '</b>\n<span foreground="grey">' + self.functions.view_encode(artist) + '</span>', artist, album, album_id, '', '']) album_id += 1 if not isfile(cover): self.album_nf.append([cover, ap, None]) # Check if we have to regenerate thumbnail (cover not found at startup) if len(self.album_nf) > 0: def regenerate_thumb(): new_album = [] for alb in self.album_nf: if isfile(alb[0]): item_iter = alb[1] cover_md5 = md5(open(alb[0], 'rb').read()).hexdigest() if alb[2] == None or alb[2] != cover_md5: cover_px = Pixbuf.new_from_file_at_scale(alb[0], 150, 150, True) self.albummodel.set_value(item_iter, 0, cover_px) alb[2] = cover_md5 new_album.append(alb) else: new_album.append(alb) if len(new_album) > 0: self.album_nf = new_album return True timeout_add(15000, regenerate_thumb)