Completed rewrite

This commit is contained in:
itdominator 2022-08-28 18:47:15 -05:00
parent 0c19f61d88
commit c7550c62ec
41 changed files with 567 additions and 1211 deletions

View File

@ -1,79 +0,0 @@
# Python imports
import builtins, threading
# Lib imports
# Application imports
from utils.pyautogui_control import ControlMixin
# NOTE: Threads WILL NOT die with parent's destruction.
def threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
return wrapper
# NOTE: Threads WILL die with parent's destruction.
def daemon_threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
return wrapper
class EndpointRegistry():
def __init__(self):
self._endpoints = {}
def register(self, rule, **options):
def decorator(f):
self._endpoints[rule] = f
return f
return decorator
def get_endpoints(self):
return self._endpoints
class Pyautogui_Controller(ControlMixin):
def __init__(self):
pass
keys_json = {
"keys": {
"row1": {
"pKeys": ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
"sKeys": ['~', '^', '#', '$', '%', '&', '-', '_', '(', ')'],
},
"row2": {
"pKeys": ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
"sKeys": ['\\', '/', '|', ':', '=', '+', '"', '*', '<', '>'],
},
"row3": {
"pKeys": ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', "'"],
"sKeys": ['`', '', '', '', '', '', '', '', '[', ']'],
},
"row4": {
"pKeys": ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '?'],
"sKeys": ['', '', '', '', '', '', ';', '!', '{', '}']
},
}
}
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.app_name = "Mouse Keyboard"
builtins.endpoint_registry = EndpointRegistry()
builtins.typwriter = Pyautogui_Controller()
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
builtins.keys_set = keys_json
builtins.trace_debug = False
builtins.debug = False
builtins.app_settings = None

View File

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

View File

@ -1,42 +0,0 @@
#!/usr/bin/python3
# Python imports
import argparse, faulthandler, traceback
from setproctitle import setproctitle
import tracemalloc
tracemalloc.start()
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from app import Application
if __name__ == "__main__":
""" Set process title, get arguments, and create GTK main thread. """
try:
# import web_pdb
# web_pdb.set_trace()
setproctitle('Mouse Keyboard')
faulthandler.enable() # For better debug info
parser = argparse.ArgumentParser()
# Add long and short arguments
parser.add_argument("--new-tab", "-t", default="", help="Open a file into new tab.")
parser.add_argument("--new-window", "-w", default="", help="Open a file into a new window.")
# Read arguments (If any...)
args, unknownargs = parser.parse_known_args()
Application(args, unknownargs)
Gtk.main()
except Exception as e:
traceback.print_exc()
quit()

View File

@ -1,48 +0,0 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.key import Key
class AT_Key(Key):
def __init__(self):
super(AT_Key, self).__init__("@", "@")
class Space_Key(Key):
def __init__(self):
super(Space_Key, self).__init__("Space", "Space")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
class COM_Key(Key):
def __init__(self):
super(COM_Key, self).__init__(".com", ".com")
def setup_signals(self):
self.connect("released", self._clicked)
class Bottom_Key_Row(Gtk.Box):
def __init__(self):
super(Bottom_Key_Row, self).__init__()
self.set_property("homogeneous", True)
for key in [AT_Key(), Space_Key(), COM_Key()]:
self.add(key)
def tempMethod(self, widget, data=None):
pass

View File

@ -1,63 +0,0 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.key import Key
import traceback
class Symbols_Key(Key):
def __init__(self):
super(Symbols_Key, self).__init__("Symbols", "Symbols")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-symbol-keys", ())
class CAPS_Key(Gtk.ToggleButton):
def __init__(self):
super(CAPS_Key, self).__init__("Caps", "Caps")
self.set_vexpand(True)
self.setup_signals()
self.show_all()
def setup_signals(self):
self.connect("clicked", self._clicked)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-caps", ())
class Left_Column(Gtk.Box):
"""docstring for Left_Column."""
def __init__(self):
super(Left_Column, self).__init__()
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.add(Symbols_Key())
self.add(CAPS_Key())
self.show_all()

View File

@ -1,48 +0,0 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.key import Key
class Backspace_Key(Key):
def __init__(self):
super(Backspace_Key, self).__init__("Backspace", "Backspace")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
class Enter_Key(Key):
def __init__(self):
super(Enter_Key, self).__init__("Enter", "Enter")
self.set_vexpand(True)
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
class Right_Column(Gtk.Box):
"""docstring for Right_Column."""
def __init__(self):
super(Right_Column, self).__init__()
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.add(Backspace_Key())
self.add(Enter_Key())
self.show_all()

View File

