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

Commit

Permalink
Merge branch 'develop' into pyqtgraph-core
Browse files Browse the repository at this point in the history
  • Loading branch information
campagnola committed Dec 23, 2013
2 parents 757dc50 + a61b375 commit 1dae1de
Show file tree
Hide file tree
Showing 147 changed files with 1,397 additions and 1,284 deletions.
48 changes: 17 additions & 31 deletions GraphicsScene/GraphicsScene.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
from pyqtgraph.Qt import QtCore, QtGui

from pyqtgraph.python2_3 import sortList
#try:
#from PyQt4 import QtOpenGL
#HAVE_OPENGL = True
#except ImportError:
#HAVE_OPENGL = False

from ..Qt import QtCore, QtGui
from ..python2_3 import sortList
import weakref
from pyqtgraph.Point import Point
import pyqtgraph.functions as fn
import pyqtgraph.ptime as ptime
from ..Point import Point
from .. import functions as fn
from .. import ptime as ptime
from .mouseEvents import *
import pyqtgraph.debug as debug
from . import exportDialog
from .. import debug as debug

if hasattr(QtCore, 'PYQT_VERSION'):
try:
Expand Down Expand Up @@ -489,7 +481,7 @@ def getViewWidget(self):
#return v
#else:
#return widget

def addParentContextMenus(self, item, menu, event):
"""
Can be called by any item in the scene to expand its context menu to include parent context menus.
Expand Down Expand Up @@ -519,30 +511,23 @@ def addParentContextMenus(self, item, menu, event):
event The original event that triggered the menu to appear.
============== ==================================================
"""

#items = self.itemsNearEvent(ev)

menusToAdd = []
while item is not self:
item = item.parentItem()

if item is None:
item = self

if not hasattr(item, "getContextMenus"):
continue

subMenus = item.getContextMenus(event)
if subMenus is None:
continue
if type(subMenus) is not list: ## so that some items (like FlowchartViewBox) can return multiple menus
subMenus = [subMenus]

for sm in subMenus:
menusToAdd.append(sm)

if len(menusToAdd) > 0:
subMenus = item.getContextMenus(event) or []
if isinstance(subMenus, list): ## so that some items (like FlowchartViewBox) can return multiple menus
menusToAdd.extend(subMenus)
else:
menusToAdd.append(subMenus)

if menusToAdd:
menu.addSeparator()

for m in menusToAdd:
if isinstance(m, QtGui.QMenu):
menu.addMenu(m)
Expand All @@ -559,6 +544,7 @@ def getContextMenus(self, event):

def showExportDialog(self):
if self.exportDialog is None:
from . import exportDialog
self.exportDialog = exportDialog.ExportDialog(self)
self.exportDialog.show(self.contextMenuItem)

Expand Down
18 changes: 10 additions & 8 deletions GraphicsScene/exportDialog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pyqtgraph.Qt import QtCore, QtGui, USE_PYSIDE
import pyqtgraph as pg
import pyqtgraph.exporters as exporters
from ..Qt import QtCore, QtGui, USE_PYSIDE
from .. import exporters as exporters
from .. import functions as fn
from ..graphicsItems.ViewBox import ViewBox
from ..graphicsItems.PlotItem import PlotItem

if USE_PYSIDE:
from . import exportDialogTemplate_pyside as exportDialogTemplate
Expand All @@ -18,7 +20,7 @@ def __init__(self, scene):
self.scene = scene

self.selectBox = QtGui.QGraphicsRectItem()
self.selectBox.setPen(pg.mkPen('y', width=3, style=QtCore.Qt.DashLine))
self.selectBox.setPen(fn.mkPen('y', width=3, style=QtCore.Qt.DashLine))
self.selectBox.hide()
self.scene.addItem(self.selectBox)

Expand All @@ -35,10 +37,10 @@ def __init__(self, scene):
def show(self, item=None):
if item is not None:
## Select next exportable parent of the item originally clicked on
while not isinstance(item, pg.ViewBox) and not isinstance(item, pg.PlotItem) and item is not None:
while not isinstance(item, ViewBox) and not isinstance(item, PlotItem) and item is not None:
item = item.parentItem()
## if this is a ViewBox inside a PlotItem, select the parent instead.
if isinstance(item, pg.ViewBox) and isinstance(item.parentItem(), pg.PlotItem):
if isinstance(item, ViewBox) and isinstance(item.parentItem(), PlotItem):
item = item.parentItem()
self.updateItemList(select=item)
self.setVisible(True)
Expand All @@ -64,9 +66,9 @@ def updateItemList(self, select=None):

def updateItemTree(self, item, treeItem, select=None):
si = None
if isinstance(item, pg.ViewBox):
if isinstance(item, ViewBox):
si = QtGui.QTreeWidgetItem(['ViewBox'])
elif isinstance(item, pg.PlotItem):
elif isinstance(item, PlotItem):
si = QtGui.QTreeWidgetItem(['Plot'])

