diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 8acb0da3..b4451a18 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -15,11 +15,27 @@ Important misc changes
- Update action versions in build.yaml to latest.
- Update Qt/GTK "Run" button in interface to run on F5
- Update two links in the **README.rst** file.
+- Adds GNOME Window Extension for interacting with Windows on x11/wayland
Features
---------
Create a GUI-free headless entrypoint to autokey, which can be run without GUI libraries and controlled purely via scripting API
+Allows the distinction between left and right modifier keys for ``[Key.CONTROL, Key.ALT, Key.SUPER, Key.SHIFT, Key.HYPER, Key.META]``.
+
+At this time you cannot "mix and match", IE if you have a ``Key.CONTROL`` and ``Key.ALT`` as the hotkeys it will check for;
+``Key.LEFTCONTROL, Key.LEFTALT``
+and
+``Key.RIGHTCONTROL, Key.RIGHTALT``
+
+But not for;
+``Key.LEFTCONTROL, Key.RIGHTALT``
+``Key.RIGHTCONTROL, Key.RIGHTALT``
+
+This is considered a breaking change, prior it would, in effect, check for all of those scenarios.
+
+Currently the left/right modifiers GUI option is only accessible via the GTK interface, but they should be respected if you manually update your config files.
+
Bug fixes
---------
@@ -88,7 +104,7 @@ Scripting API
- Deprecated: Confusingly named engine.create_abbreviation() and engine.create_hotkey() are deprecated and will be removed in the future. Use engine.create_phrase() with appropriate arguments instead.
- Extended: engine.create_phrase() now supports multiple new optional arguments, allowing to fully configure the created phrase. It can set everything the GUI can do.
-- New: Scripts can use engine.get_triggered_abbreviation() to read which abbreviation triggered it’s execution.
+- New: Scripts can use engine.get_triggered_abbreviation() to read which abbreviation triggered it's execution.
The function returns a tuple containing the abbreviation and the trigger character (the character that 'completed' or 'confirmed' the abbreviation. Both tuple elements are None if the script was not triggered by an abbreviation. The trigger character is None if the script was configured to 'trigger immediately'. The function always returns a tuple, so direct tuple unpacking like abbreviation, trigger = engine.get_triggered_abbreviation() will always work.
- Allow creation of 'temporary' hotkeys and whole folders (which do not persist between sessions).
- Allow overriding existing hotkeys when creating phrases with hotkeys.
@@ -97,7 +113,7 @@ Scripting API
**keyboard API object**
- keyboard.send_keys() got a new optional parameter send_mode, allowing to specify how the given text is sent. It basically offers the same pasting options as are available to AutoKey Phrases.
-- keyboard.send_keys() now raises a TypeError instead of a generic AssertionError, if parameters don’t match the expected types.
+- keyboard.send_keys() now raises a TypeError instead of a generic AssertionError, if parameters don't match the expected types.
**New clipboard API method**
- Change the default phrase send mode to `ctrl+v` (paste using clipboard) rather than sending keys one at a time.
@@ -115,12 +131,12 @@ Scripting API
Command line interface
-++++++++++++++++++++++
+^^^^^^^^^^^^^^^^^^^^^^
- Added a --version command line switch. It prints the current AutoKey version on the standard output and then exits.
Graphical user interfaces
-+++++++++++++++++++++++++
+^^^^^^^^^^^^^^^^^^^^^^^^^
- (GTK) Warn user about missing required and optional programs on startup.
- (GTK) UI will now update when changes are detected to watched files.
@@ -129,7 +145,7 @@ Graphical user interfaces
- Add setting to change GtkSourceView theme, (defaults to classic).
Other
-+++++
+^^^^^
- Add `wait_for_keyevent` scripting function.
- Rewrote script error logging system, with a neat Script Error Dialog to go with it.
@@ -149,20 +165,20 @@ Bug fixes
- Both QT and GTK versions will reload hotkeys after a keymap change event.
- Fix locking issue
- Expose Alt_GR as a hotkey modifier on GTK.
-- (GTK) Fixed GUI lock-up, if multiple script error notifications are posted in quick succession. The notifications are now rate-limited and won’t post more than one notification per second. Fixes issue #383
+- (GTK) Fixed GUI lock-up, if multiple script error notifications are posted in quick succession. The notifications are now rate-limited and won't post more than one notification per second. Fixes issue #383
Scripting API
-+++++++++++++
+^^^^^^^^^^^^^
- Fixed API call `system.exec_command()` crashing, if output capturing is active, but the executed command has empty output. Fixes issue #379
Packaging
-+++++++++
+^^^^^^^^^
- Fixed AutoKey PNG icon size. Now, the icon size is 96x96 pixels, fixing Lintian warnings on Debian. Fixes issue #369
Other changes
----------
+-------------
- Add CI for testing
- Update pip installation requirements
@@ -277,7 +293,7 @@ Bug fixes
- Force AutoKey to exit, if the X server connection closes, most probably at logout or session end. Fixes issue #198
Qt tray icon fixes and improvements
-+++++++++++++++++++++++++++++++++++
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- Added »View script error« entry to the Tray icon context menu, like in the GTK GUI. Part of issue #158
- Tray icon turns red, when scripts raise an error, like in the GTK GUI. Part of issue #158
@@ -384,28 +400,28 @@ Resurrected, re-written and cleaned up the `autokey-qt` Qt GUI. `autokey-qt` is
dependent on currently supported libraries.
Added improvements
-++++++++++++++++++
+^^^^^^^^^^^^^^^^^^
- The main window now keeps its complete state when closed and re-opened (excluding complete application restarts). This includes the currently selected item(s) in the tree view on the left of the main window, selected text and cursor position in the editor on the right if currently editing a script or phrase.
- The entries in the popup menu, that is shown when a hotkey assigned to a folder is pressed, now show icons based on their type (folder, phrase or script). This also works when items are configured to be shown in the system tray icon context menu.
- The *A* autokey application icons are now always displayed correctly, both in the main window and the system tray icon.
-- Various menu actions now have system dependent keyboard shortcuts, that should adjust to the expected default of the user’s current platform/desktop environment.
+- Various menu actions now have system dependent keyboard shortcuts, that should adjust to the expected default of the user's current platform/desktop environment.
- Added icons and descriptive tooltip texts to various buttons.
- The `enable monitoring` checkboxes (both in the `Settings` menu and the tray icon context menu) now properly react to pressing the global hotkey for this action and thus stay in sync. (Even if the hotkey is used while the menu is shown.)
Regressions
-+++++++++++
+^^^^^^^^^^^
- Customizing the main window toolbar entries and keyboard shortcuts to trigger various UI actions is no longer possible. This feature was provided by the KDE4 libraries and is currently dropped.
- The previous, KDE4-based About dialogue is replaced with a very minimalistic one.
- The settings dialogue heavily used the KDE4 functionalities. During the port to Qt5, the dialogue lost some visual style, but all core functionality is kept.
Runtime dependencies
-++++++++++++++++++++
+^^^^^^^^^^^^^^^^^^^^
- Removed dependencies on deprecated and unmaintained PyQt4 and PyKDE4 libraries.
- Removed dependency on `dbus.mainloop.qt`, instead use the DBus support built into Qt5.
- Now depend on PyQt5, the Qt5 SVG module and the Qt5 QScintilla2 module.
Build-time dependencies
-+++++++++++++++++++++++
+^^^^^^^^^^^^^^^^^^^^^^^
Optionally depend on `pyrcc5` command line tool to compile Qt resources into a Python module.
Qt UI files are no longer compiled using `pykdeuic4`, Removed the old compiler wrapper script in commit 6eeeb92f_.
@@ -413,11 +429,11 @@ Qt UI files are no longer compiled using `pykdeuic4`, Removed the old compiler w
.. _6eeeb92f: https://github.com/autokey/autokey/commit/6eeeb92f14c694979c1367d51350c1e6509329b1
Known bugs
-++++++++++
+^^^^^^^^^^
The system tray icon is shown, but non-functional, after enabling it in the settings dialogue. AutoKey Qt has to be restarted for the tray icon to start working. This should have no impact on the normal daily use.
Changed features
-++++++++++++++++
+^^^^^^^^^^^^^^^^
The `hide tray icon` entry in the tray icon context menu now hides the icon for the current session only. The entry does not permanently disable the tray icon any more without any confirmation. Now, the only way to permanently disable the tray icon is through using the appropriate setting in the settings dialogue.
Fixed the broken `Clipboard` and `Mouse selection` phrase paste modes
@@ -431,20 +447,20 @@ Scripting API Changes
---------------------
Additions
-+++++++++
+^^^^^^^^^
- Added a colour picker dialogue to the GTK dialog class, because the used `zenity` now supports it.
- The picked colour is returned as three integers using the ColourData NamedTuple, providing both index based access and attribute access, using the channel names (`r`, `g`, `b`). Additionally, ColourData provides some conversion methods.
Breaking changes
-++++++++++++++++
+^^^^^^^^^^^^^^^^
- See Pull request `#148`_. The `dialog` classes for user input in scripts now return typed NamedTuple tuples instead of plain tuples. This change is safe as long as users do not perform needlessly restrictive type checks in their scripts (e.g. `if type(returned_data) == type(tuple()): ...`). User scripts doing so will break.
- The KDialog based colour picker now also returns a ColourData instance instead of a HTML style hex string, thus making this portable between both GTK and Qt GUIs. AutoKey users previously using the old KDE GUI and using the colour picker dialogue have to port their scripts. A simple fix is using the `html_code` property of the returned ColourData instance.
.. _`#148`: https://github.com/autokey/autokey/pull/148
Fixes
-+++++
+^^^^^
- Re-introduce the newline trimming for system.exec_command() function. During the porting to Python 3, the newline trimming was removed, causing users various issues with unexpected newline characters at end of output. Now properly remove the _last_ newline at end of command output. (See issues `#75`_, `#92`_, `#145`_)
- Applied various code style improvements to the scripting module.
@@ -537,18 +553,18 @@ Internal changes: Changed the data structure of the input stack.
Version 0.93.0 <2014-02-27 Thu>
===============================
-Added functions “acknowledge_gnome_notification” and “move_to_pat”, more details `here`_.
+Added functions "acknowledge_gnome_notification" and "move_to_pat", more details `here`_.
.. _here: https://github.com/autokey/autokey/blob/master/new_features.rst
Version 0.92.0 <2014-02-21 Fri>
===============================
-Added an interactive shell launcher, “autokey-shell”. “autokey-shell” allows you to run some AutoKey functions interactively. Read `this`_ for more details.
+Added an interactive shell launcher, "autokey-shell". "autokey-shell" allows you to run some AutoKey functions interactively. Read `this`_ for more details.
Version 0.91.0 <2014-02-14 Fri>
===============================
-Added a new function “click_on_pat” for use in user scripts. See `this`_ for more details.
+Added a new function "click_on_pat" for use in user scripts. See `this`_ for more details.
.. _this: https://github.com/autokey/autokey/blob/master/new_features.rst
@@ -562,21 +578,21 @@ Python 3 related changes
Python 3 is less tolerant of circular imports so some files were split into several files. Those pieces of the original have their file names prefixed with the original's.
Bug fixes
-+++++++++
+^^^^^^^^^
Eliminate possible deadlock.
Changed
.. code-block:: python
- p = subprocess.Popen([…], stdout=subprocess.PIPE)
+ p = subprocess.Popen([...], stdout=subprocess.PIPE)
retCode = p.wait()
output = p.stdout.read()[:-1] # Drop trailing newline
to
-.. code:: python
+.. code-block:: python
- p = subprocess.Popen([…], stdout=subprocess.PIPE)
+ p = subprocess.Popen([...], stdout=subprocess.PIPE)
output = p.communicate()[0].decode()[:-1] # Drop trailing newline
retCode = p.returncode
@@ -584,7 +600,7 @@ The former may cause a deadlock, for more information, see `Python docs`_. This
.. _Python docs: http://docs.python.org/3/library/subprocess.html#subprocess.Popen.wait
-For a “gi.repository.Notify.Notification” object, test if method “attach_to_status_icon” exists before calling. After this fix, errors in user scripts will trigger a notification.
+For a "gi.repository.Notify.Notification" object, test if method "attach_to_status_icon" exists before calling. After this fix, errors in user scripts will trigger a notification.
Respect XDG standard. Details `here`__.
@@ -595,13 +611,13 @@ Corrected a typo in manpage of autokey-run.
For the GTK GUI, after script error is viewed, tray icon is reverted back to original.
Other changes
-+++++++++++++
-In setup.py, the “/usr/” prefix to the directory names in the data_files argument were removed to allow for non-root install.
+^^^^^^^^^^^^^
+In setup.py, the "/usr/" prefix to the directory names in the data_files argument were removed to allow for non-root install.
-Removed the “WINDOWID” environment variable so that zenity is not tied to the window from which it was launched.
+Removed the "WINDOWID" environment variable so that zenity is not tied to the window from which it was launched.
-Modified the launcher and other files to allow for editable installs (“pip install -e”).
+Modified the launcher and other files to allow for editable installs ("pip install -e").
-Added an “about” dialog for the Python 3 port.
+Added an "about" dialog for the Python 3 port.
Changed hyperlink for bug reports.
diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst
index b0b3dfc9..1fbd4cfc 100644
--- a/CONTRIBUTORS.rst
+++ b/CONTRIBUTORS.rst
@@ -7,6 +7,7 @@ Please add a line to CHANGELOG.rst when creating PRs
Please make sure tests pass before you submit PRs. To ensure this happens automatically, I recommend adding the following lines to the file `.git/hooks/pre-push`:
.. code:: sh
+
remote="$1"
url="$2"
diff --git a/lib/autokey/UI_common_functions.py b/lib/autokey/UI_common_functions.py
index 401a5533..97681df9 100644
--- a/lib/autokey/UI_common_functions.py
+++ b/lib/autokey/UI_common_functions.py
@@ -6,6 +6,7 @@
import subprocess
import sys
import time
+import os
from . import common
import autokey.model.helpers
@@ -24,13 +25,52 @@
qt_modules = ['PyQt5', 'PyQt5.QtGui', 'PyQt5.QtWidgets', 'PyQt5.QtCore',
'PyQt5.Qsci']
-common_programs = ['wmctrl', 'ps', 'xrandr']
+# wmctrl, xrandr are x11 specific programs.
+x11_programs = ['wmctrl', 'xrandr']
+common_programs = ['ps']
# Checking some of these appears to be redundant as some are provided by the same packages on my system but
# better safe than sorry.
-optional_programs = ['visgrep', 'import', 'png2pat', 'xte', 'xmousepos']
+x11_optional_programs = ['xte', 'xmousepos']
+optional_programs = ['visgrep', 'import', 'png2pat']
gtk_programs = ['zenity']
qt_programs = ['kdialog']
+def checkGnomeAutokeyExtension():
+ bus_name = "org.gnome.Shell"
+ object_path = "/org/gnome/Shell/Extensions/AutoKey"
+ interface_name = "org.gnome.Shell.Extensions.AutoKey"
+ check_dbus_object_exists(bus_name, object_path, interface_name)
+ pass
+
+
+def check_dbus_object_exists(bus_name, object_path, interface_name):
+ #keep dbus import here
+ import dbus
+ try:
+ # Connect to the D-Bus session bus
+ bus = dbus.SessionBus()
+
+ # Get a reference to the service and object
+ obj = bus.get_object(bus_name, object_path)
+
+ # Get a reference to the desired interface
+ interface = dbus.Interface(obj, interface_name)
+
+ # Call a method on the object (e.g., 'Get') and check if it returns a valid result
+ interface.List() # Replace 'property_name' with an actual property name
+
+ # If the method call was successful, the object exists
+ return True
+
+ except dbus.exceptions.DBusException as e:
+ # Handle the exception and return False if the object does not exist
+ if e.get_dbus_name() == 'org.freedesktop.DBus.Error.UnknownObject':
+ return False
+ else:
+ # If the exception is not related to the unknown object, re-raise it
+ raise
+
+
def checkModuleImports(modules):
missing_modules = []
for module in modules:
@@ -57,6 +97,9 @@ def checkProgramImports(programs, optional=False):
return missing_programs
def checkOptionalPrograms():
+ if os.environ.get("XDG_SESSION_TYPE") == "x11":
+ checkProgramImports(x11_optional_programs, optional=True)
+
if common.USED_UI_TYPE == "QT":
checkProgramImports(optional_programs, optional=True)
elif common.USED_UI_TYPE == "GTK":
@@ -74,6 +117,10 @@ def getErrorMessage(item_type, missing_items):
def checkRequirements():
errorMessage = ""
+
+ if os.environ.get("XDG_SESSION_TYPE") == "x11":
+ missing_programs = checkProgramImports(x11_programs)
+
if common.USED_UI_TYPE == "QT":
missing_programs = checkProgramImports(common_programs+qt_programs)
missing_modules = checkModuleImports(common_modules+qt_modules)
diff --git a/lib/autokey/autokey_app.py b/lib/autokey/autokey_app.py
index 06dd6bd5..a1ef7b9b 100644
--- a/lib/autokey/autokey_app.py
+++ b/lib/autokey/autokey_app.py
@@ -24,7 +24,9 @@
import dbus.mainloop.glib
import signal
import subprocess
+import hashlib
from typing import NamedTuple, Iterable
+import re
import autokey.model.script
from autokey import common
@@ -112,8 +114,61 @@ def __initialise(self):
self.__add_user_code_dir_to_path()
self.__create_DBus_service()
self.__register_ctrlc_handler()
+
+ # process command line commands here?
+ try:
+ self.usage_statistics()
+ except Exception as e:
+ logger.error(f"Usage statistics failure: {e}")
+
logger.info("Autokey application services ready")
+ def usage_statistics(self):
+ def get_digest(value):
+ return hashlib.md5(str(value).encode()).hexdigest()[0:8]
+
+ logger.info("----- AutoKey Usage Statistics -----")
+ for item in self.configManager.allItems:
+ if type(item) is autokey.model.phrase.Phrase:
+ # logger.info(item.description, item.usageCount, item.phrase)
+ logger.info(f"Phrase: {get_digest(item.description)}, Usage Count: {item.usageCount} {self.getMacroUsage(item.phrase)}")
+ elif type(item) is autokey.model.script.Script:
+ logger.info(f"Script: {get_digest(item.description)}, Usage Count: {item.usageCount} {self.getAPIUsage(item.code)}")
+
+ for item in self.configManager.allFolders:
+
+ logger.info(f"Folder: {get_digest(item.title)}, Usage Count: {item.usageCount}")
+
+ logger.info("----- AutoKey Usage Statistics -----")
+
+ def getAPIUsage(self, code):
+ api_modules = ["engine","keyboard","mouse","highlevel","store","dialog","clipboard","system","window"]
+
+ reg = re.compile("("+"|".join(api_modules)+")\.(\w*)\(")
+
+ results = re.findall(reg, code)
+
+ # Create an empty dictionary to store the counts
+ count_dict = {}
+
+ # Loop through the list and count each item
+ for item in results:
+ if item in count_dict:
+ count_dict[item] += 1
+ else:
+ count_dict[item] = 1
+
+ return count_dict
+
+ def getMacroUsage(self, phrase):
+ macros = ["cursor", "script", "system", "date", "file", "clipboard"]
+
+ reg = re.compile("<("+"|".join(macros)+")")
+
+ results = re.findall(reg, phrase)
+ return results
+
+
def __create_DBus_service(self):
logger.info("Creating DBus service")
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -279,7 +334,7 @@ def autokey_shutdown(self):
Shut down the entire application.
"""
logger.debug("Shutting down service and file monitor...")
+ self.monitor.stop()
self.service.shutdown()
self.dbusService.unregister()
- self.monitor.stop()
logger.debug("Finished shutting down service and file monitor...")
diff --git a/lib/autokey/configmanager/configmanager.py b/lib/autokey/configmanager/configmanager.py
index c51881d5..aa161b8e 100644
--- a/lib/autokey/configmanager/configmanager.py
+++ b/lib/autokey/configmanager/configmanager.py
@@ -37,7 +37,7 @@
RECENT_ENTRIES_FOLDER, IS_FIRST_RUN, SERVICE_RUNNING, MENU_TAKES_FOCUS, SHOW_TRAY_ICON, SORT_BY_USAGE_COUNT, \
PROMPT_TO_SAVE, ENABLE_QT4_WORKAROUND, UNDO_USING_BACKSPACE, WINDOW_DEFAULT_SIZE, HPANE_POSITION, COLUMN_WIDTHS, \
SHOW_TOOLBAR, NOTIFICATION_ICON, WORKAROUND_APP_REGEX, TRIGGER_BY_INITIAL, SCRIPT_GLOBALS, INTERFACE_TYPE, \
- DISABLED_MODIFIERS, GTK_THEME, GTK_TREE_VIEW_EXPANDED_ROWS, PATH_LAST_OPEN
+ DISABLED_MODIFIERS, GTK_THEME, GTK_TREE_VIEW_EXPANDED_ROWS, PATH_LAST_OPEN, KEYBOARD, MOUSE, DEVICES
import autokey.configmanager.version_upgrading as version_upgrade
import autokey.configmanager.predefined_user_files
from autokey.iomediator.constants import X_RECORD_INTERFACE
@@ -89,6 +89,10 @@ def _try_persist_settings(config_manager):
logger.exception(msg)
raise Exception(msg)
+def save_files(config_manager):
+ logger.info("Persisting files")
+ for item in config_manager.allItems:
+ item.persist()
def save_config(config_manager):
logger.info("Persisting configuration")
@@ -215,7 +219,10 @@ class ConfigManager:
SCRIPT_GLOBALS: {},
GTK_THEME: "classic",
GTK_TREE_VIEW_EXPANDED_ROWS: [],
- PATH_LAST_OPEN: "0"
+ PATH_LAST_OPEN: "0",
+ KEYBOARD: None,
+ MOUSE: None,
+ DEVICES: [],
}
def __init__(self, app):
@@ -597,7 +604,7 @@ def config_altered(self, persistGlobal):
Called when some element of configuration has been altered, to update
the lists of phrases/folders.
- @param persistGlobal: save the global configuration at the end of the process
+ :param persistGlobal: save the global configuration at the end of the process
"""
logger.info("Configuration changed - rebuilding in-memory structures")
@@ -698,9 +705,9 @@ def check_abbreviation_unique(self, abbreviation, filterPattern, targetItem):
"""
Checks that the given abbreviation is not already in use.
- @param abbreviation: the abbreviation to check
- @param filterPattern: The filter pattern associated with the abbreviation
- @param targetItem: the phrase for which the abbreviation to be used
+ :param abbreviation: the abbreviation to check
+ :param filterPattern: The filter pattern associated with the abbreviation
+ :param targetItem: the phrase for which the abbreviation to be used
"""
for item in itertools.chain(self.allFolders, self.allItems):
if ConfigManager.item_has_abbreviation(item, abbreviation) and \
@@ -750,10 +757,10 @@ def check_hotkey_unique(self, modifiers, hotKey, newFilterPattern, targetItem):
Checks that the given hotkey is not already in use. Also checks the
special hotkeys configured from the advanced settings dialog.
- @param modifiers: modifiers for the hotkey
- @param hotKey: the hotkey to check
- @param newFilterPattern:
- @param targetItem: the phrase for which the hotKey to be used
+ :param modifiers: modifiers for the hotkey
+ :param hotKey: the hotkey to check
+ :param newFilterPattern:
+ :param targetItem: the phrase for which the hotKey to be used
"""
item = self.get_item_with_hotkey(modifiers, hotKey, newFilterPattern)
if item:
@@ -767,9 +774,9 @@ def get_item_with_hotkey(self, modifiers, hotKey, newFilterPattern=None):
special hotkeys configured from the advanced settings dialog.
Checks folders first, then phrases, then special hotkeys.
- @param modifiers: modifiers for the hotkey
- @param hotKey: the hotkey to check
- @param newFilterPattern:
+ :param modifiers: modifiers for the hotkey
+ :param hotKey: the hotkey to check
+ :param newFilterPattern:
"""
for item in self.globalHotkeys:
if item.enabled and ConfigManager.item_has_same_hotkey(item,
diff --git a/lib/autokey/configmanager/configmanager_constants.py b/lib/autokey/configmanager/configmanager_constants.py
index 315c482a..7838df33 100644
--- a/lib/autokey/configmanager/configmanager_constants.py
+++ b/lib/autokey/configmanager/configmanager_constants.py
@@ -51,3 +51,6 @@
GTK_THEME = "gtkTheme"
GTK_TREE_VIEW_EXPANDED_ROWS = "gtkExpandedRows"
PATH_LAST_OPEN = "pathLastOpen"
+KEYBOARD= "keyboard"
+MOUSE = "mouse"
+DEVICES = "devices"
\ No newline at end of file
diff --git a/lib/autokey/gnome_interface.py b/lib/autokey/gnome_interface.py
new file mode 100644
index 00000000..2499700f
--- /dev/null
+++ b/lib/autokey/gnome_interface.py
@@ -0,0 +1,108 @@
+
+import dbus
+import json
+from dbus.mainloop.glib import DBusGMainLoop
+
+
+from autokey.sys_interface.abstract_interface import AbstractSysInterface, AbstractMouseInterface, AbstractWindowInterface, WindowInfo
+
+logger = __import__("autokey.logger").logger.get_logger(__name__)
+
+class DBusInterface:
+ def __init__(self):
+ mainloop= DBusGMainLoop()
+ session_bus = dbus.SessionBus(mainloop=mainloop)
+ shell_obj = session_bus.get_object('org.gnome.Shell', '/org/gnome/Shell/Extensions/AutoKey')
+ self.dbus_interface = dbus.Interface(shell_obj, 'org.gnome.Shell.Extensions.AutoKey')
+
+ version = self.dbus_interface.CheckVersion()
+ logger.debug("AutoKey Gnome Extension version: %s" % version)
+ if version == "0.1":
+ pass
+ else:
+ raise Exception("Incompatible version of AutoKey Gnome Extension")
+
+
+
+class GnomeMouseReadInterface(DBusInterface):
+ def __init__(self):
+ super().__init__()
+
+ def mouse_location(self):
+ [x, y] = self.dbus_interface.GetMouseLocation()
+ return [int(x), int(y)]
+
+class GnomeExtensionWindowInterface(DBusInterface, AbstractWindowInterface):
+ def __init__(self):
+ super().__init__()
+
+ def get_screen_size(self):
+ x,y = self.dbus_interface.ScreenSize()
+ return [int(x), int(y)]
+
+ def get_window_info(self, window=None, traverse: bool=True) -> WindowInfo:
+ """
+ Returns a WindowInfo object containing the class and title.
+ """
+ window = self._active_window()
+ return WindowInfo(wm_class=window['wm_class'], wm_title=window['wm_title'])
+
+ def get_window_class(self, window=None, traverse=True) -> str:
+ """
+ Returns the window class of the currently focused window.
+ """
+ return self._active_window()['wm_class']
+
+
+ def get_window_title(self, window=None, traverse=True) -> str:
+ """
+ Returns the active window title
+ """
+ return self._active_window()['wm_title']
+
+ def _active_window(self):
+ #TODO probably can be done more efficiently with an additional dbus method in the gnome extension
+ window_list = self._dbus_window_list()
+ for window in window_list:
+ if window['focus']:
+ return window
+ # TODO seeing this a lot when I use a script to call `gnome-screenshot -a`, suspect it's just related to that focus behaves differently when that app runs?
+ logger.error("Unable to determine the active window")
+ return None
+
+ def _dbus_window_list(self):
+ #TODO consider how/if error handling can be implemented
+ try:
+ return json.loads(self.dbus_interface.List())
+ except dbus.exceptions.DBusException as e:
+ self.__init__() #reconnect to dbus
+ return json.loads(self.dbus_interface.List())
+
+ def _dbus_close_window(self, window_id):
+ #TODO consider how/if error handling can be implemented
+ try:
+ self.dbus_interface.Close(window_id)
+ except dbus.exceptions.DBusException as e:
+ self.__init__()
+ self.dbus_interface.Close(window_id)
+
+ def _dbus_activate_window(self, window_id):
+ try:
+ self.dbus_interface.Activate(window_id)
+ except dbus.exceptions.DBusException as e:
+ self.__init__()
+ self.dbus_interface.Activate(window_id)
+
+ def _dbus_move_window(self, window_id, x, y):
+ try:
+ self.dbus_interface.Move(window_id, x, y)
+ except dbus.exceptions.DBusException as e:
+ self.__init__()
+ self.dbus_interface.Move(window_id, x, y)
+
+ def _dbus_resize_window(self, window_id, width, height):
+ try:
+ self.dbus_interface.Resize(window_id, width, height)
+ except dbus.exceptions.DBusException as e:
+ self.__init__()
+ self.dbus_interface.Resize(window_id, width, height)
\ No newline at end of file
diff --git a/lib/autokey/gtkapp.py b/lib/autokey/gtkapp.py
index 7379bcb1..8a4605f7 100644
--- a/lib/autokey/gtkapp.py
+++ b/lib/autokey/gtkapp.py
@@ -23,6 +23,7 @@
import os.path
import time
import threading
+import subprocess
import gettext
@@ -141,7 +142,7 @@ def notify_error(self, error: autokey.model.script.ScriptErrorRecord):
"""
Show an error notification popup.
- @param error: The error that occurred in a Script
+ :param error: The error that occurred in a Script
"""
message = "The script '{}' encountered an error".format(error.script_name)
self.notifier.notify_error(message)
@@ -177,13 +178,13 @@ def show_error_dialog(self, message, details=None, dialog_type=Gtk.MessageType.E
"""
Convenience method for showing an error dialog.
- @param dialog_type: One of Gtk.MessageType.ERROR, Gtk.MessageType.WARNING , Gtk.MessageType.INFO, Gtk.MessageType.OTHER, Gtk.MessageType.QUESTION
+ :param dialog_type: One of Gtk.MessageType.ERROR, Gtk.MessageType.WARNING , Gtk.MessageType.INFO, Gtk.MessageType.OTHER, Gtk.MessageType.QUESTION
defaults to Gtk.MessageType.ERROR
"""
- # TODO check if gtk threads entered.
- # Gdk.threads_enter()
- # display error
- # Gdk.threads_leave()
+ # TODO does this cause issues with other places the error dialog is shown?
+ # without this threads_enter/threads_leave it would fail to show dialog/create
+ # app indicator when error is thrown from uinput interfaced
+ Gdk.threads_enter()
logger.debug("Displaying "+dialog_type.value_name+" Dialog")
dlg = Gtk.MessageDialog(type=dialog_type, buttons=Gtk.ButtonsType.OK,
message_format=message)
@@ -191,6 +192,33 @@ def show_error_dialog(self, message, details=None, dialog_type=Gtk.MessageType.E
dlg.format_secondary_text(details)
dlg.run()
dlg.destroy()
+ Gdk.threads_leave()
+
+ def show_error_dialog_with_link(self, message, details=None, link_data=None, dialog_type=Gtk.MessageType.ERROR):
+ Gdk.threads_enter()
+ # logger.debug("Displaying )
+ label = Gtk.Label()
+ label.set_markup(f'{link_data}')
+ # label.set_tooltip_text("Click to open file")
+ # label.set_cursor(Gdk.Cursor.new(Gdk.CursorType.HAND1))
+ # label.connect("activate-link", open_file_link, link_data)
+
+ dialog = Gtk.MessageDialog(type=dialog_type, buttons=Gtk.ButtonsType.NONE, message_format=message)
+ open_button = dialog.add_button("Open", Gtk.ResponseType.YES)
+
+ dialog.get_message_area().add(label)
+
+ dialog.show_all()
+
+ response = dialog.run()
+
+ if response == Gtk.ResponseType.YES:
+ logger.info(f"Attempting to open {link_data}")
+ subprocess.Popen(['xdg-open', link_data])
+
+ dialog.destroy()
+ Gdk.threads_leave()
+
def show_script_error(self, parent):
"""
diff --git a/lib/autokey/gtkui/data/hotkeysettings.xml b/lib/autokey/gtkui/data/hotkeysettings.xml
index fa460962..b589dfbb 100644
--- a/lib/autokey/gtkui/data/hotkeysettings.xml
+++ b/lib/autokey/gtkui/data/hotkeysettings.xml
@@ -1,35 +1,35 @@
+
-
+