@ -1,43 +0,0 @@
# Python imports
import os
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .container import Container
class Window(Gtk.ApplicationWindow):
"""docstring for Window."""
def __init__(self, args, unknownargs):
super(Window, self).__init__()
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self.setup_styling()
self.setup_signals()
self.add(Container())
self.show_all()
def setup_styling(self):
self.set_icon_from_file(f"{self._SCRIPT_PTH}/../resources/icon.png")
self.set_title(app_name)
self.set_default_size(800, 200)
self.set_accept_focus(False)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_type_hint(3) # 3 = TOOLBAR
self.set_gravity(8) # 5 = CENTER, 8 = SOUTH
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
self.stick()
def setup_signals(self):
self.connect("delete-event", Gtk.main_quit)

View File

@ -1,436 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="commands">
<columns>
<!-- column-name Commands -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkApplicationWindow" id="Main_Window">
<property name="can-focus">False</property>
<property name="title" translatable="yes">Mouse Board</property>
<property name="window-position">center</property>
<property name="default-height">260</property>
<property name="icon">icon.png</property>
<property name="type-hint">toolbar</property>
<property name="skip-taskbar-hint">True</property>
<property name="skip-pager-hint">True</property>
<property name="accept-focus">False</property>
<property name="gravity">center</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="width-request">520</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkSearchEntry" id="autoTypeField">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="primary-icon-stock">gtk-go-forward</property>
<property name="primary-icon-activatable">False</property>
<property name="primary-icon-sensitive">False</property>
<property name="placeholder-text" translatable="yes">Autotype Field...</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Type</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="typeString" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="label" translatable="yes">Special Characters</property>
<attributes>
<attribute name="scale" value="1.5"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkButtonBox" id="specials">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<property name="layout-style">start</property>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="main_keys">
<property name="name">popoutkeyboard</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">5</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="layout-style">start</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Del</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkToggleButton">
<property name="label" translatable="yes">Ctrl</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="tgglCtrl" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkToggleButton">
<property name="label" translatable="yes">Shift</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="tgglShift" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkToggleButton">
<property name="label" translatable="yes">Alt</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="toggled" handler="tgglAlt" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">PrtSc</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-add</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="use-stock">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkTreeView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="model">commands</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn">
<property name="title" translatable="yes">Commands</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="column-homogeneous">True</property>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Up</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Down</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Left</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label" translatable="yes">Right</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="insert" swapped="no"/>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

View File

@ -1,8 +0,0 @@
/* * {
background: rgba(0, 0, 0, 0.14);
color: rgba(255, 255, 255, 1);
}
#popoutkeyboard {
background-color: rgba(0, 65, 125, 1);
} */

View File

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

View File

@ -1,56 +0,0 @@
# Python imports
import os, logging
# Application imports
class Logger:
"""
Create a new logging object and return it.
:note:
NOSET # Don't know the actual log level of this... (defaulting or literally none?)
Log Levels (From least to most)
Type Value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
:param loggerName: Sets the name of the logger object. (Used in log lines)
:param createFile: Whether we create a log file or just pump to terminal
:return: the logging object we created
"""
def __init__(self, config_path: str, _ch_log_lvl = logging.CRITICAL, _fh_log_lvl = logging.INFO):
self._CONFIG_PATH = config_path
self.global_lvl = logging.DEBUG # Keep this at highest so that handlers can filter to their desired levels
self.ch_log_lvl = _ch_log_lvl # Prety much the only one we ever change
self.fh_log_lvl = _fh_log_lvl
def get_logger(self, loggerName: str = "NO_LOGGER_NAME_PASSED", createFile: bool = True) -> logging.Logger:
log = logging.getLogger(loggerName)
log.setLevel(self.global_lvl)
# Set our log output styles
fFormatter = logging.Formatter('[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s', '%m-%d %H:%M:%S')
cFormatter = logging.Formatter('%(pathname)s:%(lineno)d] %(levelname)s - %(message)s')
ch = logging.StreamHandler()
ch.setLevel(level=self.ch_log_lvl)
ch.setFormatter(cFormatter)
log.addHandler(ch)
if createFile:
folder = self._CONFIG_PATH
file = f"{folder}/application.log"
if not os.path.exists(folder):
os.mkdir(folder)
fh = logging.FileHandler(file)
fh.setLevel(level=self.fh_log_lvl)
fh.setFormatter(fFormatter)
log.addHandler(fh)
return log

View File