if si is not None:
Expand Down
2 changes: 1 addition & 1 deletion GraphicsScene/exportDialogTemplate.ui
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<customwidget>
<class>ParameterTree</class>
<extends>QTreeWidget</extends>
<header>pyqtgraph.parametertree</header>
<header>..parametertree</header>
</customwidget>
</customwidgets>
<resources/>
Expand Down
33 changes: 21 additions & 12 deletions GraphicsScene/exportDialogTemplate_pyqt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file './GraphicsScene/exportDialogTemplate.ui'
# Form implementation generated from reading ui file './pyqtgraph/GraphicsScene/exportDialogTemplate.ui'
#
# Created: Wed Jan 30 21:02:28 2013
# by: PyQt4 UI code generator 4.9.3
# Created: Mon Dec 23 10:10:52 2013
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!

Expand All @@ -12,7 +12,16 @@
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form(object):
def setupUi(self, Form):
Expand Down Expand Up @@ -57,12 +66,12 @@ def setupUi(self, Form):
QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Export", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "Item to export:", None, QtGui.QApplication.UnicodeUTF8))
self.label_2.setText(QtGui.QApplication.translate("Form", "Export format", None, QtGui.QApplication.UnicodeUTF8))
self.exportBtn.setText(QtGui.QApplication.translate("Form", "Export", None, QtGui.QApplication.UnicodeUTF8))
self.closeBtn.setText(QtGui.QApplication.translate("Form", "Close", None, QtGui.QApplication.UnicodeUTF8))
self.label_3.setText(QtGui.QApplication.translate("Form", "Export options", None, QtGui.QApplication.UnicodeUTF8))
self.copyBtn.setText(QtGui.QApplication.translate("Form", "Copy", None, QtGui.QApplication.UnicodeUTF8))
Form.setWindowTitle(_translate("Form", "Export", None))
self.label.setText(_translate("Form", "Item to export:", None))
self.label_2.setText(_translate("Form", "Export format", None))
self.exportBtn.setText(_translate("Form", "Export", None))
self.closeBtn.setText(_translate("Form", "Close", None))
self.label_3.setText(_translate("Form", "Export options", None))
self.copyBtn.setText(_translate("Form", "Copy", None))

from pyqtgraph.parametertree import ParameterTree
from ..parametertree import ParameterTree
8 changes: 4 additions & 4 deletions GraphicsScene/exportDialogTemplate_pyside.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file './GraphicsScene/exportDialogTemplate.ui'
# Form implementation generated from reading ui file './pyqtgraph/GraphicsScene/exportDialogTemplate.ui'
#
# Created: Wed Jan 30 21:02:28 2013
# by: pyside-uic 0.2.13 running on PySide 1.1.1
# Created: Mon Dec 23 10:10:53 2013
# by: pyside-uic 0.2.14 running on PySide 1.1.2
#
# WARNING! All changes made in this file will be lost!

Expand Down Expand Up @@ -60,4 +60,4 @@ def retranslateUi(self, Form):
self.label_3.setText(QtGui.QApplication.translate("Form", "Export options", None, QtGui.QApplication.UnicodeUTF8))
self.copyBtn.setText(QtGui.QApplication.translate("Form", "Copy", None, QtGui.QApplication.UnicodeUTF8))

from pyqtgraph.parametertree import ParameterTree
from ..parametertree import ParameterTree
6 changes: 3 additions & 3 deletions GraphicsScene/mouseEvents.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyqtgraph.Point import Point
from pyqtgraph.Qt import QtCore, QtGui
from ..Point import Point
from ..Qt import QtCore, QtGui
import weakref
import pyqtgraph.ptime as ptime
from .. import ptime as ptime

