Skip to content

Commit

Permalink
Python clean
Browse files Browse the repository at this point in the history
Typo
  • Loading branch information
aoblet committed Jun 2, 2016
1 parent 2a4cb85 commit ba71f94
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 126 deletions.
3 changes: 0 additions & 3 deletions example/dynamicList/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import sys
sys.path.append("../..")

from quickmamba.models import QObjectListModel

from PyQt5 import QtCore, QtWidgets, QtQuick


Expand Down
4 changes: 1 addition & 3 deletions example/dynamicRepeater/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sys
sys.path.append("../..")

from PyQt5 import QtCore, QtWidgets, QtQuick
from quickmamba.models import QObjectListModel
from PyQt5 import QtCore, QtWidgets, QtQuick


class ClipWrapper(QtCore.QObject):
Expand Down
17 changes: 9 additions & 8 deletions example/instantCoding/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import sys
sys.path.append("../..")

from quickmamba.utils import QmlInstantCoding

from PyQt5 import QtCore, QtWidgets, QtQuick

from quickmamba.utils.instantcoding import QmlInstantCoding, ReloadComponent
from PyQt5 import QtCore, QtWidgets, QtQuick, QtQml
import os


Expand All @@ -14,9 +10,14 @@ def main():
view.setResizeMode(QtQuick.QQuickView.SizeRootObjectToView)

# Create a declarative view
view.setSource(QtCore.QUrl("source.qml"))
component = QtQml.QQmlComponent(view)
topLevelItem = component.create()
qmlFile = QtCore.QUrl("source.qml")
view.setSource(qmlFile)

# Declare we are using instant coding tool on this view
qic = QmlInstantCoding(view, verbose=True)
qic = QmlInstantCoding(view, ReloadComponent(qmlFile, component, topLevelItem), verbose=True)

# Add any source file (.qml and .js by default) in current working directory
qic.addFilesFromDirectory(os.getcwd())

Expand Down
12 changes: 2 additions & 10 deletions example/screenPicker/main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import sys
from PyQt5 import QtCore, QtWidgets, QtQuick
#Fix execution shader bug
from OpenGL import GL


import os

currentFilePath = os.path.dirname(os.path.abspath(__file__))
quickmambaPath = os.path.join(currentFilePath, '../QuickMamba')
sys.path.append(quickmambaPath)

from OpenGL import GL # Fix execution shader bug
import quickmamba


if __name__ == '__main__':
quickmamba.qmlRegister()
app = QtWidgets.QApplication(sys.argv)
Expand Down
6 changes: 2 additions & 4 deletions example/signal/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import sys
sys.path.append("../..")

from quickmamba.patterns import Signal


# Sample usage:
class Model(object):
def __init__(self, value):
Expand All @@ -11,7 +9,7 @@ def __init__(self, value):

def set_value(self, value):
self.__value = value
self.changed() # Emit signal
self.changed() # Emit signal

def get_value(self):
return self.__value
Expand Down
1 change: 1 addition & 0 deletions quickmamba/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from PyQt5 import QtQml


def qmlRegister():
QtQml.qmlRegisterType(WheelArea, "QuickMamba", 1, 0, "WheelAreaImpl")
QtQml.qmlRegisterType(ExternDropArea, "QuickMamba", 1, 0, "ExternDropAreaImpl")
Expand Down
43 changes: 18 additions & 25 deletions quickmamba/gui/colorPicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
from PyQt5 import QtQuick
from PyQt5.QtGui import QCursor, QColor, QGuiApplication


class ColorPickingEventFilter(QtCore.QObject):
def __init__(self, screenpicker):
QtCore.QObject.__init__(self, screenpicker)
self._screenpicker = screenpicker

def eventFilter(self, obj, event):
if(event.type() == QtCore.QEvent.MouseMove):
if event.type() == QtCore.QEvent.MouseMove:
self._screenpicker.updateCurrentColor()
elif(event.type() == QtCore.QEvent.MouseButtonRelease):
elif event.type() == QtCore.QEvent.MouseButtonRelease:
self._screenpicker.setGrabbing(False)
self._screenpicker.accepted.emit()

