Initial layout and signals

This commit is contained in:
itdominator 2023-04-16 22:01:16 -05:00
parent 3e014b1c6d
commit 66b3ab8624
18 changed files with 484 additions and 18 deletions

View File

@ -32,6 +32,7 @@ if __name__ == "__main__":
# Add long and short arguments
parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.")
parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.")
parser.add_argument("--no-plugins", "-np", default="false", help="Do not load plugins.")
parser.add_argument("--new-tab", "-nt", default="false", help="Opens a 'New Tab' if a handler is set for it.")
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")

View File

@ -0,0 +1,3 @@
"""
Containers Module
"""

View File

@ -6,7 +6,8 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .left_box import LeftBox
from .right_box import RightBox
@ -24,21 +25,11 @@ class CoreWidget(Gtk.Box):
def _setup_styling(self):
self.set_orientation(1)
self.set_orientation(Gtk.Orientation.HORIZONTAL)
def _setup_signals(self):
...
def _load_widgets(self):
glade_box = self._builder.get_object("glade_box")
button = Gtk.Button(label="Click Me!")
button.connect("clicked", self._hello_world)
self.add(button)
self.add(glade_box)
def _hello_world(self, widget=None, eve=None):
print("Hello, World!")
self.add(LeftBox())
self.add(RightBox())

View File

@ -0,0 +1,35 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.radio_buttons import RadioButtons
from ..widgets.delay_amount import DelayAmount
from ..widgets.preview_image import PreviewPane
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)
def _setup_signals(self):
...
def _load_widgets(self):
self.add(RadioButtons())
self.add(DelayAmount())
self.add(PreviewPane())

View File

@ -0,0 +1,35 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.snapshot_button import SnapshotButton
from ..widgets.monitor_list import MonitorList
from ..widgets.images_list import ImagesList
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_orientation(Gtk.Orientation.VERTICAL)
def _setup_signals(self):
...
def _load_widgets(self):
self.add(SnapshotButton())
self.add(MonitorList())
self.add(ImagesList())

View File

@ -1,4 +1,5 @@
# Python imports
import os
# Lib imports
import gi
@ -11,7 +12,7 @@ from gi.repository import GLib
# Application imports
from .mixins.signals_mixins import SignalsMixins
from .controller_data import ControllerData
from .core_widget import CoreWidget
from .containers.core_widget import CoreWidget

View File

@ -0,0 +1,3 @@
"""
Widgets Module
"""

View File

@ -0,0 +1,43 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class DelayAmount(Gtk.Box):
def __init__(self):
super(DelayAmount, self).__init__()
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.HORIZONTAL)
self.set_margin_top(5)
self.set_margin_bottom(5)
def _setup_signals(self):
...
def _load_widgets(self):
label = Gtk.Label("Timeout: ")
spinner = Gtk.SpinButton()
spinner.set_hexpand(True)
spinner.set_numeric(True)
spinner.set_snap_to_ticks(True)
spinner.set_digits(0)
spinner.set_range(1, 120)
spinner.set_increments(1, 5)
self.add(label)
self.add(spinner)

View File

@ -0,0 +1,54 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from mixins.tree_nixin import TreeMixin
class ImagesList(TreeMixin, Gtk.ScrolledWindow):
def __init__(self):
super(ImagesList, self).__init__()
self._store = None
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_size_request(200, -1)
self.set_hexpand(False)
self.set_vexpand(True)
self.set_margin_top(15)
def _setup_signals(self):
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
grid, self._store = self._create_treeview_widget("Images")
self.referesh_directory_list()
self.add(grid)
@threaded
def referesh_directory_list(self):
images = settings.get_directory_list()
images.sort()
if len(images) != len(self._store):
self._store.clear()
for image in images:
GLib.idle_add(self.add_to_store, (image,))
def add_to_store(self, image):
self._store.append(image)

View File

