Skip to content

Commit

Permalink
Fix paths and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrnr committed Feb 3, 2025
1 parent 0121d46 commit a4836ea
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 22 deletions.
2 changes: 1 addition & 1 deletion plover/gui_qt/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from PyQt6.QtGui import QFontDatabase, QFontMetrics
from PyQt6.QtWidgets import QWidget

from plover.plugins_manager.gui_qt.console_widget_ui import Ui_ConsoleWidget
from plover.gui_qt.console_widget_ui import Ui_ConsoleWidget


NULL = open(os.devnull, 'r+b')
Expand Down
82 changes: 76 additions & 6 deletions plover/gui_qt/manager.py → plover/gui_qt/plugins_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,94 @@
import html
import os
import sys
import itertools
import subprocess
import site

from PyQt6.QtCore import Qt, pyqtSignal
from PyQt6.QtWidgets import QDialog, QMessageBox, QTableWidgetItem, QInputDialog

from plover.gui_qt.tool import Tool

from plover.plugins_manager.gui_qt.info_browser import InfoBrowser
from plover.plugins_manager.gui_qt.manager_ui import Ui_PluginsManager
from plover.plugins_manager.gui_qt.run_dialog import RunDialog
from plover.gui_qt.info_browser import InfoBrowser
from plover.gui_qt.plugins_manager_ui import Ui_PluginsManager
from plover.gui_qt.run_dialog import RunDialog
from plover.plugins_manager.registry import Registry
from plover.plugins_manager.utils import description_to_html
from plover.plugins_manager.__main__ import pip
from plover.plugins_manager import local_registry, global_registry
from plover.plugins_manager.utils import running_under_virtualenv


def list_plugins(freeze=False):
installed_plugins = local_registry.list_plugins()
if freeze:
available_plugins = {}
else:
available_plugins = global_registry.list_plugins()
for name, installed, available in sorted(
(name,
installed_plugins.get(name, []),
available_plugins.get(name, []))
for name in set(itertools.chain(installed_plugins,
available_plugins))
):
latest = available[-1] if available else None
current = installed[-1] if installed else None
info = latest or current
if freeze:
if current:
print('%s==%s' % (current.name, current.version))
continue
print('%s (%s) - %s' % (info.name, info.version, info.summary))
if current:
print(' INSTALLED: %s' % current.version)
if latest:
print(' LATEST: %s' % latest.version)


def pip(args, stdin=None, stdout=None, stderr=None, **kwargs):
cmd = [sys.executable, '-m',
'plover.plugins_manager.pip_wrapper',
'--disable-pip-version-check']
env = dict(os.environ)
# Make sure user plugins are handled
# even if user site is not enabled.
if not running_under_virtualenv() and not site.ENABLE_USER_SITE:
pypath = env.get('PYTHONPATH')
if pypath is None:
pypath = []
else:
pypath = pypath.split(os.pathsep)
pypath.insert(0, site.USER_SITE)
env['PYTHONPATH'] = os.pathsep.join(pypath)
command = args.pop(0)
if command == 'check':
cmd.append('check')
elif command == 'install':
cmd.extend((
'install',
'--upgrade-strategy=only-if-needed',
))
if not running_under_virtualenv():
cmd.append('--user')
elif command == 'uninstall':
cmd.append('uninstall')
elif command == 'list':
cmd.extend((
'list',
'--format=columns',
))
else:
raise ValueError('invalid command: %s' % command)
cmd.extend(args)
return subprocess.Popen(cmd, env=env, stdin=stdin,
stdout=stdout, stderr=stderr,
**kwargs)

class PluginsManager(Tool, Ui_PluginsManager):

TITLE = 'Plugins Manager'
ROLE = 'plugins_manager'
ICON = ('plover.plugins_manager.gui_qt.resources', ':/icon.svg')
ICON = (':/plugins_manager.svg')