class MouseDragEvent(object):
"""
Expand Down
52 changes: 49 additions & 3 deletions Qt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
## Do all Qt imports from here to allow easier PyQt / PySide compatibility
"""
This module exists to smooth out some of the differences between PySide and PyQt4:
* Automatically import either PyQt4 or PySide depending on availability
* Allow to import QtCore/QtGui pyqtgraph.Qt without specifying which Qt wrapper
you want to use.
* Declare QtCore.Signal, .Slot in PyQt4
* Declare loadUiType function for Pyside
"""

import sys, re

## Automatically determine whether to use PyQt or PySide.
Expand All @@ -23,8 +33,41 @@
from PySide import QtGui, QtCore, QtOpenGL, QtSvg
import PySide
VERSION_INFO = 'PySide ' + PySide.__version__

# Make a loadUiType function like PyQt has

# Credit:
# http://stackoverflow.com/questions/4442286/python-code-genration-with-pyside-uic/14195313#14195313

def loadUiType(uiFile):
"""
Pyside "loadUiType" command like PyQt4 has one, so we have to convert the ui file to py code in-memory first and then execute it in a special frame to retrieve the form_class.
"""
import pysideuic
import xml.etree.ElementTree as xml
from io import StringIO

parsed = xml.parse(uiFile)
widget_class = parsed.find('widget').get('class')
form_class = parsed.find('class').text

with open(uiFile, 'r') as f:
o = StringIO()
frame = {}

pysideuic.compileUi(f, o, indent=0)
pyc = compile(o.getvalue(), '<string>', 'exec')
exec(pyc, frame)

#Fetch the base_class and form class based on their type in the xml from designer
form_class = frame['Ui_%s'%form_class]
base_class = eval('QtGui.%s'%widget_class)

return form_class, base_class


else:
from PyQt4 import QtGui, QtCore
from PyQt4 import QtGui, QtCore, uic
try:
from PyQt4 import QtSvg
except ImportError:
Expand All @@ -34,6 +77,9 @@
except ImportError:
pass


loadUiType = uic.loadUiType

QtCore.Signal = QtCore.pyqtSignal
VERSION_INFO = 'PyQt4 ' + QtCore.PYQT_VERSION_STR + ' Qt ' + QtCore.QT_VERSION_STR

Expand All @@ -43,6 +89,6 @@
QtVersion = PySide.QtCore.__version__ if USE_PYSIDE else QtCore.QT_VERSION_STR
m = re.match(r'(\d+)\.(\d+).*', QtVersion)
if m is not None and list(map(int, m.groups())) < versionReq:
print(map(int, m.groups()))
print(list(map(int, m.groups())))
raise Exception('pyqtgraph requires Qt version >= %d.%d (your version is %s)' % (versionReq[0], versionReq[1], QtVersion))

5 changes: 2 additions & 3 deletions SRTTransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from .Qt import QtCore, QtGui
from .Point import Point
import numpy as np
import pyqtgraph as pg

class SRTTransform(QtGui.QTransform):
"""Transform that can always be represented as a combination of 3 matrices: scale * rotate * translate
Expand Down Expand Up @@ -77,7 +76,7 @@ def setFromQTransform(self, tr):
self.update()

def setFromMatrix4x4(self, m):
m = pg.SRTTransform3D(m)
m = SRTTransform3D(m)
angle, axis = m.getRotation()
if angle != 0 and (axis[0] != 0 or axis[1] != 0 or axis[2] != 1):
print("angle: %s axis: %s" % (str(angle), str(axis)))
Expand Down Expand Up @@ -256,4 +255,4 @@ def update():
w1.sigRegionChanged.connect(update)
#w2.sigRegionChanged.connect(update2)

from .SRTTransform3D import SRTTransform3D
26 changes: 13 additions & 13 deletions SRTTransform3D.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding: utf-8 -*-
from .Qt import QtCore, QtGui
from .Vector import Vector
from .SRTTransform import SRTTransform
import pyqtgraph as pg
from .Transform3D import Transform3D
from .Vector import Vector
import numpy as np
import scipy.linalg

class SRTTransform3D(pg.Transform3D):
class SRTTransform3D(Transform3D):
"""4x4 Transform matrix that can always be represented as a combination of 3 matrices: scale * rotate * translate
This transform has no shear; angles are always preserved.
"""
def __init__(self, init=None):
pg.Transform3D.__init__(self)
Transform3D.__init__(self)
self.reset()
if init is None:
return
Expand Down Expand Up @@ -44,14 +44,14 @@ def __init__(self, init=None):


def getScale(self):
return pg.Vector(self._state['scale'])
return Vector(self._state['scale'])

def getRotation(self):
"""Return (angle, axis) of rotation"""
return self._state['angle'], pg.Vector(self._state['axis'])
return self._state['angle'], Vector(self._state['axis'])

def getTranslation(self):
return pg.Vector(self._state['pos'])
return Vector(self._state['pos'])

def reset(self):
self._state = {
Expand Down Expand Up @@ -169,7 +169,7 @@ def setFromMatrix(self, m):

def as2D(self):
"""Return a QTransform representing the x,y portion of this transform (if possible)"""
return pg.SRTTransform(self)
return SRTTransform(self)

#def __div__(self, t):
#"""A / B == B^-1 * A"""
Expand Down Expand Up @@ -202,11 +202,11 @@ def restoreState(self, state):
self.update()

def update(self):
pg.Transform3D.setToIdentity(self)
Transform3D.setToIdentity(self)
## modifications to the transform are multiplied on the right, so we need to reverse order here.
pg.Transform3D.translate(self, *self._state['pos'])
pg.Transform3D.rotate(self, self._state['angle'], *self._state['axis'])
pg.Transform3D.scale(self, *self._state['scale'])
Transform3D.translate(self, *self._state['pos'])
Transform3D.rotate(self, self._state['angle'], *self._state['axis'])
Transform3D.scale(self, *self._state['scale'])

def __repr__(self):
return str(self.saveState())
Expand Down Expand Up @@ -311,4 +311,4 @@ def update():
w1.sigRegionChanged.connect(update)
#w2.sigRegionChanged.connect(update2)

from .SRTTransform import SRTTransform
2 changes: 1 addition & 1 deletion ThreadsafeTimer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyqtgraph.Qt import QtCore, QtGui
from .Qt import QtCore, QtGui

class ThreadsafeTimer(QtCore.QObject):
"""
Expand Down
Loading

0 comments on commit 1dae1de

Please sign in to comment.