Expand All @@ -20,20 +21,16 @@ def eventFilter(self, obj, event):

class ColorPicker(QtQuick.QQuickItem):
"""
Define the common methods and fields for screenPicker.
Define the common methods and fields for screenPicker.
"""

def __init__(self, parent = None):
def __init__(self, parent=None):
QtQuick.QQuickItem.__init__(self, parent)
self._currentColor = QColor("#FFFFFF")
self._grabbing = False
self._desktop = QtWidgets.QDesktopWidget()
self._colorPickingEventFilter = ColorPickingEventFilter(self)

# ######################################## Methods private to this class ####################################### #

# ## Getters ## #

def getCurrentColor(self):
return self._currentColor

Expand All @@ -45,19 +42,19 @@ def isGrabbing(self):
return self._grabbing

def setGrabbing(self, grabbing):
if(self._grabbing != grabbing):
self._grabbing = grabbing
if(self._grabbing):
self.installEventFilter(self._colorPickingEventFilter)
QGuiApplication.setOverrideCursor(QCursor(QtCore.Qt.CrossCursor))
self.grabMouse()
else:
self.ungrabMouse()
self.removeEventFilter(self._colorPickingEventFilter)
QGuiApplication.restoreOverrideCursor()
self.grabbingChanged.emit()

# ## Others ## #
if self._grabbing == grabbing:
return

self._grabbing = grabbing
if self._grabbing:
self.installEventFilter(self._colorPickingEventFilter)
QGuiApplication.setOverrideCursor(QCursor(QtCore.Qt.CrossCursor))
self.grabMouse()
else:
self.ungrabMouse()
self.removeEventFilter(self._colorPickingEventFilter)
QGuiApplication.restoreOverrideCursor()
self.grabbingChanged.emit()

def updateCurrentColor(self):
cursorPos = QCursor.pos()
Expand All @@ -67,12 +64,8 @@ def updateCurrentColor(self):
qColor = QColor(qImage.pixel(0, 0))
self.setCurrentColor(qColor)

# ############################################# Data exposed to QML ############################################## #

accepted = QtCore.pyqtSignal()

currentColorChanged = QtCore.pyqtSignal()
currentColor = QtCore.pyqtProperty(QColor, getCurrentColor, setCurrentColor, notify=currentColorChanged)

grabbingChanged = QtCore.pyqtSignal()
grabbing = QtCore.pyqtProperty(bool, isGrabbing, setGrabbing, notify=grabbingChanged)
48 changes: 22 additions & 26 deletions quickmamba/gui/externDropArea.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
from PyQt5 import QtCore, QtGui
from PyQt5 import QtQuick


class ExternDropArea(QtQuick.QQuickItem):
# QGraphicsSceneDragDropEvent:
#Qt::MouseButtons buttons, Qt::DropAction dropAction, const QMimeData mimeData, Qt::KeyboardModifiers modifiers, QPointF pos, Qt::DropActions possibleActions, Qt::DropAction proposedAction, QWidget source
# Qt::MouseButtons buttons, Qt::DropAction dropAction,
# const QMimeData mimeData, Qt::KeyboardModifiers modifiers,
# QPointF pos, Qt::DropActions possibleActions, Qt::DropAction proposedAction, QWidget source
internDragEnter = QtCore.pyqtSignal(
bool, str, # text
bool, str, # html
bool, str, # urls
bool, str, # text
bool, str, # html
bool, str, # urls
QtCore.Qt.MouseButtons, QtCore.Qt.DropAction,
QtCore.Qt.KeyboardModifiers, QtCore.QPointF,
QtCore.Qt.DropActions, QtCore.Qt.DropAction,
str)
internDragMove = QtCore.pyqtSignal(
bool, str, # text
bool, str, # html
bool, str, # urls
bool, str, # text
bool, str, # html
bool, str, # urls
QtCore.Qt.MouseButtons, QtCore.Qt.DropAction,
QtCore.Qt.KeyboardModifiers, QtCore.QPointF,
QtCore.Qt.DropActions, QtCore.Qt.DropAction,
str)
internDragLeave = QtCore.pyqtSignal(
bool, str, # text
bool, str, # html
bool, str, # urls
bool, str, # text
bool, str, # html
bool, str, # urls
QtCore.Qt.MouseButtons, QtCore.Qt.DropAction,
QtCore.Qt.KeyboardModifiers, QtCore.QPointF,
QtCore.Qt.DropActions, QtCore.Qt.DropAction,
str)
internDrop = QtCore.pyqtSignal(
bool, str, # text
bool, str, # html
bool, str, # urls
bool, str, # text
bool, str, # html
bool, str, # urls
QtCore.Qt.MouseButtons, QtCore.Qt.DropAction,
QtCore.Qt.KeyboardModifiers, QtCore.QPointF,
QtCore.Qt.DropActions, QtCore.Qt.DropAction,
str)

