2020-05-08 00:07:33 +00:00
|
|
|
# Python imports
|
|
|
|
import os
|
|
|
|
|
|
|
|
# Gtk imports
|
|
|
|
import gi, cairo
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
gi.require_version('Gdk', '3.0')
|
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import Gdk
|
2020-05-08 00:07:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Application imports
|
2022-01-23 22:56:27 +00:00
|
|
|
from . import Logger
|
|
|
|
|
2020-05-08 00:07:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Settings:
|
|
|
|
def __init__(self):
|
2022-01-23 22:56:27 +00:00
|
|
|
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
|
2022-01-23 23:33:52 +00:00
|
|
|
self._USER_HOME = os.path.expanduser('~')
|
|
|
|
self._CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
|
|
|
|
self._GLADE_FILE = f"{self._CONFIG_PATH}/Main_Window.glade"
|
|
|
|
self._CSS_FILE = f"{self._CONFIG_PATH}/stylesheet.css"
|
|
|
|
self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons"
|
|
|
|
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
|
|
|
|
self._USR_PATH = f"/usr/share/{app_name.lower()}"
|
2022-01-23 22:56:27 +00:00
|
|
|
|
2022-01-24 06:38:12 +00:00
|
|
|
self._logger = Logger(self._CONFIG_PATH).get_logger()
|
2022-01-23 22:56:27 +00:00
|
|
|
self._builder = Gtk.Builder()
|
|
|
|
self._main_window = None
|
|
|
|
|
|
|
|
# '_filters'
|
|
|
|
self._office_filter = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm', '.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
|
|
|
|
self._vids_filter = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv', '.mpeg', '.mp4', '.webm')
|
|
|
|
self._txt_filter = ('.txt', '.text', '.sh', '.cfg', '.conf')
|
|
|
|
self._music_filter = ('.psf', '.mp3', '.ogg' , '.flac')
|
|
|
|
self._images_filter = ('.png', '.jpg', '.jpeg', '.gif')
|
|
|
|
self._pdf_filter = ('.pdf')
|
|
|
|
|
|
|
|
self._success_color = "#88cc27"
|
|
|
|
self._warning_color = "#ffa800"
|
|
|
|
self._error_color = "#ff0000"
|
|
|
|
|
2022-01-25 02:58:41 +00:00
|
|
|
if not os.path.exists(self._CONFIG_PATH):
|
2022-01-24 06:38:12 +00:00
|
|
|
os.mkdir(self._CONFIG_PATH)
|
2022-01-25 02:58:41 +00:00
|
|
|
self._logger = Logger(self._CONFIG_PATH).get_logger()
|
2022-01-24 06:38:12 +00:00
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
if not os.path.exists(self._GLADE_FILE):
|
|
|
|
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade"
|
|
|
|
if not os.path.exists(self._CSS_FILE):
|
|
|
|
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css"
|
|
|
|
if not os.path.exists(self._WINDOW_ICON):
|
2022-01-23 23:33:52 +00:00
|
|
|
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png"
|
|
|
|
if not os.path.exists(self._DEFAULT_ICONS):
|
2022-01-23 22:56:27 +00:00
|
|
|
self.DEFAULT_ICONS = f"{self._USR_PATH}/icons"
|
|
|
|
|
|
|
|
self._builder.add_from_file(self._GLADE_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_window(self):
|
2020-05-08 00:07:33 +00:00
|
|
|
# Get window and connect signals
|
2022-01-23 22:56:27 +00:00
|
|
|
self._main_window = self._builder.get_object("Main_Window")
|
|
|
|
self.set_window_data()
|
2020-05-08 00:07:33 +00:00
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
def set_window_data(self):
|
|
|
|
self._main_window.set_icon_from_file(self._WINDOW_ICON)
|
|
|
|
screen = self._main_window.get_screen()
|
2020-05-08 00:07:33 +00:00
|
|
|
visual = screen.get_rgba_visual()
|
|
|
|
|
|
|
|
if visual != None and screen.is_composited():
|
2022-01-23 22:56:27 +00:00
|
|
|
self._main_window.set_visual(visual)
|
|
|
|
self._main_window.set_app_paintable(True)
|
|
|
|
self._main_window.connect("draw", self.draw_area)
|
2020-05-08 00:07:33 +00:00
|
|
|
|
|
|
|
# bind css file
|
2022-01-23 22:56:27 +00:00
|
|
|
cssProvider = Gtk.CssProvider()
|
|
|
|
cssProvider.load_from_path(self._CSS_FILE)
|
|
|
|
screen = Gdk.Screen.get_default()
|
|
|
|
styleContext = Gtk.StyleContext()
|
|
|
|
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
|
|
|
|
|
|
|
def get_monitor_data(self):
|
|
|
|
screen = self._builder.get_object("Main_Window").get_screen()
|
2020-05-08 00:07:33 +00:00
|
|
|
monitors = []
|
|
|
|
for m in range(screen.get_n_monitors()):
|
|
|
|
monitors.append(screen.get_monitor_geometry(m))
|
|
|
|
|
|
|
|
for monitor in monitors:
|
2022-01-23 22:56:27 +00:00
|
|
|
print("{}x{}|{}+{}".format(monitor.width, monitor.height, monitor.x, monitor.y))
|
2020-05-08 00:07:33 +00:00
|
|
|
|
|
|
|
return monitors
|
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
def draw_area(self, widget, cr):
|
2020-05-08 00:07:33 +00:00
|
|
|
cr.set_source_rgba(0, 0, 0, 0.54)
|
|
|
|
cr.set_operator(cairo.OPERATOR_SOURCE)
|
|
|
|
cr.paint()
|
|
|
|
cr.set_operator(cairo.OPERATOR_OVER)
|
|
|
|
|
|
|
|
|
2022-01-23 22:56:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_builder(self): return self._builder
|
|
|
|
def get_logger(self): return self._logger
|
|
|
|
def get_main_window(self): return self._main_window
|
2022-01-23 23:33:52 +00:00
|
|
|
def get_home_path(self): return self._USER_HOME
|
2020-05-08 00:07:33 +00:00
|
|
|
|
|
|
|
# Filter returns
|
2022-01-23 23:47:54 +00:00
|
|
|
def get_office_filter(self): return self._office_filter
|
|
|
|
def get_vids_filter(self): return self._vids_filter
|
|
|
|
def get_text_filter(self): return self._txt_filter
|
|
|
|
def get_music_filter(self): return self._music_filter
|
|
|
|
def get_images_filter(self): return self._images_filter
|
|
|
|
def get_pdf_filter(self): return self._pdf_filter
|
2022-01-23 22:56:27 +00:00
|
|
|
|
|
|
|
def get_success_color(self): return self._success_color
|
|
|
|
def get_warning_color(self): return self._warning_color
|
|
|
|
def get_error_color(self): return self._error_color
|