Moved mirage2 to use newer GTK template structure patterns
This commit is contained in:
@@ -30,7 +30,7 @@ class ButtonControls(Gtk.ButtonBox):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
icons_path = settings.get_icons_path()
|
||||
icons_path = settings_manager.path_manager.get_icons_path()
|
||||
center_widget = Gtk.ButtonBox()
|
||||
zoomout_button = Gtk.Button()
|
||||
lrotate_button = Gtk.Button()
|
||||
@@ -97,32 +97,32 @@ class ButtonControls(Gtk.ButtonBox):
|
||||
self.set_center_widget(center_widget)
|
||||
|
||||
def _zoom_out(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_out")
|
||||
event_system.emit("zoom-out")
|
||||
|
||||
def _rotate_left(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_left")
|
||||
event_system.emit("rotate-left")
|
||||
|
||||
def _vertical_flip(self, widget = None, eve = None):
|
||||
event_system.emit("vertical_flip")
|
||||
event_system.emit("vertical-flip")
|
||||
|
||||
def _scale_1_two_1(self, widget = None, eve = None):
|
||||
self._unset_class(self.fit_button)
|
||||
self._set_class(self.one2one_button)
|
||||
event_system.emit("scale_1_two_1")
|
||||
event_system.emit("scale-1-to-1")
|
||||
|
||||
def _fit_to_container(self, widget = None, eve = None):
|
||||
self._unset_class(self.one2one_button)
|
||||
self._set_class(self.fit_button)
|
||||
event_system.emit("fit_to_container")
|
||||
event_system.emit("fit-to-container")
|
||||
|
||||
def _horizontal_flip(self, widget = None, eve = None):
|
||||
event_system.emit("horizontal_flip")
|
||||
event_system.emit("horizontal-flip")
|
||||
|
||||
def _rotate_right(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_right")
|
||||
event_system.emit("rotate-right")
|
||||
|
||||
def _zoom_in(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_in")
|
||||
event_system.emit("zoom-in")
|
||||
|
||||
def _set_class(self, target):
|
||||
ctx = target.get_style_context()
|
||||
@@ -133,4 +133,4 @@ class ButtonControls(Gtk.ButtonBox):
|
||||
ctx.remove_class("button-highlighted")
|
||||
|
||||
def _show_ocr(self, widget):
|
||||
event_system.emit("show_ocr")
|
||||
event_system.emit("show-ocr")
|
||||
|
||||
@@ -18,8 +18,8 @@ class Image(Gtk.EventBox):
|
||||
def __init__(self, path: str):
|
||||
super(Image, self).__init__()
|
||||
|
||||
self._thumbnail_with = settings.get_thumbnail_with()
|
||||
self._thumbnail_height = settings.get_thumbnail_height()
|
||||
self._thumbnail_with = settings_manager.settings.config.thumbnail_with
|
||||
self._thumbnail_height = settings_manager.settings.config.thumbnail_height
|
||||
self.is_loaded = False
|
||||
self.image = None
|
||||
self.path = path
|
||||
@@ -45,7 +45,7 @@ class Image(Gtk.EventBox):
|
||||
|
||||
def set_image_to_view(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
event_system.emit("handle_file_from_dnd", (self.path, ))
|
||||
event_system.emit("handle-file-from-dnd", (self.path, ))
|
||||
|
||||
def load_pixbuf(self):
|
||||
self.set_from_pixbuf( self.get_pixbuf_data(self.path, \
|
||||
@@ -56,7 +56,7 @@ class Image(Gtk.EventBox):
|
||||
def set_from_pixbuf(self, pixbuf):
|
||||
self.image.set_from_pixbuf(pixbuf)
|
||||
|
||||
def get_pixbuf_data(self, path, w = 126, h = 126):
|
||||
def get_pixbuf_data(self, path: str, w: int = 126, h: int = 126):
|
||||
path = self.path if not path else path
|
||||
pixbuf = None
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ class ImageList(Gtk.Box):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("load_image_list", self.load_image_list)
|
||||
event_system.subscribe("load-image-list", self.load_image_list)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def _clear_children(self, widget: type) -> None:
|
||||
def _clear_children(self, widget: Gtk.Object) -> None:
|
||||
''' Clear children of a gtk widget. '''
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
@@ -49,9 +49,10 @@ class ImageList(Gtk.Box):
|
||||
path = os.path.join(self.path, img)
|
||||
paths.append(path)
|
||||
|
||||
paths.sort()
|
||||
return paths
|
||||
|
||||
def load_image_list(self, path = None, img_list: [] = []):
|
||||
def load_image_list(self, path: str, img_list: list = []):
|
||||
if not path or len(img_list) == 0:
|
||||
return
|
||||
|
||||
@@ -64,10 +65,14 @@ class ImageList(Gtk.Box):
|
||||
for file in paths:
|
||||
self.add( Image(file) )
|
||||
|
||||
event_system.emit("update_list_size_constraints", (len(paths),))
|
||||
event_system.emit("update-list-size-constraints", (len(paths),))
|
||||
self.show_range()
|
||||
|
||||
def show_range(self, i = 0, j = settings.get_max_ring_thumbnail_list()):
|
||||
def show_range(
|
||||
self,
|
||||
i: int = 0,
|
||||
j: int = settings_manager.settings.config.max_ring_thumbnail_list
|
||||
):
|
||||
children = self.get_children()
|
||||
if len(children) <= j:
|
||||
j = len(children) - 1
|
||||
@@ -78,7 +83,7 @@ class ImageList(Gtk.Box):
|
||||
i += 1
|
||||
|
||||
@daemon_threaded
|
||||
def load_child_pixbuf_threaded(self, child):
|
||||
def load_child_pixbuf_threaded(self, child: Gtk.Object):
|
||||
GLib.idle_add(child.load_pixbuf)
|
||||
GLib.idle_add(child.show)
|
||||
Gtk.main_iteration()
|
||||
|
||||
@@ -47,18 +47,18 @@ class ImageView(ImageViewMixin, Gtk.Image):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("size_allocate", self._size_allocate)
|
||||
event_system.subscribe("handle_file_from_dnd", self._handle_file_from_dnd)
|
||||
event_system.subscribe("size-allocate", self._size_allocate)
|
||||
event_system.subscribe("handle-file-from-dnd", self._handle_file_from_dnd)
|
||||
|
||||
event_system.subscribe("get_active_image_path", self._get_active_image_path)
|
||||
event_system.subscribe("zoom_out", self._zoom_out)
|
||||
event_system.subscribe("rotate_left", self._rotate_left)
|
||||
event_system.subscribe("vertical_flip", self._vertical_flip)
|
||||
event_system.subscribe("scale_1_two_1", self._scale_1_two_1)
|
||||
event_system.subscribe("fit_to_container", self._fit_to_container)
|
||||
event_system.subscribe("horizontal_flip", self._horizontal_flip)
|
||||
event_system.subscribe("rotate_right", self._rotate_right)
|
||||
event_system.subscribe("zoom_in", self._zoom_in)
|
||||
event_system.subscribe("get-active-image-path", self._get_active_image_path)
|
||||
event_system.subscribe("zoom-out", self._zoom_out)
|
||||
event_system.subscribe("rotate-left", self._rotate_left)
|
||||
event_system.subscribe("vertical-flip", self._vertical_flip)
|
||||
event_system.subscribe("scale-1-to-1", self._scale_1_two_1)
|
||||
event_system.subscribe("fit-to-container", self._fit_to_container)
|
||||
event_system.subscribe("horizontal-flip", self._horizontal_flip)
|
||||
event_system.subscribe("rotate-right", self._rotate_right)
|
||||
event_system.subscribe("zoom-in", self._zoom_in)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
@@ -91,15 +91,22 @@ class ImageView(ImageViewMixin, Gtk.Image):
|
||||
|
||||
width = self.pixbuff.get_width()
|
||||
height = self.pixbuff.get_height()
|
||||
size = sizeof_fmt( getsize(path) )
|
||||
size = self.sizeof_fmt( getsize(path) )
|
||||
path = f"{path} | {width} x {height} | {size}"
|
||||
event_system.emit("update_path_label", (path,))
|
||||
event_system.emit("update-path-label", (path,))
|
||||
|
||||
if self.fit_to_win:
|
||||
self._fit_to_container()
|
||||
else:
|
||||
self._scale_1_two_1()
|
||||
|
||||
def sizeof_fmt(self, num, suffix = "B"):
|
||||
for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]:
|
||||
if abs(num) < 1024.0:
|
||||
return f"{num:3.1f} {unit}{suffix}"
|
||||
num /= 1024.0
|
||||
return f"{num:.1f} Yi{suffix}"
|
||||
|
||||
def set_as_gif(self, path):
|
||||
image = None
|
||||
try:
|
||||
@@ -127,4 +134,4 @@ class ImageView(ImageViewMixin, Gtk.Image):
|
||||
w, h = im.size
|
||||
|
||||
return GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||
False, 8, w, h, w * 3)
|
||||
False, 8, w, h, w * 3)
|
||||
|
||||
@@ -19,7 +19,7 @@ class OCRWindow(Gtk.Window):
|
||||
def __init__(self):
|
||||
super(OCRWindow, self).__init__()
|
||||
|
||||
self.tesseract_path = f"{settings.get_home_config_path()}/tesseract-ocr.AppImage"
|
||||
self.tesseract_path = f"{settings_manager.path_manager.get_home_config_path()}/tesseract-ocr.AppImage"
|
||||
self.download_url = "https://github.com/AlexanderP/tesseract-appimage/releases/download/v5.3.3/tesseract-5.3.3-x86_64.AppImage"
|
||||
|
||||
self._setup_styling()
|
||||
@@ -30,7 +30,7 @@ class OCRWindow(Gtk.Window):
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_title(f"Tesseract OCR")
|
||||
self.set_icon_from_file( settings.get_window_icon() )
|
||||
self.set_icon_from_file( settings_manager.path_manager.get_window_icon() )
|
||||
self.set_gravity(5) # 5 = CENTER
|
||||
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
||||
|
||||
@@ -42,7 +42,7 @@ class OCRWindow(Gtk.Window):
|
||||
self.connect("delete-event", self._tear_down)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("show_ocr", self._show_ocr)
|
||||
event_system.subscribe("show-ocr", self._show_ocr)
|
||||
|
||||
def _load_widgets(self):
|
||||
scrolled_window = Gtk.ScrolledWindow()
|
||||
|
||||
@@ -33,12 +33,12 @@ class PathLabel(Gtk.Label):
|
||||
self.set_margin_bottom(10)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("update_path_label", self.update_path_label)
|
||||
event_system.subscribe("update-path-label", self.update_path_label)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def update_path_label(self, path = None):
|
||||
def update_path_label(self, path: str):
|
||||
if not path: return
|
||||
|
||||
self.set_label(path)
|
||||
|
||||
36
src/core/widgets/separator_widget.py
Normal file
36
src/core/widgets/separator_widget.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class Separator(Gtk.Separator):
|
||||
def __init__(self, id: str = None, ORIENTATION: int = 0):
|
||||
super(Separator, self).__init__()
|
||||
|
||||
if id:
|
||||
widget_registery.expose_object(id, self)
|
||||
|
||||
self.ORIENTATION = ORIENTATION
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
# HORIZONTAL = 0, VERTICAL = 1
|
||||
self.set_orientation(self.ORIENTATION)
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
Reference in New Issue
Block a user