def __init__(self, parent = None):
def __init__(self, parent=None):
super(ExternDropArea, self).__init__(parent)
#self.setAcceptDrops(True)

def dragEnterEvent(self, event):
#print 'dragEnterEvent'

urls = event.mimeData().urls()
firstUrl = urls[0].toLocalFile() if len(urls) else ""
firstUrl = urls[0].toLocalFile() if len(urls) else '' \
''
self.internDragEnter.emit(
event.mimeData().hasText(), event.mimeData().text(),
event.mimeData().hasHtml(), event.mimeData().html(),
Expand All @@ -66,10 +68,9 @@ def dragEnterEvent(self, event):
event.setAccepted(self._acceptDropValue)

def dragMoveEvent(self, event):
#print 'dragMoveEvent'

urls = event.mimeData().urls()
firstUrl = urls[0].toLocalFile() if len(urls) else ""
firstUrl = urls[0].toLocalFile() if len(urls) else ''

self.internDragMove.emit(
event.mimeData().hasText(), event.mimeData().text(),
event.mimeData().hasHtml(), event.mimeData().html(),
Expand All @@ -86,10 +87,9 @@ def dragMoveEvent(self, event):
event.setAccepted(self._acceptDropValue)

def dragLeaveEvent(self, event):
#print 'dragLeaveEvent'

urls = event.mimeData().urls()
firstUrl = urls[0].toLocalFile() if len(urls) else ""

self.internDragLeave.emit(
event.mimeData().hasText(), event.mimeData().text(),
event.mimeData().hasHtml(), event.mimeData().html(),
Expand All @@ -107,8 +107,6 @@ def dragLeaveEvent(self, event):
self.unsetCursor()

def dropEvent(self, event):
#print 'dropEvent'

# hasText() text() text/plain
# hasHtml() html() text/html
# hasUrls() urls() text/uri-list
Expand All @@ -134,7 +132,6 @@ def dropEvent(self, event):
event.possibleActions(), event.proposedAction(),
"")
#event.source().accessibleName() if event.source() else "")


if self._acceptDropValue:
event.acceptProposedAction()
Expand All @@ -154,7 +151,6 @@ def setAcceptDrop(self, acceptDrop):
self.acceptDropChanged.emit()

acceptDropChanged = QtCore.pyqtSignal()

_acceptDropValue = True
acceptDrop = QtCore.pyqtProperty(bool, getAcceptDrop, setAcceptDrop, notify=acceptDropChanged)

5 changes: 3 additions & 2 deletions quickmamba/gui/wheelArea.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from PyQt5 import QtCore
from PyQt5 import QtQuick


class WheelArea(QtQuick.QQuickItem):
#QPointF pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers
# QPointF pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers
internVerticalWheel = QtCore.pyqtSignal(QtCore.QPointF, int, QtCore.Qt.MouseButtons, QtCore.Qt.KeyboardModifiers)
internHorizontalWheel = QtCore.pyqtSignal(QtCore.QPointF, int, QtCore.Qt.MouseButtons, QtCore.Qt.KeyboardModifiers)

def __init__(self, parent = None):
def __init__(self, parent=None):
QtQuick.QQuickItem.__init__(self, parent)

def wheelEvent(self, event):
Expand Down
Loading

0 comments on commit ba71f94

Please sign in to comment.