# We use a class instance so the state is persistent
# accross different executions of the dialog when
Expand All @@ -42,6 +111,7 @@ def __init__(self, engine):
self._packages_updated.connect(self._on_packages_updated)
if self._packages is None:
PluginsManager._packages = Registry()
print(PluginsManager._packages)
self._on_packages_updated()
self.on_refresh()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</property>
<property name="icon">
<iconset resource="resources/resources.qrc">
<normaloff>:/plugins_manager/git.png</normaloff>:/plugins_manager/git.png</iconset>
<normaloff>:/git.png</normaloff>:/git.png</iconset>
</property>
</widget>
</item>
Expand Down
4 changes: 2 additions & 2 deletions plover/gui_qt/run_dialog.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

from PyQt6.QtWidgets import QDialogButtonBox, QDialog

from plover.plugins_manager.gui_qt.console_widget import ConsoleWidget
from plover.plugins_manager.gui_qt.run_dialog_ui import Ui_RunDialog
from plover.gui_qt.console_widget import ConsoleWidget
from plover.gui_qt.run_dialog_ui import Ui_RunDialog


class RunDialog(QDialog, Ui_RunDialog):
Expand Down
20 changes: 11 additions & 9 deletions plover/oslayer/osx/log.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
UNUserNotificationCenter = objc.lookUpClass('UNUserNotificationCenter')
UNMutableNotificationContent = objc.lookUpClass('UNMutableNotificationContent')
UNNotificationRequest = objc.lookUpClass('UNNotificationRequest')

NSObject = objc.lookUpClass('NSObject')

from plover import log, __name__ as __software_name__
Expand All @@ -16,15 +18,15 @@ def __init__(self):
self.setFormatter(log.NoExceptionTracebackFormatter('%(message)s'))

def emit(self, record):
# Notification Center has no levels or timeouts.
notification = NSUserNotification.alloc().init()
content = UNMutableNotificationContent.alloc().init()
content.setTitle_(record.levelname.title())
content.setBody_(self.format(record))

notification.setTitle_(record.levelname.title())
notification.setInformativeText_(self.format(record))
request = UNNotificationRequest.requestWithIdentifier_content_trigger_("notification", content, None)

ns = NSUserNotificationCenter.defaultUserNotificationCenter()
ns.setDelegate_(always_present_delegator)
ns.deliverNotification_(notification)
center = UNUserNotificationCenter.currentNotificationCenter()
center.requestAuthorizationWithOptions_completionHandler_(3, lambda granted, error: None)
center.addNotificationRequest_withCompletionHandler_(request, None)


class AlwaysPresentNSDelegator(NSObject):
Expand Down
6 changes: 3 additions & 3 deletions reqs/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ pluggy==1.0.0
py==1.10.0
pycparser==2.20
Pygments==2.10.0
pyobjc-core==9.0
pyobjc-framework-Cocoa==9.0
pyobjc-framework-Quartz==9.0
pyobjc-core==11.0
pyobjc-framework-Cocoa==11.0
pyobjc-framework-Quartz==11.0
pyparsing==3.0.3
PyQt6==6.4.2
PyQt6-Qt6==6.4.3
Expand Down
2 changes: 2 additions & 0 deletions reqs/dist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pyobjc-framework-Quartz>=9.0; "darwin" in sys_platform
pyserial>=2.7
python-xlib>=0.16; ("linux" in sys_platform or "bsd" in sys_platform) and python_version < "3.9"
python-xlib>=0.29; ("linux" in sys_platform or "bsd" in sys_platform) and python_version >= "3.9"
requests-cache>=0.9.1
requests-futures>=1.0.0
rtf_tokenize
setuptools
wcwidth
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ plover.gui.qt.tool =
add_translation = plover.gui_qt.add_translation_dialog:AddTranslationDialog
lookup = plover.gui_qt.lookup_dialog:LookupDialog
paper_tape = plover.gui_qt.paper_tape:PaperTape
plugins_manager = plover.gui_qt.plugins_manager:PluginsManager
suggestions = plover.gui_qt.suggestions_dialog:SuggestionsDialog
plover.machine =
Gemini PR = plover.machine.geminipr:GeminiPr
Expand Down

0 comments on commit a4836ea

Please sign in to comment.