@ -3,7 +3,6 @@ An onscreen keyboard for the mouse.
# TODO # TODO
<li>Get save and execute of custom commands working.</li> <li>Get save and execute of custom commands working.</li>
<li>Get button case toggle working.</li>
# Images # Images
![1 GUI of the keyboard. ](images/pic1.png) ![1 GUI of the keyboard. ](images/pic1.png)

View File

@ -1,7 +1,79 @@
import builtins # Python imports
import builtins, threading
class Builtins: # Lib imports
# Application imports
from utils.pyautogui_control import ControlMixin
# NOTE: Threads WILL NOT die with parent's destruction.
def threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
return wrapper
# NOTE: Threads WILL die with parent's destruction.
def daemon_threaded_wrapper(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
return wrapper
class EndpointRegistry():
def __init__(self):
self._endpoints = {}
def register(self, rule, **options):
def decorator(f):
self._endpoints[rule] = f
return f
return decorator
def get_endpoints(self):
return self._endpoints
class Pyautogui_Controller(ControlMixin):
def __init__(self): def __init__(self):
pass pass
builtins.app_name = "Mouse_Keyboard"
keys_json = {
"keys": {
"row1": {
"pKeys": ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
"sKeys": ['~', '^', '#', '$', '%', '&', '-', '_', '(', ')'],
},
"row2": {
"pKeys": ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
"sKeys": ['\\', '/', '|', ':', '=', '+', '"', '*', '<', '>'],
},
"row3": {
"pKeys": ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', "'"],
"sKeys": ['`', '', '', '', '', '', '', '', '[', ']'],
},
"row4": {
"pKeys": ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '?'],
"sKeys": ['', '', '', '', '', '', ';', '!', '{', '}']
},
}
}
# NOTE: Just reminding myself we can add to builtins two different ways...
# __builtins__.update({"event_system": Builtins()})
builtins.app_name = "Mouse Keyboard"
builtins.endpoint_registry = EndpointRegistry()
builtins.typwriter = Pyautogui_Controller()
builtins.threaded = threaded_wrapper
builtins.daemon_threaded = daemon_threaded_wrapper
builtins.keys_set = keys_json
builtins.trace_debug = False
builtins.debug = False
builtins.app_settings = None

View File

