From c9daa8a599a033d311ec02049909145f5de7606c Mon Sep 17 00:00:00 2001 From: DYefremov Date: Sat, 10 Aug 2024 10:54:31 +0300 Subject: [PATCH] small refactoring --- app/ui/control.py | 11 ++++------- app/ui/main_helper.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/ui/control.py b/app/ui/control.py index 371c4486..f99ccf41 100644 --- a/app/ui/control.py +++ b/app/ui/control.py @@ -2,7 +2,7 @@ # # The MIT License (MIT) # -# Copyright (c) 2018-2023 Dmitriy Yefremov +# Copyright (c) 2018-2024 Dmitriy Yefremov # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -32,8 +32,9 @@ import re from gi.repository import GLib +from .main_helper import redraw_image from .dialogs import get_builder, translate -from .uicommons import Gtk, Gdk, UI_RESOURCES_PATH +from .uicommons import Gtk, UI_RESOURCES_PATH from ..commons import run_task, run_with_delay, log, run_idle from ..connections import HttpAPI from ..settings import IS_DARWIN, IS_LINUX, IS_WIN @@ -201,11 +202,7 @@ class ControlTool(Gtk.Box): def on_screenshot_draw(self, area, cr): """ Called to automatically resize the screenshot. """ if self._pix: - cr.scale(area.get_allocated_width() / self._pix.get_width(), - area.get_allocated_height() / self._pix.get_height()) - img_surface = Gdk.cairo_surface_create_from_pixbuf(self._pix, 1, None) - cr.set_source_surface(img_surface, 0, 0) - cr.paint() + redraw_image(area, cr, self._pix) def on_screenshot_all(self, action, value=None): if self._app.http_api: diff --git a/app/ui/main_helper.py b/app/ui/main_helper.py index 2c6eefa5..b6af17b8 100644 --- a/app/ui/main_helper.py +++ b/app/ui/main_helper.py @@ -855,7 +855,7 @@ def get_iptv_data(fav_id): def on_popup_menu(menu, event): - """ Shows popup menu for the view """ + """ Shows popup menu for the view. """ if event.get_event_type() == Gdk.EventType.BUTTON_PRESS and event.button == Gdk.BUTTON_SECONDARY: menu.popup(None, None, None, None, event.button, event.time) @@ -868,5 +868,14 @@ def show_info_bar_message(bar, label, text, message_type=Gtk.MessageType.INFO): bar.set_visible(True) +def redraw_image(area, cr, pixbuf): + """ Helper method to redraw (auto resize) image in the Gtk DrawingArea. """ + cr.scale(area.get_allocated_width() / pixbuf.get_width(), + area.get_allocated_height() / pixbuf.get_height()) + img_surface = Gdk.cairo_surface_create_from_pixbuf(pixbuf, 1, None) + cr.set_source_surface(img_surface, 0, 0) + cr.paint() + + if __name__ == "__main__": pass