Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Feature/expconf without spyder #1465

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/sardana/taurus/qt/qtgui/extra_sardana/sardanaeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
from taurus.qt.qtgui.editor import TaurusBaseEditor
from taurus.qt.qtgui.dialog import ProtectTaurusMessageBox

# consider adding an utility in taurusedirot to create actions
from spyder.utils.qthelpers import create_action
from sardana.taurus.qt.qtgui.extra_sardana.spyder_util import create_action

from .macrotree import MacroSelectionDialog
from .elementtree import SardanaElementTreeWidget
Expand Down
97 changes: 97 additions & 0 deletions src/sardana/taurus/qt/qtgui/extra_sardana/spyder_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env python

##############################################################################
##
# This file is part of Sardana
##
# http://www.sardana-controls.org/
##
# Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
# Sardana is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
##
# Sardana is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
##
# You should have received a copy of the GNU Lesser General Public License
# along with Sardana. If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################

"""
Functions vendored from Spyder.

.. note::

In comparison to original Spyder code, this code was modified -
it drops compatiblity layer for Python 2/3 and PyQt 4/5.
Right now it will only work for Python3 and PyQt5.
"""

import sys

from taurus.external.qt import Qt


class SpyderAction(Qt.QAction):
"""Spyder QAction class wrapper to handle cross platform patches."""

def __init__(self, *args, **kwargs):
"""Spyder QAction class wrapper to handle cross platform patches."""
super(SpyderAction, self).__init__(*args, **kwargs)
if sys.platform == "darwin":
self.setIconVisibleInMenu(False)

def __str__(self):
return "SpyderAction('{0}')".format(self.text())

def __repr__(self):
return "SpyderAction('{0}')".format(self.text())


def create_action(parent, text, shortcut=None, icon=None, tip=None,
toggled=None, triggered=None, data=None, menurole=None,
context=Qt.WindowShortcut):
"""Create a QAction"""
action = SpyderAction(text, parent)
if triggered is not None:
action.triggered.connect(triggered)
if toggled is not None:
action.toggled.connect(toggled)
action.setCheckable(True)
if icon is not None:
action.setIcon(icon)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if data is not None:
action.setData(data)
if menurole is not None:
action.setMenuRole(menurole)

# Workround for Mac because setting context=Qt.WidgetShortcut
# there doesn't have any effect
if sys.platform == 'darwin':
action._shown_shortcut = None
if context == Qt.WidgetShortcut:
if shortcut is not None:
action._shown_shortcut = shortcut
else:
# This is going to be filled by
# main.register_shortcut
action._shown_shortcut = 'missing'
else:
if shortcut is not None:
action.setShortcut(shortcut)
action.setShortcutContext(context)
else:
if shortcut is not None:
action.setShortcut(shortcut)
action.setShortcutContext(context)

return action