Skip to content

Commit

Permalink
PySide2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
csaez committed Nov 18, 2016
1 parent 503d51c commit b69227b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 65 deletions.
27 changes: 2 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A minimal Qt based menu to quickly find and execute Maya commands and user scrip

![quicklauncher](https://cloud.githubusercontent.com/assets/2292742/17669950/1be0ea84-6353-11e6-8726-f233cfc2ea25.gif)

> `quicklauncher` relies on PySide, it should work out of the box on Autodesk Maya 2014 or greater.
> `quicklauncher` relies on PySide/PySide2 and should work out of the box on Autodesk Maya 2014 or greater.

## Installation
Expand All @@ -14,8 +14,7 @@ There are many ways to go about this, but for casual users I would recommend sim
`quicklauncher.py` to your maya script directory.

If you are a developer or want to integrate quicklauncher in your pipeline, I highly recommend
the standard `setup.py` script as it brings more flexibility and is the exact same procedure as
every other python library.
the standard `setup.py` script as it brings more flexibility.

```python
python setup.py install
Expand All @@ -36,33 +35,11 @@ import quicklauncher
quicklauncher.select_repo()
```

And alternatively, assign TAB key (it's kind of an special case as Maya reserve that key).

```python
import quicklauncher
quicklauncher.setup_hotkey()
```

> Be aware that the later override Maya default behavior of the tab key jumping between inputs in the
> attribute editor and editors alike.

For more info, check the [Wiki][] (there are a few interesting things you can do).

[Wiki]: https://github.com/csaez/quicklauncher/wiki


## Running tests

This is not something the average user should worry about, but if you want to contribute to `quicklauncher` development you can run the test suite by typing the following from the root of the project.

```bash
python setup.py test
```

> Testing requires `mock`, it should be automatically installed by running the previous snippet in case it's not already available on your system.

## Contributing

- [Check for open issues](https://github.com/csaez/quicklauncher/issues) or open a fresh issue to
Expand Down
42 changes: 24 additions & 18 deletions quicklauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,23 @@
import sys
import inspect
from importlib import import_module

from PySide import QtCore, QtGui
from maya import cmds

import maya.cmds as cmds

# qt bindings
for each in ("PySide", "PySide2"):
try:
_temp = __import__(each, globals(), locals(), ('QtCore', 'QtGui'), -1)
QtCore = _temp.QtCore
QtGui = _temp.QtGui
if each == "PySide2":
_temp = __import__(each, globals(), locals(), ['QtWidgets'], -1)
QtWidgets = _temp.QtWidgets
else:
QtWidgets = QtGui
except ImportError:
pass
else:
break

__all__ = ['show', 'get_main_window', 'get_repo', 'set_repo', 'list_scripts',
'get_scripts', 'list_commands', 'get_commands', 'run_script',
Expand Down Expand Up @@ -95,7 +108,7 @@ def run_cmd(cmd_name):


# GUI
class QuickLauncherMenu(QtGui.QMenu):
class QuickLauncherMenu(QtWidgets.QMenu):

"""A menu to find and execute Maya commands and user scripts."""

Expand All @@ -105,16 +118,16 @@ def __init__(self, *args, **kwds):

def init_gui(self):
# set search field
self.lineEdit = QtGui.QLineEdit(self)
action = QtGui.QWidgetAction(self)
self.lineEdit = QtWidgets.QLineEdit(self)
action = QtWidgets.QWidgetAction(self)
action.setDefaultWidget(self.lineEdit)
self.addAction(action)
self.lineEdit.setFocus()
# completion
items = list_scripts()
items.extend(list_commands())
completer = QtGui.QCompleter(items, self)
completer.setCompletionMode(QtGui.QCompleter.PopupCompletion)
completer = QtWidgets.QCompleter(items, self)
completer.setCompletionMode(QtWidgets.QCompleter.PopupCompletion)
completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.lineEdit.setCompleter(completer)
# connect signals
Expand All @@ -131,23 +144,16 @@ def accept(self):


def select_repo():
repo = QtGui.QFileDialog.getExistingDirectory(
repo = QtWidgets.QFileDialog.getExistingDirectory(
caption="Select repository directory",
parent=get_main_window(),
dir=get_repo())
if repo:
set_repo(repo)


def setup_hotkey():
"""Assign TAB-key to open quicklauncher"""
hotkey_sequence = QtGui.QKeySequence(QtCore.Qt.Key_Tab)
hotkey_log = QtGui.QShortcut(hotkey_sequence, get_main_window())
hotkey_log.activated.connect(show)


def get_main_window(widget=None):
widget = widget or QtGui.QApplication.activeWindow()
widget = widget or QtWidgets.QApplication.activeWindow()
if widget is None:
return
parent = widget.parent()
Expand Down
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

setup(
name='quicklauncher',
description='quicklauncher is a simple menu to find and launch Maya commands and user scripts.',
version='3.0.0',
description='quicklauncher is a simple menu to launch Maya commands and user scripts.',
version='3.1.0',
license='The MIT License',
author='Cesar Saez',
author_email='[email protected]',
url='https://www.github.com/csaez/quicklauncher',
py_modules=["quicklauncher"],
test_suite='tests',
tests_require=["mock"],
)
31 changes: 13 additions & 18 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import os
import mock
import unittest
from collections import Iterable

import quicklauncher as ql


_REPO = ql.get_repo()


Expand All @@ -18,26 +17,23 @@ def test_list_scripts(self):
self.assertEqual(len(ql.list_scripts()), len(ql.get_scripts()))

def test_list_commands(self):
with mock.patch("maya.cmds", create=True):
self.assertIsInstance(ql.list_commands(), Iterable)
self.assertIsInstance(ql.get_commands(), dict)
self.assertEqual(len(ql.list_commands()),
len(ql.get_commands()))
self.assertIsInstance(ql.list_commands(), Iterable)
self.assertIsInstance(ql.get_commands(), dict)
self.assertEqual(len(ql.list_commands()),
len(ql.get_commands()))

def test_run_cmd(self):
with mock.patch("maya.cmds", create=True):
self.assertTrue(ql.run_cmd("ls"))
self.assertTrue(ql.run_cmd("ls"))


class RepoCase(unittest.TestCase):
def setUp(self):
test_path = os.path.join(os.path.expanduser("~"), "testing")
ql.set_repo(test_path)
self.test_path = os.path.join(os.path.expanduser("~"), "testing")
ql.set_repo(self.test_path)

def tearDown(self):
ql.set_repo(_REPO)
test_path = os.path.join(os.path.expanduser("~"), "testing")
os.rmdir(test_path)
os.rmdir(self.test_path)

def test_repo(self):
test_path = os.path.join(os.path.expanduser("~"), "testing")
Expand All @@ -48,8 +44,8 @@ def test_repo(self):

class ScriptCase(unittest.TestCase):
def setUp(self):
test_path = os.path.join(os.path.expanduser("~"), "testing")
ql.set_repo(test_path)
self.test_path = os.path.join(os.path.expanduser("~"), "testing")
ql.set_repo(self.test_path)

with open(os.path.join(ql.get_repo(), "testsuite.py"), "w") as f:
code = 'print("im in the root dir")'
Expand All @@ -74,13 +70,12 @@ def tearDown(self):
os.rmdir(subdir)

ql.set_repo(_REPO)
test_path = os.path.join(os.path.expanduser("~"), "testing")
os.rmdir(test_path)
os.rmdir(self.test_path)

def test_run_script(self):
self.assertTrue(ql.run_script("testsuite.py"))
self.assertTrue(ql.run_script("test/testsuite.py"))


if __name__ == "__main__":
unittest.main(verbosity=3)
unittest.main(verbosity=3, exit=False)

0 comments on commit b69227b

Please sign in to comment.