Cleared out old files
This commit is contained in:
3
src/core/__init__.py
Normal file
3
src/core/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Gtk Bound Signal Module
|
||||
"""
|
3
src/core/containers/__init__.py
Normal file
3
src/core/containers/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Containers Module
|
||||
"""
|
44
src/core/containers/base_container.py
Normal file
44
src/core/containers/base_container.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .left_box import LeftBox
|
||||
from .right_box import RightBox
|
||||
from ..widgets.button_controls import ButtonControls
|
||||
from ..widgets.path_label import PathLabel
|
||||
|
||||
|
||||
class BaseContainer(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(BaseContainer, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
box = Gtk.Box()
|
||||
box2 = Gtk.Box()
|
||||
box.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
box2.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
box.add(ButtonControls())
|
||||
box.add(PathLabel())
|
||||
box2.add(LeftBox())
|
||||
box2.add(RightBox())
|
||||
|
||||
self.add(box)
|
||||
self.add(box2)
|
80
src/core/containers/image_list_scroll.py
Normal file
80
src/core/containers/image_list_scroll.py
Normal file
@@ -0,0 +1,80 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from ..widgets.image_list import ImageList
|
||||
|
||||
|
||||
|
||||
class ImageListScroll(Gtk.ScrolledWindow):
|
||||
def __init__(self):
|
||||
super(ImageListScroll, self).__init__()
|
||||
|
||||
self.image_list_widget = None
|
||||
self.size = 0
|
||||
self.start = 0
|
||||
self.end = settings.get_max_ring_thumbnail_list()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
self.set_overlay_scrolling(False)
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("edge-reached", self._handle_edge_reached)
|
||||
self.connect("edge-overshot", self._handle_edge_reached)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("update_list_size_constraints", self._update_list_size_constraints)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.image_list_widget = ImageList()
|
||||
self.add(self.image_list_widget)
|
||||
|
||||
# TODO: Setup to load range start/end values from settings,
|
||||
# NOTE: Must align with ImageList start/end limits too
|
||||
def _update_list_size_constraints(self, size):
|
||||
self.size = size
|
||||
self.start = 0
|
||||
self.end = settings.get_max_ring_thumbnail_list()
|
||||
|
||||
def _handle_edge_reached(self, widget, edge):
|
||||
children = self.image_list_widget.get_children()
|
||||
vadjustment = self.get_vadjustment()
|
||||
vvalue = vadjustment.get_value()
|
||||
|
||||
if edge == Gtk.PositionType.TOP:
|
||||
if self.start >= 1:
|
||||
self.start -= 1
|
||||
self._unload_image(children[self.end])
|
||||
children[self.start].show()
|
||||
self.end -= 1
|
||||
|
||||
vadjustment.set_value(vvalue + 1)
|
||||
if edge == Gtk.PositionType.BOTTOM:
|
||||
if (self.end + 1) < self.size:
|
||||
self.end += 1
|
||||
self._unload_image(children[self.start])
|
||||
|
||||
if not children[self.end].is_loaded:
|
||||
children[self.end].load_pixbuf()
|
||||
|
||||
children[self.end].show()
|
||||
self.start += 1
|
||||
vadjustment.set_value(vvalue - 1)
|
||||
|
||||
def _unload_image(self, child):
|
||||
child.hide()
|
||||
# child.image.clear()
|
||||
child.is_loaded = False
|
109
src/core/containers/image_view_scroll.py
Normal file
109
src/core/containers/image_view_scroll.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
from ..widgets.image_view import ImageView
|
||||
|
||||
|
||||
|
||||
class ImageViewScroll(Gtk.ScrolledWindow):
|
||||
def __init__(self):
|
||||
super(ImageViewScroll, self).__init__()
|
||||
|
||||
self.fimages = settings.get_images_filter()
|
||||
self.curent_dir = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
ctx = self.get_style_context()
|
||||
ctx.add_class("image-view")
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
self._set_up_dnd()
|
||||
self.connect("size-allocate", self._size_request_change)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add(ImageView())
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("do_filter_open", self._do_filter_open)
|
||||
|
||||
def _set_up_dnd(self):
|
||||
flags = Gtk.DestDefaults.ALL
|
||||
URI_TARGET_TYPE = 80
|
||||
|
||||
uri_target = Gtk.TargetEntry.new('text/uri-list', Gtk.TargetFlags(0), URI_TARGET_TYPE)
|
||||
targets = [ uri_target ]
|
||||
action = Gdk.DragAction.COPY
|
||||
|
||||
self.drag_dest_set(flags, targets, action)
|
||||
self.connect("drag-data-received", self._on_drag_data_received)
|
||||
|
||||
def _on_drag_data_received(self, widget, drag_context, _x, _y, data, info, time):
|
||||
if info == 80:
|
||||
uris = data.get_uris()
|
||||
if len(uris) == 0:
|
||||
uris = data.get_text().split("\n")
|
||||
|
||||
self._do_filter_open(uris)
|
||||
|
||||
|
||||
def _do_filter_open(self, uris: [] = []):
|
||||
if len(uris) == 0:
|
||||
return
|
||||
|
||||
has_loaded_image, path, img_list = self.filter_for_images(uris)
|
||||
self._handle_open(has_loaded_image, path, img_list)
|
||||
|
||||
def filter_for_images(self, files):
|
||||
path = files[0].replace("file://", "")
|
||||
img_list = []
|
||||
listedDir = False
|
||||
has_loaded_image = False
|
||||
|
||||
if not os.path.isdir(path):
|
||||
event_system.emit("handle_file_from_dnd", (path,))
|
||||
path = os.path.dirname(path)
|
||||
has_loaded_image = True
|
||||
|
||||
if not self.curent_dir or not self.curent_dir == path:
|
||||
files = os.listdir(path)
|
||||
self.curent_dir = path
|
||||
else:
|
||||
files = []
|
||||
|
||||
for file in files:
|
||||
if file.endswith(self.fimages):
|
||||
img_list.append(file)
|
||||
|
||||
return has_loaded_image, path, img_list
|
||||
|
||||
def _handle_open(self, has_loaded_image, path, img_list):
|
||||
if len(img_list) == 0:
|
||||
return
|
||||
|
||||
if not has_loaded_image:
|
||||
img = img_list[0]
|
||||
target = os.path.join(path, img)
|
||||
event_system.emit("handle_file_from_dnd", target)
|
||||
|
||||
event_system.emit("load_image_list", (path, img_list))
|
||||
|
||||
def _size_request_change(self, widget = None, eve = None):
|
||||
event_system.emit("size_allocate")
|
33
src/core/containers/left_box.py
Normal file
33
src/core/containers/left_box.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .image_list_scroll import ImageListScroll
|
||||
|
||||
|
||||
|
||||
class LeftBox(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(LeftBox, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
self.set_size_request(settings.get_thumbnail_with() + 15, -1)
|
||||
self.set_vexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add(ImageListScroll())
|
35
src/core/containers/right_box.py
Normal file
35
src/core/containers/right_box.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
from .image_view_scroll import ImageViewScroll
|
||||
|
||||
|
||||
|
||||
class RightBox(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(RightBox, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
self.add(ImageViewScroll())
|
60
src/core/controller.py
Normal file
60
src/core/controller.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .mixins.signals_mixins import SignalsMixins
|
||||
from .controller_data import ControllerData
|
||||
from .containers.base_container import BaseContainer
|
||||
|
||||
|
||||
|
||||
class Controller(SignalsMixins, ControllerData):
|
||||
def __init__(self, args, unknownargs):
|
||||
self.setup_controller_data()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins.launch_plugins()
|
||||
|
||||
collection = unknownargs + [args.file] if args.file and os.path.isfile(args.file) else unknownargs
|
||||
event_system.emit("do_filter_open", (collection,))
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.window.connect("focus-out-event", self.unset_keys_and_data)
|
||||
self.window.connect("key-press-event", self.on_global_key_press_controller)
|
||||
self.window.connect("key-release-event", self.on_global_key_release_controller)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
event_system.subscribe("handle_dir_from_ipc", self.handle_dir_from_ipc)
|
||||
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
||||
|
||||
def _tggl_top_main_menubar(self):
|
||||
print("_tggl_top_main_menubar > stub...")
|
||||
|
||||
def setup_builder_and_container(self):
|
||||
self.builder = Gtk.Builder()
|
||||
# self.builder.add_from_file(settings.get_glade_file())
|
||||
self.builder.expose_object("main_window", self.window)
|
||||
|
||||
settings.set_builder(self.builder)
|
||||
self.base_container = BaseContainer()
|
||||
|
||||
settings.register_signals_to_builder([self, self.base_container])
|
||||
|
||||
def get_base_container(self):
|
||||
return self.base_container
|
69
src/core/controller_data.py
Normal file
69
src/core/controller_data.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# Python imports
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from plugins.plugins_controller import PluginsController
|
||||
|
||||
|
||||
|
||||
|
||||
class ControllerData:
|
||||
''' ControllerData contains most of the state of the app at ay given time. It also has some support methods. '''
|
||||
|
||||
def setup_controller_data(self) -> None:
|
||||
self.window = settings.get_main_window()
|
||||
self.builder = None
|
||||
self.base_container = None
|
||||
self.was_midified_key = False
|
||||
self.ctrl_down = False
|
||||
self.shift_down = False
|
||||
self.alt_down = False
|
||||
|
||||
self.setup_builder_and_container()
|
||||
self.plugins = PluginsController()
|
||||
|
||||
|
||||
def clear_console(self) -> None:
|
||||
''' Clears the terminal screen. '''
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
def call_method(self, _method_name: str, data: type) -> type:
|
||||
'''
|
||||
Calls a method from scope of class.
|
||||
|
||||
Parameters:
|
||||
a (obj): self
|
||||
b (str): method name to be called
|
||||
c (*): Data (if any) to be passed to the method.
|
||||
Note: It must be structured according to the given methods requirements.
|
||||
|
||||
Returns:
|
||||
Return data is that which the calling method gives.
|
||||
'''
|
||||
method_name = str(_method_name)
|
||||
method = getattr(self, method_name, lambda data: f"No valid key passed...\nkey={method_name}\nargs={data}")
|
||||
return method(*data) if data else method()
|
||||
|
||||
def has_method(self, obj: type, method: type) -> type:
|
||||
''' Checks if a given method exists. '''
|
||||
return callable(getattr(obj, method, None))
|
||||
|
||||
def clear_children(self, widget: type) -> None:
|
||||
''' Clear children of a gtk widget. '''
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
|
||||
def get_clipboard_data(self, encoding="utf-8") -> str:
|
||||
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
|
||||
retcode = proc.wait()
|
||||
data = proc.stdout.read()
|
||||
return data.decode(encoding).strip()
|
||||
|
||||
def set_clipboard_data(self, data: type, encoding="utf-8") -> None:
|
||||
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
|
||||
proc.stdin.write(data.encode(encoding))
|
||||
proc.stdin.close()
|
||||
retcode = proc.wait()
|
3
src/core/mixins/__init__.py
Normal file
3
src/core/mixins/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Generic Mixins Module
|
||||
"""
|
3
src/core/mixins/signals/__init__.py
Normal file
3
src/core/mixins/signals/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Signals module
|
||||
"""
|
22
src/core/mixins/signals/ipc_signals_mixin.py
Normal file
22
src/core/mixins/signals/ipc_signals_mixin.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class IPCSignalsMixin:
|
||||
""" IPCSignalsMixin handle messages from another starting solarfm process. """
|
||||
|
||||
def print_to_console(self, message=None):
|
||||
print(message)
|
||||
|
||||
def handle_file_from_ipc(self, path: str) -> None:
|
||||
print(f"File From IPC: {path}")
|
||||
event_system.emit("do_filter_open", ([path],))
|
||||
|
||||
def handle_dir_from_ipc(self, path: str) -> None:
|
||||
print(f"Dir From IPC: {path}")
|
||||
event_system.emit("do_filter_open", ([path],))
|
94
src/core/mixins/signals/keyboard_signals_mixin.py
Normal file
94
src/core/mixins/signals/keyboard_signals_mixin.py
Normal file
@@ -0,0 +1,94 @@
|
||||
# Python imports
|
||||
import re
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
valid_keyvalue_pat = re.compile(r"[a-z0-9A-Z-_\[\]\(\)\| ]")
|
||||
|
||||
|
||||
|
||||
class KeyboardSignalsMixin:
|
||||
""" KeyboardSignalsMixin keyboard hooks controller. """
|
||||
|
||||
# TODO: Need to set methods that use this to somehow check the keybindings state instead.
|
||||
def unset_keys_and_data(self, widget=None, eve=None):
|
||||
self.ctrl_down = False
|
||||
self.shift_down = False
|
||||
self.alt_down = False
|
||||
|
||||
def on_global_key_press_controller(self, eve, user_data):
|
||||
keyname = Gdk.keyval_name(user_data.keyval).lower()
|
||||
modifiers = Gdk.ModifierType(user_data.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||
|
||||
self.was_midified_key = True if modifiers != 0 else False
|
||||
|
||||
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
||||
if "control" in keyname:
|
||||
self.ctrl_down = True
|
||||
if "shift" in keyname:
|
||||
self.shift_down = True
|
||||
if "alt" in keyname:
|
||||
self.alt_down = True
|
||||
|
||||
def on_global_key_release_controller(self, widget, event):
|
||||
""" Handler for keyboard events """
|
||||
keyname = Gdk.keyval_name(event.keyval).lower()
|
||||
modifiers = Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||
|
||||
if keyname.replace("_l", "").replace("_r", "") in ["control", "alt", "shift"]:
|
||||
should_return = self.was_midified_key and (self.ctrl_down or self.shift_down or self.alt_down)
|
||||
|
||||
if "control" in keyname:
|
||||
self.ctrl_down = False
|
||||
if "shift" in keyname:
|
||||
self.shift_down = False
|
||||
if "alt" in keyname:
|
||||
self.alt_down = False
|
||||
|
||||
# NOTE: In effect a filter after releasing a modifier and we have a modifier mapped
|
||||
if should_return:
|
||||
self.was_midified_key = False
|
||||
return
|
||||
|
||||
mapping = keybindings.lookup(event)
|
||||
logger.debug(f"on_global_key_release_controller > key > {keyname}")
|
||||
logger.debug(f"on_global_key_release_controller > keyval > {event.keyval}")
|
||||
logger.debug(f"on_global_key_release_controller > mapping > {mapping}")
|
||||
|
||||
if mapping:
|
||||
# See if in controller scope
|
||||
try:
|
||||
getattr(self, mapping)()
|
||||
return True
|
||||
except Exception:
|
||||
# Must be plugins scope, event call, OR we forgot to add method to controller scope
|
||||
if "||" in mapping:
|
||||
sender, eve_type = mapping.split("||")
|
||||
else:
|
||||
sender = ""
|
||||
eve_type = mapping
|
||||
|
||||
self.handle_key_event_system(sender, eve_type)
|
||||
else:
|
||||
logger.debug(f"on_global_key_release_controller > key > {keyname}")
|
||||
|
||||
if self.ctrl_down:
|
||||
if not keyname in ["1", "kp_1", "2", "kp_2", "3", "kp_3", "4", "kp_4"]:
|
||||
self.handle_key_event_system(None, mapping)
|
||||
else:
|
||||
...
|
||||
|
||||
def handle_key_event_system(self, sender, eve_type):
|
||||
event_system.emit(eve_type)
|
||||
|
||||
def keyboard_close_tab(self):
|
||||
...
|
13
src/core/mixins/signals_mixins.py
Normal file
13
src/core/mixins/signals_mixins.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
from .signals.ipc_signals_mixin import IPCSignalsMixin
|
||||
from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
|
||||
class SignalsMixins(KeyboardSignalsMixin, IPCSignalsMixin):
|
||||
...
|
3
src/core/widgets/__init__.py
Normal file
3
src/core/widgets/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Widgets Module
|
||||
"""
|
134
src/core/widgets/button_controls.py
Normal file
134
src/core/widgets/button_controls.py
Normal file
@@ -0,0 +1,134 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ButtonControls(Gtk.ButtonBox):
|
||||
def __init__(self):
|
||||
super(ButtonControls, self).__init__()
|
||||
|
||||
self.one2one_button = None
|
||||
self.fit_button = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
icons_path = settings.get_icons_path()
|
||||
center_widget = Gtk.ButtonBox()
|
||||
zoomout_button = Gtk.Button()
|
||||
lrotate_button = Gtk.Button()
|
||||
vflip_button = Gtk.Button()
|
||||
# NOTE: Toggle Buttons are acting broken for me so workaround ith regular buttons
|
||||
self.one2one_button = Gtk.Button()
|
||||
self.fit_button = Gtk.Button()
|
||||
hflip_button = Gtk.Button()
|
||||
rrotate_button = Gtk.Button()
|
||||
zoomin_button = Gtk.Button()
|
||||
|
||||
# TODO: add if check against settings pull to set 1:1 or fit
|
||||
self._set_class(self.one2one_button)
|
||||
# self._set_class(self.fit_button)
|
||||
|
||||
zoomout_button.set_tooltip_text("Zoom Out")
|
||||
lrotate_button.set_tooltip_text("Rotate Left")
|
||||
vflip_button.set_tooltip_text("Flip Vertical")
|
||||
self.one2one_button.set_tooltip_text("Zoom 1:1")
|
||||
self.fit_button.set_tooltip_text("Zoom Fit")
|
||||
hflip_button.set_tooltip_text("Flip Horizontal")
|
||||
rrotate_button.set_tooltip_text("Rotate Right")
|
||||
zoomin_button.set_tooltip_text("Zoom In")
|
||||
|
||||
zoomout_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-out.png") )
|
||||
lrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-left.png") )
|
||||
vflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-virtical.png") )
|
||||
self.one2one_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-original.png") )
|
||||
self.fit_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-fit.png") )
|
||||
hflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-horizontal.png") )
|
||||
rrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-right.png") )
|
||||
zoomin_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-in.png") )
|
||||
|
||||
zoomout_button.set_always_show_image(True)
|
||||
lrotate_button.set_always_show_image(True)
|
||||
vflip_button.set_always_show_image(True)
|
||||
self.one2one_button.set_always_show_image(True)
|
||||
self.fit_button.set_always_show_image(True)
|
||||
hflip_button.set_always_show_image(True)
|
||||
rrotate_button.set_always_show_image(True)
|
||||
zoomin_button.set_always_show_image(True)
|
||||
|
||||
zoomout_button.connect("clicked", self._zoom_out)
|
||||
lrotate_button.connect("clicked", self._rotate_left)
|
||||
vflip_button.connect("clicked", self._vertical_flip)
|
||||
self.one2one_button.connect("button-release-event", self._scale_1_two_1)
|
||||
self.fit_button.connect("button-release-event", self._fit_to_container)
|
||||
hflip_button.connect("clicked", self._horizontal_flip)
|
||||
rrotate_button.connect("clicked", self._rotate_right)
|
||||
zoomin_button.connect("clicked", self._zoom_in)
|
||||
|
||||
center_widget.add(zoomout_button)
|
||||
center_widget.add(lrotate_button)
|
||||
center_widget.add(vflip_button)
|
||||
center_widget.add(self.one2one_button)
|
||||
center_widget.add(self.fit_button)
|
||||
center_widget.add(hflip_button)
|
||||
center_widget.add(rrotate_button)
|
||||
center_widget.add(zoomin_button)
|
||||
|
||||
self.set_center_widget(center_widget)
|
||||
|
||||
def _zoom_out(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_out")
|
||||
|
||||
def _rotate_left(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_left")
|
||||
|
||||
def _vertical_flip(self, widget = None, eve = None):
|
||||
event_system.emit("vertical_flip")
|
||||
|
||||
def _scale_1_two_1(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
self._unset_class(self.fit_button)
|
||||
self._set_class(self.one2one_button)
|
||||
|
||||
event_system.emit("scale_1_two_1")
|
||||
|
||||
def _fit_to_container(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
self._unset_class(self.one2one_button)
|
||||
self._set_class(self.fit_button)
|
||||
|
||||
event_system.emit("fit_to_container")
|
||||
|
||||
def _horizontal_flip(self, widget = None, eve = None):
|
||||
event_system.emit("horizontal_flip")
|
||||
|
||||
def _rotate_right(self, widget = None, eve = None):
|
||||
event_system.emit("rotate_right")
|
||||
|
||||
def _zoom_in(self, widget = None, eve = None):
|
||||
event_system.emit("zoom_in")
|
||||
|
||||
def _set_class(self, target):
|
||||
ctx = target.get_style_context()
|
||||
ctx.add_class("button-highlighted")
|
||||
|
||||
def _unset_class(self, target):
|
||||
ctx = target.get_style_context()
|
||||
ctx.remove_class("button-highlighted")
|
86
src/core/widgets/image.py
Normal file
86
src/core/widgets/image.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GdkPixbuf', '2.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
try:
|
||||
from PIL import Image as PImage
|
||||
except Exception as e:
|
||||
PImage = None
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class Image(Gtk.EventBox):
|
||||
def __init__(self, path = None):
|
||||
super(Image, self).__init__()
|
||||
|
||||
self._thumbnail_with = settings.get_thumbnail_with()
|
||||
self._thumbnail_height = settings.get_thumbnail_height()
|
||||
self.is_loaded = False
|
||||
self.image = None
|
||||
self.path = path
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("button-release-event", self.set_image_to_view)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
self.image = Gtk.Image()
|
||||
self.image.show()
|
||||
self.add(self.image)
|
||||
|
||||
def set_image_to_view(self, widget = None, eve = None):
|
||||
if eve.button == 1:
|
||||
event_system.emit("handle_file_from_dnd", (self.path, ))
|
||||
|
||||
def load_pixbuf(self):
|
||||
self.set_from_pixbuf( self.get_pixbuf_data(self.path, \
|
||||
self._thumbnail_with, \
|
||||
self._thumbnail_height) )
|
||||
self.is_loaded = True
|
||||
|
||||
def set_from_pixbuf(self, pixbuf):
|
||||
self.image.set_from_pixbuf(pixbuf)
|
||||
|
||||
def get_pixbuf_data(self, path, w = 126, h = 126):
|
||||
path = self.path if not path else path
|
||||
pixbuf = None
|
||||
|
||||
if PImage and path.endswith(".webp"):
|
||||
return self.image2pixbuf(path, w, h)
|
||||
|
||||
try:
|
||||
pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
except Exception:
|
||||
pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
|
||||
|
||||
return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
|
||||
def image2pixbuf(self, path, _w, _h):
|
||||
"""Convert Pillow image to GdkPixbuf"""
|
||||
im = PImage.open(path)
|
||||
data = im.tobytes()
|
||||
data = GLib.Bytes.new(data)
|
||||
w, h = im.size
|
||||
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
|
||||
False, 8, w, h, w * 3)
|
||||
|
||||
return pixbuf.scale_simple(_w, _h, 2) # 2 = BILINEAR and is best by default
|
85
src/core/widgets/image_list.py
Normal file
85
src/core/widgets/image_list.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# Python imports
|
||||
import os
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from ..widgets.image import Image
|
||||
|
||||
|
||||
|
||||
class ImageList(Gtk.Box):
|
||||
def __init__(self):
|
||||
super(ImageList, self).__init__()
|
||||
|
||||
self.path = None
|
||||
self.img_list = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
self.set_spacing(15)
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("load_image_list", self.load_image_list)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def _clear_children(self, widget: type) -> None:
|
||||
''' Clear children of a gtk widget. '''
|
||||
for child in widget.get_children():
|
||||
widget.remove(child)
|
||||
|
||||
def _marshal_paths(self):
|
||||
paths = []
|
||||
for img in self.img_list:
|
||||
path = os.path.join(self.path, img)
|
||||
paths.append(path)
|
||||
|
||||
return paths
|
||||
|
||||
def load_image_list(self, path = None, img_list: [] = []):
|
||||
if not path or len(img_list) == 0:
|
||||
return
|
||||
|
||||
logger.debug(f"Loading images from: {path}\nList: {img_list}")
|
||||
self.path = path
|
||||
self.img_list = img_list
|
||||
paths = self._marshal_paths()
|
||||
|
||||
self._clear_children(self)
|
||||
for file in paths:
|
||||
self.add( Image(file) )
|
||||
|
||||
event_system.emit("update_list_size_constraints", (len(paths),))
|
||||
self.show_range()
|
||||
|
||||
# TODO: Setup to load range start/end values from settings
|
||||
def show_range(self, i = 0, j = settings.get_max_ring_thumbnail_list()):
|
||||
children = self.get_children()
|
||||
if len(children) <= j:
|
||||
j = len(children) - 1
|
||||
|
||||
while i <= j:
|
||||
child = children[i]
|
||||
self.load_child_pixbuf_threaded(child)
|
||||
i += 1
|
||||
|
||||
@daemon_threaded
|
||||
def load_child_pixbuf_threaded(self, child):
|
||||
GLib.idle_add(child.load_pixbuf)
|
||||
GLib.idle_add(child.show)
|
||||
Gtk.main_iteration()
|
170
src/core/widgets/image_view.py
Normal file
170
src/core/widgets/image_view.py
Normal file
@@ -0,0 +1,170 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class ImageView(Gtk.Image):
|
||||
def __init__(self):
|
||||
super(ImageView, self).__init__()
|
||||
|
||||
self.pixbuf = None
|
||||
self.work_pixbuf = None
|
||||
self.animation = None
|
||||
self.fit_to_win = False
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("zoom_out", self._zoom_out)
|
||||
event_system.subscribe("handle_file_from_dnd", self._handle_file_from_dnd)
|
||||
event_system.subscribe("vertical_flip", self._vertical_flip)
|
||||
event_system.subscribe("rotate_left", self._rotate_left)
|
||||
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("size_allocate", self._size_allocate)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def _handle_file_from_dnd(self, path = None):
|
||||
logger.debug(f"Loading image from: {path}")
|
||||
self.load_path(path)
|
||||
|
||||
if self.animation:
|
||||
logger.debug("Start animation stub...")
|
||||
|
||||
def load_path(self, path):
|
||||
self.pixbuf = None
|
||||
self.work_pixbuf = None
|
||||
self.animation = None
|
||||
|
||||
if path.endswith(".gif"):
|
||||
try:
|
||||
self.animation = Gtk.Image.new_from_file(path).get_animation()
|
||||
except Exception:
|
||||
self.animation = Gtk.Image.new_from_resource(path).get_animation()
|
||||
|
||||
return
|
||||
|
||||
try:
|
||||
self.work_pixbuf = Gtk.Image.new_from_file(path).get_pixbuf()
|
||||
except Exception:
|
||||
self.work_pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
|
||||
|
||||
self.pixbuf = self.work_pixbuf
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
if self.fit_to_win:
|
||||
self._fit_to_container()
|
||||
|
||||
event_system.emit("update_path_label", (path,))
|
||||
|
||||
|
||||
def _zoom_out(self):
|
||||
if self.work_pixbuf:
|
||||
# TODO: Setup scale factor setting to pull from settings...
|
||||
stepx = self.work_pixbuf.get_width() * 0.05
|
||||
stepy = self.work_pixbuf.get_height() * 0.05
|
||||
|
||||
w = self.work_pixbuf.get_width() - stepx
|
||||
h = self.work_pixbuf.get_height() - stepy
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _rotate_left(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.COUNTERCLOCKWISE)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _vertical_flip(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.flip(True)
|
||||
self.pixbuf = self.pixbuf.flip(True)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _scale_1_two_1(self):
|
||||
self.fit_to_win = False
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.pixbuf
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _fit_to_container(self):
|
||||
self.fit_to_win = True
|
||||
if self.work_pixbuf:
|
||||
parent_aloc = self.get_parent().get_parent().get_allocation()
|
||||
pw = parent_aloc.width
|
||||
ph = parent_aloc.height
|
||||
iw = self.pixbuf.get_width()
|
||||
ih = self.pixbuf.get_height()
|
||||
w = 0
|
||||
h = 0
|
||||
|
||||
if iw == 0 or ih == 0:
|
||||
return
|
||||
|
||||
w = pw;
|
||||
h = ((ih * w) / iw + 0.5)
|
||||
|
||||
if h > ph:
|
||||
h = ph
|
||||
w = (iw * h) / ih + 0.5
|
||||
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _horizontal_flip(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.flip(False)
|
||||
self.pixbuf = self.pixbuf.flip(False)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _rotate_right(self):
|
||||
if self.work_pixbuf:
|
||||
self.work_pixbuf = self.work_pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
|
||||
self.pixbuf = self.pixbuf.rotate_simple(GdkPixbuf.PixbufRotation.CLOCKWISE)
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _zoom_in(self):
|
||||
if self.work_pixbuf:
|
||||
# TODO: Setup scale factor setting to pull from settings...
|
||||
stepx = self.work_pixbuf.get_width() * 0.05
|
||||
stepy = self.work_pixbuf.get_height() * 0.05
|
||||
|
||||
w = self.work_pixbuf.get_width() + stepx
|
||||
h = self.work_pixbuf.get_height() + stepy
|
||||
|
||||
self.work_pixbuf = self.pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
self.set_from_pixbuf(self.work_pixbuf)
|
||||
|
||||
def _size_allocate(self):
|
||||
if self.fit_to_win:
|
||||
self._fit_to_container()
|
46
src/core/widgets/path_label.py
Normal file
46
src/core/widgets/path_label.py
Normal file
@@ -0,0 +1,46 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
class PathLabel(Gtk.Label):
|
||||
def __init__(self):
|
||||
super(PathLabel, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_line_wrap(False)
|
||||
self.set_ellipsize(1) # NONE = 0¶, START = 1¶, MIDDLE = 2¶, END = 3¶
|
||||
|
||||
|
||||
def _setup_signals(self):
|
||||
self.set_margin_left(25)
|
||||
self.set_margin_right(25)
|
||||
self.set_margin_top(5)
|
||||
self.set_margin_bottom(10)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("update_path_label", self.update_path_label)
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def update_path_label(self, path = None):
|
||||
if not path:
|
||||
return
|
||||
|
||||
self.set_label(path)
|
||||
self.set_tooltip_text(path)
|
96
src/core/window.py
Normal file
96
src/core/window.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# Python imports
|
||||
import time
|
||||
import signal
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
import cairo
|
||||
gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('Gdk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from core.controller import Controller
|
||||
|
||||
|
||||
class ControllerStartExceptiom(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
|
||||
class Window(Gtk.ApplicationWindow):
|
||||
""" docstring for Window. """
|
||||
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Window, self).__init__()
|
||||
|
||||
self._controller = None
|
||||
|
||||
self._set_window_data()
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
|
||||
settings.set_main_window(self)
|
||||
self._load_widgets(args, unknownargs)
|
||||
|
||||
self.show()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_size_request(720, 480)
|
||||
self.set_default_size(settings.get_main_window_width(),
|
||||
settings.get_main_window_height())
|
||||
self.set_title(f"{app_name}")
|
||||
self.set_icon_from_file( settings.get_window_icon() )
|
||||
self.set_gravity(5) # 5 = CENTER
|
||||
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("delete-event", self._tear_down)
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("tear_down", self._tear_down)
|
||||
|
||||
def _load_widgets(self, args, unknownargs):
|
||||
if settings.is_debug():
|
||||
self.set_interactive_debugging(True)
|
||||
|
||||
|
||||
self._controller = Controller(args, unknownargs)
|
||||
if not self._controller:
|
||||
raise ControllerStartException("Controller exited and doesn't exist...")
|
||||
|
||||
self.add( self._controller.get_base_container() )
|
||||
|
||||
def _set_window_data(self) -> None:
|
||||
screen = self.get_screen()
|
||||
visual = screen.get_rgba_visual()
|
||||
|
||||
if visual != None and screen.is_composited():
|
||||
self.set_visual(visual)
|
||||
self.set_app_paintable(True)
|
||||
self.connect("draw", self._area_draw)
|
||||
|
||||
# bind css file
|
||||
cssProvider = Gtk.CssProvider()
|
||||
cssProvider.load_from_path( settings.get_css_file() )
|
||||
screen = Gdk.Screen.get_default()
|
||||
styleContext = Gtk.StyleContext()
|
||||
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||
|
||||
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
|
||||
cr.set_source_rgba( *settings.get_paint_bg_color() )
|
||||
cr.set_operator(cairo.OPERATOR_SOURCE)
|
||||
cr.paint()
|
||||
cr.set_operator(cairo.OPERATOR_OVER)
|
||||
|
||||
|
||||
def _tear_down(self, widget=None, eve=None):
|
||||
settings.clear_pid()
|
||||
time.sleep(event_sleep_time)
|
||||
Gtk.main_quit()
|
Reference in New Issue
Block a user