@ -0,0 +1,50 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from mixins.tree_nixin import TreeMixin
class MonitorList(TreeMixin, Gtk.Box):
def __init__(self):
super(MonitorList, self).__init__()
self._store = None
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_hexpand(False)
def _setup_signals(self):
...
def _subscribe_to_events(self):
...
def _load_widgets(self):
grid, self._store = self._create_treeview_widget("Monitors")
self._load_monitor_store()
grid.set_hexpand(True)
self.add(grid)
def _load_monitor_store(self):
MONITORS = settings.get_monitor_data()
i = 0
for monitor in MONITORS:
if i > 0:
mon = str(monitor.width) + "x" + str(monitor.height) + "+" + str(monitor.x) + "+" + str(monitor.y)
self._store.append([mon])
i += 1

View File

@ -0,0 +1,33 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class PreviewPane(Gtk.AspectFrame):
def __init__(self):
super(PreviewPane, self).__init__()
self._preview_image = None
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_size_request(312, 312)
def _setup_signals(self):
...
def _load_widgets(self):
self._preview_image = Gtk.Image()
self.add(self._preview_image)

View File

@ -0,0 +1,57 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class RadioButtons(Gtk.Box):
def __init__(self):
super(RadioButtons, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_orientation(Gtk.Orientation.HORIZONTAL)
def _setup_signals(self):
...
def _subscribe_to_events(self):
event_system.subscribe("get_screenshot_type", self._get_active_type)
def _load_widgets(self):
radio_1 = Gtk.RadioButton(label = "Entire Screen")
radio_2 = Gtk.RadioButton(label = "Active Window")
radio_3 = Gtk.RadioButton(label = "Select Region")
radio_4 = Gtk.RadioButton(label = "Select Monitor")
self.add(radio_1)
self.add(radio_2)
self.add(radio_3)
self.add(radio_4)
self._setup_data()
def _setup_data(self):
last_child = None
for child in self.get_children():
if last_child:
child.join_group(last_child)
else:
last_child = child
def _get_active_type(self):
group = self.get_children()[0].get_group()
active_radio = [r for r in group if r.get_active()]
return active_radio[0]

View File

@ -0,0 +1,45 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class SnapshotButton(Gtk.Button):
def __init__(self):
super(SnapshotButton, self).__init__()
self._setup_styling()
self._setup_signals()
self._subscribe_to_events()
self._load_widgets()
self.show_all()
def _setup_styling(self):
self.set_always_show_image(True)
self.set_image_position(Gtk.PositionType.LEFT)
self.set_label("Take Snapshot")
def _setup_signals(self):
self.connect("clicked", self._take_snapshot)
def _subscribe_to_events(self):
...
def _load_widgets(self):
image = Gtk.Image.new_from_icon_name("gtk-media-play", 3)
self.set_image(image)
def _take_snapshot(self, widget = None, eve = None):
type = event_system.emit_and_await("get_screenshot_type").get_label()
print(type)
# NOTE:
# 1. Get type of screenshot
# 2. Grab screenshot
# 3. Emit images list file update

View File

@ -43,6 +43,10 @@ class Window(Gtk.ApplicationWindow):
def _setup_styling(self):
self.set_default_size(settings.get_main_window_width(),
settings.get_main_window_height())
self.set_size_request(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

View File

@ -0,0 +1,3 @@
"""
Mixins module
"""

View File

@ -0,0 +1,37 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class TreeMixin:
def _create_treeview_widget(self, title = "Not Set"):
scroll = Gtk.ScrolledWindow()
grid = Gtk.TreeView()
store = Gtk.ListStore(str)
column = Gtk.TreeViewColumn(title)
name = Gtk.CellRendererText()
selec = grid.get_selection()
grid.set_model(store)
selec.set_mode(2)
scroll.set_size_request(145, 96)
column.pack_start(name, True)
column.add_attribute(name, "text", 0)
column.set_expand(False)
grid.append_column(column)
grid.set_search_column(0)
grid.set_headers_visible(True)
grid.set_enable_tree_lines(False)
grid.show_all()
scroll.add(grid)
grid.columns_autosize()
return scroll, store

View File

@ -4,6 +4,9 @@ import json
import inspect
# Lib imports
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk
# Application imports
from ..singleton import Singleton
@ -23,6 +26,7 @@ class Settings(StartCheckMixin, Singleton):
self._USR_CONFIG_FILE = f"{self._USR_PATH}/settings.json"
self._HOME_CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
self._SCREENSHOTS_DIR = f"{self._USER_HOME}/.screenshots"
self._PLUGINS_PATH = f"{self._HOME_CONFIG_PATH}/plugins"
self._DEFAULT_ICONS = f"{self._HOME_CONFIG_PATH}/icons"
self._CONFIG_FILE = f"{self._HOME_CONFIG_PATH}/settings.json"
@ -30,14 +34,17 @@ class Settings(StartCheckMixin, Singleton):
self._CSS_FILE = f"{self._HOME_CONFIG_PATH}/stylesheet.css"
self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
self._UI_WIDEGTS_PATH = f"{self._HOME_CONFIG_PATH}/ui_widgets"
self._CONTEXT_MENU = f"{self._HOME_CONFIG_PATH}/contexct_menu.json"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
if not os.path.exists(self._HOME_CONFIG_PATH):
os.mkdir(self._HOME_CONFIG_PATH)
if not os.path.exists(self._PLUGINS_PATH):
os.mkdir(self._PLUGINS_PATH)
if not os.path.isdir(self._SCREENSHOTS_DIR):
os.mkdir(self._SCREENSHOTS_DIR)
if not os.path.exists(self._CONFIG_FILE):
import shutil
@ -87,8 +94,8 @@ class Settings(StartCheckMixin, Singleton):
self._main_window = None
self._main_window_w = 800
self._main_window_h = 600
self._main_window_w = 500
self._main_window_h = 310
self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
@ -134,6 +141,7 @@ class Settings(StartCheckMixin, Singleton):
def get_ui_widgets_path(self) -> str: return self._UI_WIDEGTS_PATH
def get_context_menu_data(self) -> str: return self._context_menu_data
def get_screenshots_dir(self) -> str: return self._SCREENSHOTS_DIR
def get_plugins_path(self) -> str: return self._PLUGINS_PATH
def get_icon_theme(self) -> str: return self._ICON_THEME
def get_css_file(self) -> str: return self._CSS_FILE
@ -175,3 +183,28 @@ class Settings(StartCheckMixin, Singleton):
def save_settings(self):
with open(self._CONFIG_FILE, 'w') as outfile:
json.dump(self._settings, outfile, separators=(',', ':'), indent=4)
def get_monitor_data(self):
screen = self.get_main_window().get_screen()
wdth = screen.get_width()
hght = screen.get_height()
mon0 = Gdk.Rectangle()
mon0.width = wdth
mon0.height = hght
monitors = []
monitors.append(mon0)
for m in range(screen.get_n_monitors()):
monitors.append(screen.get_monitor_geometry(m))
return monitors
def get_directory_list(self):
files = []
for file in os.listdir(self._SCREENSHOTS_DIR):
if os.path.isfile(os.path.join(self._SCREENSHOTS_DIR, file)):
files.append(file)
return files

View File

@ -0,0 +1,38 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
class TreeMixin:
def _create_treeview_widget(self, title = "Not Set"):
# scroll = Gtk.ScrolledWindow()
grid = Gtk.TreeView()
store = Gtk.ListStore(str)
column = Gtk.TreeViewColumn(title)
name = Gtk.CellRendererText()
selec = grid.get_selection()
grid.set_model(store)
selec.set_mode(2)
# scroll.set_size_request(145, 96)
column.pack_start(name, True)
column.add_attribute(name, "text", 0)
column.set_expand(False)
grid.append_column(column)
grid.set_search_column(0)
grid.set_headers_visible(True)
grid.set_enable_tree_lines(False)
grid.show_all()
# scroll.add(grid)
grid.columns_autosize()
# return scroll, store
return grid, store