This commit is contained in:
Benjamin Schaaf
2021-02-13 23:56:43 +11:00
parent 95c3e5a018
commit 14a7b2bb77
3 changed files with 35 additions and 17 deletions

0
flatpak/flatpak_build.sh Executable file
View File

View File

@@ -3,7 +3,7 @@ from typing import Optional
from gi.repository import Gdk, GdkPixbuf, Gtk
class SpinnerPicture(Gtk.Overlay):
class SpinnerPicture(Gtk.Bin):
def __init__(
self,
loading: bool = True,
@@ -15,9 +15,8 @@ class SpinnerPicture(Gtk.Overlay):
self.filename: Optional[str] = None
self.pixbuf = None
self.drawing_area = Gtk.DrawingArea()
self.drawing_area.connect("draw", self.expose)
self.add_overlay(self.drawing_area)
self.offset = (0, 0)
self.sized_pixbuf = None
self.spinner = Gtk.Spinner(
name=spinner_name,
@@ -25,7 +24,7 @@ class SpinnerPicture(Gtk.Overlay):
halign=Gtk.Align.CENTER,
valign=Gtk.Align.CENTER,
)
self.add_overlay(self.spinner)
self.add(self.spinner)
def set_from_file(self, filename: Optional[str]):
"""Set the picture to the given filename."""
@@ -39,6 +38,7 @@ class SpinnerPicture(Gtk.Overlay):
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.filename)
else:
self.pixbuf = None
self._update_sized_pixbuf()
def set_loading(self, loading_status: bool):
if loading_status:
@@ -48,16 +48,34 @@ class SpinnerPicture(Gtk.Overlay):
self.spinner.stop()
self.spinner.hide()
def expose(self, area, cr):
if self.pixbuf:
pix_width = self.pixbuf.get_width()
pix_height = self.pixbuf.get_height()
alloc_width = self.get_allocated_width()
alloc_height = self.get_allocated_height()
def do_size_allocate(self, allocation):
Gtk.Bin.do_size_allocate(self, allocation)
cr.translate(alloc_width / 2, alloc_height / 2);
scale = max(alloc_width / pix_width, alloc_height / pix_height)
cr.scale(scale, scale)
cr.translate(-pix_width / 2, -pix_height / 2);
Gdk.cairo_set_source_pixbuf(cr, self.pixbuf, 0, 0)
self._update_sized_pixbuf()
def do_draw(self, cr):
if self.sized_pixbuf:
Gdk.cairo_set_source_pixbuf(cr, self.sized_pixbuf, self.offset[0], self.offset[1])
cr.paint()
Gtk.Bin.do_draw(self, cr)
def _update_sized_pixbuf(self):
if self.pixbuf is None:
self.sized_pixbuf = None
return
pix_width = self.pixbuf.get_width()
pix_height = self.pixbuf.get_height()
alloc_width = self.get_allocated_width()
alloc_height = self.get_allocated_height()
scale = max(alloc_width / pix_width, alloc_height / pix_height)
scaled_width = pix_width * scale
scaled_height = pix_height * scale
self.sized_pixbuf = self.pixbuf.scale_simple(scaled_width, scaled_height, GdkPixbuf.InterpType.BILINEAR)
self.offset = (
(alloc_width - scaled_width) / 2,
(alloc_height - scaled_height) / 2,
)

View File

@@ -143,7 +143,7 @@ class MainWindow(Gtk.ApplicationWindow):
# Toggle drawer when handle is pressed
def toggle_drawer(handle, event):
if event.get_click_count() != (True, 1) or not drawer.get_swipe_to_open():
if event.get_click_count() != (True, 1) or not drawer.get_swipe_to_open() or event.device.get_source() == Gdk.InputSource.TOUCHSCREEN:
return
drawer.set_reveal_flap(not drawer.get_reveal_flap())