@ -1,34 +1,3 @@
# Python imports """
import inspect Base module
"""
# Gtk imports
# Application imports
from utils.settings import Settings
from signal_classes.signals import Signals
from __builtins__ import Builtins
class Main(Builtins):
def __init__(self, args):
settings = Settings()
builder = settings.returnBuilder()
# Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs.
classes = [Signals(settings)]
handlers = {}
for c in classes:
methods = None
try:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
except Exception as e:
pass
builder.connect_signals(handlers)
window = settings.createWindow()
window.show()

View File

@ -2,31 +2,41 @@
# Python imports # Python imports
import argparse import argparse, faulthandler, traceback
from setproctitle import setproctitle from setproctitle import setproctitle
# Gtk imports import tracemalloc
import gi, faulthandler, signal tracemalloc.start()
# Lib imports
import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import GLib
# Application imports # Application imports
from __init__ import Main from app import Application
if __name__ == "__main__": if __name__ == "__main__":
""" Set process title, get arguments, and create GTK main thread. """
try: try:
# import web_pdb
# web_pdb.set_trace()
setproctitle('Mouse Keyboard') setproctitle('Mouse Keyboard')
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, Gtk.main_quit)
faulthandler.enable() # For better debug info faulthandler.enable() # For better debug info
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# Add long and short arguments # Add long and short arguments
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.") parser.add_argument("--new-tab", "-t", default="", help="Open a file into new tab.")
parser.add_argument("--new-window", "-w", default="", help="Open a file into a new window.")
# Read arguments (If any...) # Read arguments (If any...)
args = parser.parse_args() args, unknownargs = parser.parse_known_args()
main = Main(args)
Application(args, unknownargs)
Gtk.main() Gtk.main()
except Exception as e: except Exception as e:
print( repr(e) ) traceback.print_exc()
quit()

View File

@ -0,0 +1,21 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .widgets.defined_keys import Esc_Key, AT_Key, Space_Key, COM_Key
class Bottom_Key_Row(Gtk.Box):
def __init__(self):
super(Bottom_Key_Row, self).__init__()
self.set_property("homogeneous", True)
for key in [Esc_Key(), Space_Key(), AT_Key(), COM_Key()]:
self.add(key)

View File

@ -1,3 +1,4 @@
from .left_column import Left_Column from .left_column import Left_Column
from .keys_column import Keys_Column from .keys_column import Keys_Column
from .right_column import Right_Column from .right_column import Right_Column
from .controls_column import Controls_Column

View File

@ -0,0 +1,102 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Del_Key, Ctrl_Key, Shift_Key, Alt_Key, PrtSc_Key, Up_Key, Down_Key, Left_Key, Right_Key
class Button_Box(Gtk.ButtonBox):
"""docstring for Button_Box."""
def __init__(self):
super(Button_Box, self).__init__()
for key in [Del_Key(), Ctrl_Key(), Shift_Key(), Alt_Key(), PrtSc_Key()]:
self.add(key)
class List_Box(Gtk.ScrolledWindow):
"""docstring for List_Box."""
def __init__(self):
super(List_Box, self).__init__()
tree, store = self.create_treeview()
self.add(tree)
self.set_size_request(360, 240)
def create_treeview(self):
tree = Gtk.TreeView()
store = Gtk.ListStore(str)
column = Gtk.TreeViewColumn("Commands")
name = Gtk.CellRendererText()
selec = tree.get_selection()
tree.set_model(store)
selec.set_mode(2)
column.pack_start(name, True)
column.add_attribute(name, "text", 0)
column.set_expand(False)
tree.append_column(column)
tree.set_search_column(0)
tree.set_headers_visible(True)
tree.set_enable_tree_lines(False)
tree.columns_autosize()
return tree, store
class Grid_Box(Gtk.Grid):
"""docstring for Grid_Box."""
def __init__(self):
super(Grid_Box, self).__init__()
self.setup_styling()
self.insert_row(0)
self.insert_row(1)
self.insert_row(2)
self.insert_column(0)
self.insert_column(1)
self.insert_column(2)
# NOTE: Widget, left, top, width, height
self.attach(Up_Key(), 1, 0, 1, 1)
self.attach(Down_Key(), 1, 2, 1, 1)
self.attach(Left_Key(), 0, 1, 1, 1)
self.attach(Right_Key(), 2, 1, 1, 1)
def setup_styling(self):
self.set_hexpand(True)
self.set_margin_top(5)
self.set_margin_bottom(5)
self.set_column_homogeneous(True)
class Controls_Column(Gtk.Box):
"""docstring for Controls_Column."""
def __init__(self):
super(Controls_Column, self).__init__()
self. setup_styling()
for key in [Button_Box(), List_Box(), Grid_Box()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.set_vexpand(True)
self.set_margin_start(10)
self.set_margin_end(10)

View File

@ -7,7 +7,7 @@ from gi.repository import Gtk
# Application imports # Application imports
from ..widgets.key import Key from ..widgets.key import Key
from .bottom_key_row import Bottom_Key_Row from ..bottom_key_row import Bottom_Key_Row
class KeyboardRowMatchError(Exception): class KeyboardRowMatchError(Exception):
@ -21,7 +21,6 @@ class Keys_Column(Gtk.Box):
super(Keys_Column, self).__init__() super(Keys_Column, self).__init__()
self.setup_styling() self.setup_styling()
self.setup_signals()
self.setup_key_buttons() self.setup_key_buttons()
self.show_all() self.show_all()
@ -32,9 +31,6 @@ class Keys_Column(Gtk.Box):
self.set_property("homogeneous", True) self.set_property("homogeneous", True)
self.set_hexpand(True) self.set_hexpand(True)
def setup_signals(self):
pass
def setup_key_buttons(self): def setup_key_buttons(self):
keys = keys_set["keys"] keys = keys_set["keys"]
children = keys.keys() children = keys.keys()

View File

@ -0,0 +1,28 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Symbols_Key, CAPS_Key
class Left_Column(Gtk.Box):
"""docstring for Left_Column."""
def __init__(self):
super(Left_Column, self).__init__()
self.setup_styling()
for key in [Symbols_Key(), CAPS_Key()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1

View File

@ -0,0 +1,28 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from ..widgets.defined_keys import Backspace_Key, Enter_Key
class Right_Column(Gtk.Box):
"""docstring for Right_Column."""
def __init__(self):
super(Right_Column, self).__init__()
self.setup_styling()
for key in [Backspace_Key(), Enter_Key()]:
self.add(key)
self.show_all()
def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1

View File

@ -6,11 +6,7 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
# Application imports # Application imports
from .columns import Left_Column, Keys_Column, Right_Column from .columns import Left_Column, Keys_Column, Right_Column, Controls_Column
from .signals_mixin import SignalsMixin
@ -40,9 +36,13 @@ class Auto_Type(Gtk.Box):
self.add(self._type_btn) self.add(self._type_btn)
self.add(pad2) self.add(pad2)
self.setup_styling()
self.setup_signals() self.setup_signals()
self.show_all() self.show_all()
def setup_styling(self):
self.set_margin_bottom(5)
def setup_signals(self): def setup_signals(self):
self._type_btn.connect("released", self.type_out) self._type_btn.connect("released", self.type_out)
@ -51,13 +51,12 @@ class Auto_Type(Gtk.Box):
text = self._auto_typer.get_text() text = self._auto_typer.get_text()
typwriter.type_string(text) typwriter.type_string(text)
class Main_Container(SignalsMixin, Gtk.Box): class Main_Container(Gtk.Box):
"""docstring for Main_Container.""" """docstring for Main_Container."""
def __init__(self): def __init__(self):
super(Main_Container, self).__init__() super(Main_Container, self).__init__()
self.setup_custom_event_signals()
self.setup_styling() self.setup_styling()
self.add_columns() self.add_columns()
@ -72,6 +71,7 @@ class Main_Container(SignalsMixin, Gtk.Box):
self.add(Left_Column()) self.add(Left_Column())
self.add(Keys_Column()) self.add(Keys_Column())
self.add(Right_Column()) self.add(Right_Column())
self.add(Controls_Column())
class Container(Gtk.Box): class Container(Gtk.Box):
"""docstring for Container.""" """docstring for Container."""
@ -88,6 +88,9 @@ class Container(Gtk.Box):
def setup_styling(self): def setup_styling(self):
self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1 self.set_orientation(1) # HORIZONTAL = 0, VERTICAL = 1
self.set_vexpand(True) self.set_vexpand(True)
self.set_margin_start(5)
self.set_margin_top(5)
self.set_margin_bottom(5)
def add_content(self): def add_content(self):
self.add(Auto_Type()) self.add(Auto_Type())

View File

@ -0,0 +1,175 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .key import Key
############################ Left_Column Keys ############################
class Symbols_Key(Key):
def __init__(self):
super(Symbols_Key, self).__init__("Symbols", "Symbols")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-symbol-keys", ())
class CAPS_Key(Gtk.ToggleButton):
def __init__(self):
super(CAPS_Key, self).__init__("Caps", "Caps")
self.set_vexpand(True)
self.setup_signals()
self.show_all()
def setup_signals(self):
self.connect("clicked", self._clicked)
def _clicked(self, widget = None):
key_columns = self.get_parent().get_parent().get_children()[1]
for row in key_columns.get_children():
for key in row:
key.emit("toggle-caps", ())
############################ Right_Column Keys ############################
class Backspace_Key(Key):
def __init__(self):
super(Backspace_Key, self).__init__("Backspace", "Backspace")
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
class Enter_Key(Key):
def __init__(self):
super(Enter_Key, self).__init__("Enter", "Enter")
self.setup_styling()
def setup_styling(self):
self.set_vexpand(True)
def setup_signals(self):
self.connect("released", self._clicked)
def _clicked(self, widget = None):
typwriter.press_special_keys(self.get_label())
############################ Bottom_Key_Row Keys ############################
class AT_Key(Key):
def __init__(self):
super(AT_Key, self).__init__("@", "@")
class Space_Key(Key):
def __init__(self):
super(Space_Key, self).__init__("Space", "Space")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class COM_Key(Key):
def __init__(self):
super(COM_Key, self).__init__(".com", ".com")
############################ Controls_Column Keys ############################
class Esc_Key(Key):
def __init__(self):
super(Esc_Key, self).__init__("Esc", "Esc")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Del_Key(Key):
def __init__(self):
super(Del_Key, self).__init__("Del", "Del")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Ctrl_Key(Key):
def __init__(self):
super(Ctrl_Key, self).__init__("Ctrl", "Ctrl")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Shift_Key(Key):
def __init__(self):
super(Shift_Key, self).__init__("Shift", "Shift")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Alt_Key(Key):
def __init__(self):
super(Alt_Key, self).__init__("Alt", "Alt")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class PrtSc_Key(Key):
def __init__(self):
super(PrtSc_Key, self).__init__("PrtSc", "PrtSc")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Up_Key(Key):
def __init__(self):
super(Up_Key, self).__init__("Up", "Up")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Down_Key(Key):
def __init__(self):
super(Down_Key, self).__init__("Down", "Down")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Left_Key(Key):
def __init__(self):
super(Left_Key, self).__init__("Left", "Left")
def setup_signals(self):
self.connect("released", self._do_press_special_key)
class Right_Key(Key):
def __init__(self):
super(Right_Key, self).__init__("Right", "Right")
def setup_signals(self):
self.connect("released", self._do_press_special_key)

View File

@ -22,14 +22,17 @@ class Key(Gtk.Button):
def setup_signals(self): def setup_signals(self):
self.connect("released", self._clicked) self.connect("released", self._do_type)
self.connect("toggle-caps", self.toggle_caps) self.connect("toggle-caps", self.toggle_caps)
self.connect("toggle-symbol-keys", self.toggle_symbol_keys) self.connect("toggle-symbol-keys", self.toggle_symbol_keys)
def _clicked(self, widget = None): def _do_type(self, widget = None):
key = self.get_label().strip() key = self.get_label().strip()
typwriter.type(key) typwriter.type(key)
def _do_press_special_key(self, widget = None):
typwriter.press_special_keys(self.get_label())
def toggle_symbol_keys(self, widget = None, eve = None): def toggle_symbol_keys(self, widget = None, eve = None):
self._is_symbol = not self._is_symbol self._is_symbol = not self._is_symbol
if self._is_symbol: if self._is_symbol:

73
src/core/window.py Normal file
View File

@ -0,0 +1,73 @@
# Python imports
import os
# Lib imports
import gi, cairo
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 .signals_mixin import SignalsMixin
from .container import Container
class Window(SignalsMixin, Gtk.ApplicationWindow):
"""docstring for Window."""
def __init__(self, args, unknownargs):
super(Window, self).__init__()
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
self._ICON_FILE = f"{self._SCRIPT_PTH}/../resources/icon.png"
self._CSS_FILE = f"{self._SCRIPT_PTH}/../resources/stylesheet.css"
self.setup_win_settings()
self.setup_styling()
self.setup_signals()
self.setup_custom_event_signals()
self.add(Container())
self.show_all()
def setup_signals(self):
self.connect("delete-event", Gtk.main_quit)
def setup_win_settings(self):
self.set_icon_from_file(self._ICON_FILE)
self.set_title(app_name)
self.set_default_size(800, 200)
self.set_keep_above(True)
self.set_accept_focus(False)
self.set_skip_taskbar_hint(True)
self.set_skip_pager_hint(True)
self.set_type_hint(3) # 3 = TOOLBAR
self.set_gravity(8) # 5 = CENTER, 8 = SOUTH
self.set_position(1) # 1 = CENTER, 4 = CENTER_ALWAYS
self.stick()
def setup_styling(self):
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)
css_provider = Gtk.CssProvider()
css_provider.load_from_path(self._CSS_FILE)
screen = Gdk.Screen.get_default()
style_context = Gtk.StyleContext()
style_context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
def _area_draw(self, widget, cr):
cr.set_source_rgba(0, 0, 0, 0.54)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)

View File

@ -1,5 +1,5 @@
/* * { /* * {
background: rgba(0, 0, 0, 0.14); background: rgba(0, 0, 0, 0.64);
color: rgba(255, 255, 255, 1); color: rgba(255, 255, 255, 1);
} }

View File

@ -1,94 +0,0 @@
# Python imports
import pyautogui
# Gtk imports
# Application imports
# Let piautogui make updates as quick as it can...
pyautogui.FAILSAFE = False # If we hit corner, that's ok
pyautogui.MINIMUM_DURATION = 0
pyautogui.PAUSE = 0
class KeyboardMixin:
def typeString(self, widget = None, data = None):
text = self.autoTypeField.get_text()
for char in text:
self.do_insert(char)
def insert(self, widget = None, data = None, key = None):
if not key:
key = widget.get_label().strip()
if self.is_keypress_type(key):
return
if self.isCapsLockOn:
key = key.upper()
self.do_insert(key)
def do_insert(self, key):
if self.isCtrlOn or self.isShiftOn or self.isAltOn:
self.set_hotkeys()
pyautogui.typewrite(key)
if self.isCtrlOn or self.isShiftOn or self.isAltOn:
self.unset_hotkeys()
def is_keypress_type(self, key):
if key in ["Esc", "Tab", "Space", "Del", "Up", "Down", "Left", "Right", "PrtSc"]:
pyautogui.press(key.lower())
return True
for i in range(1, 13):
fkey = 'F' + str(i)
if key == fkey:
pyautogui.press(key.lower())
return True
return False
def set_hotkeys(self):
if self.isCtrlOn:
pyautogui.keyDown('ctrl')
if self.isShiftOn:
pyautogui.keyDown('shiftleft')
pyautogui.keyDown('shiftright')
if self.isAltOn:
pyautogui.keyDown('alt')
def unset_hotkeys(self):
pyautogui.keyUp('ctrl')
pyautogui.keyUp('shiftleft')
pyautogui.keyUp('shiftright')
pyautogui.keyUp('alt')
def toggleCaps(self, widget, data=None):
self.isCapsLockOn = False if self.isCapsLockOn else True
def tgglCtrl(self, widget, data=None):
self.isCtrlOn = False if self.isCtrlOn else True
def tgglShift(self, widget, data=None):
self.isShiftOn = False if self.isShiftOn else True
def tgglAlt(self, widget, data=None):
self.isAltOn = False if self.isAltOn else True
def enter(self, widget, data=None):
pyautogui.press("enter")
def backspace(self, widget, data=None):
pyautogui.press("backspace")

View File

@ -1,107 +0,0 @@
# Python imports
import threading, subprocess, os
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
# Application imports
from .mixins.keyboardmixin import KeyboardMixin
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
return wrapper
class Signals(KeyboardMixin):
def __init__(self, settings):
self.settings = settings
self.builder = self.settings.returnBuilder()
self.autoTypeField = self.builder.get_object("autoTypeField")
self.commandsStore = self.builder.get_object("commands")
self.specialsStore = self.builder.get_object("specials")
self.specialsTree = self.builder.get_object("specialsTree")
main_keys = self.builder.get_object("main_keys")
self.isCapsLockOn = False
self.isCtrlOn = False
self.isShiftOn = False
self.isAltOn = False
special_characters = "<>()[]{}/\!?#$%&@*:^|'\"-_=+~`"
self.generate_keys(special_characters, self.specialsStore)
self.specialsStore.show_all()
main_keys.show_all()
row1_characters = "1234567890"
row1 = Gtk.Box()
self.generate_keys(["Esc",], row1)
self.generate_keys(row1_characters, row1)
self.generate_keys(["Backspace",], row1)
row1.set_homogeneous(True)
row1.show_all()
main_keys.add(row1)
row2_characters = "qwertyuiop"
row2 = Gtk.Box()
self.generate_keys(["Tab",], row2)
self.generate_keys(row2_characters, row2)
row2.set_homogeneous(True)
row2.show_all()
main_keys.add(row2)
row3_characters = "asdfghjkl"
row3 = Gtk.Box()
self.generate_keys(["Caps Lock",], row3)
self.generate_keys(row3_characters, row3)
self.generate_keys(["Enter",], row3)
row3.set_homogeneous(True)
row3.show_all()
main_keys.add(row3)
row4_characters = "zxcvbnm,.:"
row4 = Gtk.Box()
self.generate_keys(row4_characters, row4)
row4.set_homogeneous(True)
row4.show_all()
main_keys.add(row4)
row5_characters = "Space"
row5 = Gtk.Box()
self.generate_keys([row5_characters,], row5)
row5.set_homogeneous(True)
row5.show_all()
main_keys.add(row5)
def generate_keys(self, labels, target):
for label in labels:
button = Gtk.Button.new_with_label(label)
if label not in ["Enter", "Backspace", "Caps Lock"]:
button.connect("clicked", self.insert)
else:
if label == "Enter":
button.connect("clicked", self.enter)
if label == "Backspace":
button.connect("clicked", self.backspace)
if label == "Caps Lock":
button = Gtk.ToggleButton.new_with_label(label)
button.connect("toggled", self.toggleCaps)
target.add(button)
def getClipboardData(self):
proc = subprocess.Popen(['xclip','-selection', 'clipboard', '-o'], stdout=subprocess.PIPE)
retcode = proc.wait()
data = proc.stdout.read()
return data.decode("utf-8").strip()
def setClipboardData(self, data):
proc = subprocess.Popen(['xclip','-selection','clipboard'], stdin=subprocess.PIPE)
proc.stdin.write(data)
proc.stdin.close()
retcode = proc.wait()

View File

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

View File

@ -5,51 +5,51 @@ import os, logging
class Logger: class Logger:
def __init__(self): """
pass Create a new logging object and return it.
:note:
def get_logger(self, loggerName = "NO_LOGGER_NAME_PASSED", createFile = True): NOSET # Don't know the actual log level of this... (defaulting or literally none?)
""" Log Levels (From least to most)
Create a new logging object and return it.
:note:
NOSET # Don't know the actual log level of this... (defaulting or literally none?)
Log Levels (From least to most)
Type Value Type Value
CRITICAL 50 CRITICAL 50
ERROR 40 ERROR 40
WARNING 30 WARNING 30
INFO 20 INFO 20
DEBUG 10 DEBUG 10
:param loggerName: Sets the name of the logger object. (Used in log lines) :param loggerName: Sets the name of the logger object. (Used in log lines)
:param createFile: Whether we create a log file or just pump to terminal :param createFile: Whether we create a log file or just pump to terminal
:return: the logging object we created :return: the logging object we created
""" """
globalLogLvl = logging.DEBUG # Keep this at highest so that handlers can filter to their desired levels def __init__(self, config_path: str, _ch_log_lvl = logging.CRITICAL, _fh_log_lvl = logging.INFO):
chLogLevel = logging.CRITICAL # Prety musch the only one we change ever self._CONFIG_PATH = config_path
fhLogLevel = logging.DEBUG self.global_lvl = logging.DEBUG # Keep this at highest so that handlers can filter to their desired levels
self.ch_log_lvl = _ch_log_lvl # Prety much the only one we ever change
self.fh_log_lvl = _fh_log_lvl
def get_logger(self, loggerName: str = "NO_LOGGER_NAME_PASSED", createFile: bool = True) -> logging.Logger:
log = logging.getLogger(loggerName) log = logging.getLogger(loggerName)
log.setLevel(globalLogLvl) log.setLevel(self.global_lvl)
# Set our log output styles # Set our log output styles
fFormatter = logging.Formatter('[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s', '%m-%d %H:%M:%S') fFormatter = logging.Formatter('[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s', '%m-%d %H:%M:%S')
cFormatter = logging.Formatter('%(pathname)s:%(lineno)d] %(levelname)s - %(message)s') cFormatter = logging.Formatter('%(pathname)s:%(lineno)d] %(levelname)s - %(message)s')
ch = logging.StreamHandler() ch = logging.StreamHandler()
ch.setLevel(level=chLogLevel) ch.setLevel(level=self.ch_log_lvl)
ch.setFormatter(cFormatter) ch.setFormatter(cFormatter)
log.addHandler(ch) log.addHandler(ch)
if createFile: if createFile:
folder = "logs" folder = self._CONFIG_PATH
file = folder + "/application.log" file = f"{folder}/application.log"
if not os.path.exists(folder): if not os.path.exists(folder):
os.mkdir(folder) os.mkdir(folder)
fh = logging.FileHandler(file) fh = logging.FileHandler(file)
fh.setLevel(level=fhLogLevel) fh.setLevel(level=self.fh_log_lvl)
fh.setFormatter(fFormatter) fh.setFormatter(fFormatter)
log.addHandler(fh) log.addHandler(fh)

View File

@ -1,97 +0,0 @@
# Python imports
import os
# Gtk imports
import gi, cairo
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk
from gi.repository import Gdk
# Application imports
class Settings:
def __init__(self):
self.SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
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._USR_PATH = f"/usr/share/{app_name.lower()}"
if not os.path.exists(self._CONFIG_PATH):
os.mkdir(self._CONFIG_PATH)
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"
# 'Filters'
self.office = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm',
'.ppt', 'pptx', '.pps', '.ppsx', '.odt', '.rtf')
self.vids = ('.mkv', '.avi', '.flv', '.mov', '.m4v', '.mpg', '.wmv',
'.mpeg', '.mp4', '.webm')
self.txt = ('.txt', '.text', '.sh', '.cfg', '.conf')
self.music = ('.psf', '.mp3', '.ogg' , '.flac')
self.images = ('.png', '.jpg', '.jpeg', '.gif')
self.pdf = ('.pdf')
self.builder = Gtk.Builder()
self.builder.add_from_file(self._GLADE_FILE)
def createWindow(self):
# Get window and connect signals
window = self.builder.get_object("Main_Window")
window.connect("delete-event", Gtk.main_quit)
self.setWindowData(window, False)
return window
def setWindowData(self, window, paintable):
screen = window.get_screen()
visual = screen.get_rgba_visual()
if visual != None and screen.is_composited():
window.set_visual(visual)
# bind css file
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)
window.set_app_paintable(paintable)
if paintable:
window.connect("draw", self.area_draw)
def getMonitorData(self):
screen = self.builder.get_object("Main_Window").get_screen()
monitors = []
for m in range(screen.get_n_monitors()):
monitors.append(screen.get_monitor_geometry(m))
for monitor in monitors:
print("{}x{}+{}+{}".format(monitor.width, monitor.height, monitor.x, monitor.y))
return monitors
def area_draw(self, widget, cr):
cr.set_source_rgba(0, 0, 0, 0.54)
cr.set_operator(cairo.OPERATOR_SOURCE)
cr.paint()
cr.set_operator(cairo.OPERATOR_OVER)
def returnBuilder(self): return self.builder
# Filter returns
def returnOfficeFilter(self): return self.office
def returnVidsFilter(self): return self.vids
def returnTextFilter(self): return self.txt
def returnMusicFilter(self): return self.music
def returnImagesFilter(self): return self.images
def returnPdfFilter(self): return self.pdf