Skip to content

Commit

Permalink
Initial implementation of typing output
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Jun 10, 2018
1 parent 8e571e0 commit 864c78e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -14,7 +14,8 @@ before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then wget https://bootstrap.pypa.io/get-pip.py -O- | sudo python3.6; sudo pip install tox-travis; fi

script:
- tox -v
- if [ "$TRAVIS_OS_NAME" == "linux" ]; xvfb-run tox -v; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; tox -v; fi
# build dmg for macOS
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then bash -xe travis/build-dmg.sh; fi
# build AppImage for Linux
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Ability to switch output location on runtime
- Ability to type output directly

## [0.15] - 2018-06-07
### Packaging changes
Expand Down
41 changes: 35 additions & 6 deletions pext/__main__.py
Expand Up @@ -54,6 +54,7 @@

from dulwich import porcelain
from dulwich.repo import Repo
from pynput import keyboard
from PyQt5.QtCore import QStringListModel, QLocale, QTranslator, Qt
from PyQt5.QtWidgets import (QApplication, QDialog, QDialogButtonBox,
QInputDialog, QLabel, QLineEdit, QMainWindow,
Expand Down Expand Up @@ -113,6 +114,7 @@ class OutputMode(IntEnum):
DefaultClipboard = 0
SelectionClipboard = 1
FindBuffer = 2
AutoType = 3


class ConfigRetriever():
Expand Down Expand Up @@ -491,14 +493,17 @@ def _process_tab_action(self, tab: Dict, active_tab: int) -> None:

elif action[0] == Action.copy_to_clipboard:
# Copy the given data to the user-chosen clipboard
if Settings.get('output_mode') == OutputMode.SelectionClipboard:
mode = QClipboard.Selection
elif Settings.get('output_mode') == OutputMode.FindBuffer:
mode = QClipboard.FindBuffer
if Settings.get('output_mode') == OutputMode.AutoType:
self.window.output_queue.append(str(action[1]))
else:
mode = QClipboard.Clipboard
if Settings.get('output_mode') == OutputMode.SelectionClipboard:
mode = QClipboard.Selection
elif Settings.get('output_mode') == OutputMode.FindBuffer:
mode = QClipboard.FindBuffer
else:
mode = QClipboard.Clipboard

self.app.clipboard().setText(str(action[1]), mode)
self.app.clipboard().setText(str(action[1]), mode)

elif action[0] == Action.set_selection:
if len(action) > 1:
Expand Down Expand Up @@ -1944,6 +1949,9 @@ def __init__(self, locale_manager: LocaleManager, parent=None) -> None:
"""Initialize the window."""
super().__init__(parent)

# Text to type on close if needed
self.output_queue = [] # type: List[str]

# Save settings
self.locale_manager = locale_manager

Expand Down Expand Up @@ -2047,6 +2055,8 @@ def __init__(self, locale_manager: LocaleManager, parent=None) -> None:
QObject, "menuOutputSelectionClipboard")
menu_output_find_buffer = self.window.findChild(
QObject, "menuOutputFindBuffer")
menu_output_auto_type = self.window.findChild(
QObject, "menuOutputAutoType")

menu_sort_module_shortcut = self.window.findChild(
QObject, "menuSortModule")
Expand Down Expand Up @@ -2104,6 +2114,7 @@ def __init__(self, locale_manager: LocaleManager, parent=None) -> None:
menu_output_default_clipboard.toggled.connect(self._menu_output_default_clipboard)
menu_output_selection_clipboard.toggled.connect(self._menu_output_selection_clipboard)
menu_output_find_buffer.toggled.connect(self._menu_output_find_buffer)
menu_output_auto_type.toggled.connect(self._menu_output_auto_type)

menu_sort_module_shortcut.toggled.connect(self._menu_sort_module)
menu_sort_ascending_shortcut.toggled.connect(self._menu_sort_ascending)
Expand All @@ -2130,6 +2141,9 @@ def __init__(self, locale_manager: LocaleManager, parent=None) -> None:
QQmlProperty.write(menu_output_find_buffer,
"checked",
int(Settings.get('output_mode')) == OutputMode.FindBuffer)
QQmlProperty.write(menu_output_auto_type,
"checked",
int(Settings.get('output_mode')) == OutputMode.AutoType)

QQmlProperty.write(menu_sort_module_shortcut,
"checked",
Expand Down Expand Up @@ -2519,6 +2533,10 @@ def _menu_output_find_buffer(self, enabled: bool) -> None:
if enabled:
Settings.set('output_mode', OutputMode.FindBuffer)

def _menu_output_auto_type(self, enabled: bool) -> None:
if enabled:
Settings.set('output_mode', OutputMode.AutoType)

def _menu_sort_module(self, enabled: bool) -> None:
if enabled:
Settings.set('sort_mode', SortMode.Module)
Expand Down Expand Up @@ -2676,6 +2694,15 @@ def close(self, manual=False, force_tray=False) -> None:

self._macos_focus_workaround()

while True:
try:
output = self.output_queue.pop()
except IndexError:
break

keyboard_device = keyboard.Controller()
keyboard_device.type(output)

def show(self) -> None:
"""Show the window."""
if self.tray:
Expand Down Expand Up @@ -3105,6 +3132,8 @@ def _load_settings(args: argparse.Namespace) -> None:
Settings.set('output_mode', OutputMode.SelectionClipboard)
elif args.output == 'macos-findbuffer':
Settings.set('output_mode', OutputMode.FindBuffer)
elif args.output == 'autotype':
Settings.set('output_mode', OutputMode.AutoType)

if args.install_module:
for metadata_url in args.install_module:
Expand Down
8 changes: 7 additions & 1 deletion pext/qml/main.qml
Expand Up @@ -617,8 +617,14 @@ ApplicationWindow {
checkable: true
exclusiveGroup: menuOutputGroup
}
}

MenuItem {
objectName: "menuOutputAutoType"
text: qsTr("Type automatically")
checkable: true
exclusiveGroup: menuOutputGroup
}
}

Menu {
title: qsTr("Sorting style")
Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -32,6 +32,7 @@
version=version,
install_requires=[
'dulwich',
'pynput',
'pyqt5'
],
description='Python-based extendable tool',
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Expand Up @@ -9,6 +9,7 @@
envlist = py35, py36

[testenv]
passenv = DISPLAY
commands =
flake8 pext/ pext_dev/__main__.py test/
mypy --ignore-missing-imports --follow-imports=skip pext/
Expand Down
2 changes: 1 addition & 1 deletion travis/build-appimage.sh
Expand Up @@ -38,7 +38,7 @@ conda config --add channels conda-forge
conda install -y xorg-libxi

# install dependencies
pip install PyQt5 PyOpenGL PyOpenGL_accelerate dulwich
pip install PyQt5 PyOpenGL PyOpenGL_accelerate dulwich pynput

# install Pext
pushd "$REPO_ROOT"/
Expand Down
2 changes: 1 addition & 1 deletion travis/build-dmg.sh
Expand Up @@ -38,7 +38,7 @@ conda create -n Pext python --yes
source activate Pext

# install dependencies
pip install PyQt5 dulwich
pip install PyQt5 dulwich pynput

# leave conda env
source deactivate
Expand Down

0 comments on commit 864c78e

Please sign in to comment.