Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Added examples tests instrumented with userale.
  • Loading branch information
mooshu1x2 committed Jul 15, 2016
1 parent bdb9b8c commit 2ec3c41c71ccaca5f7e44e5964aeb183e3e1b21e
Showing 4 changed files with 210 additions and 0 deletions.
Empty file.
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
#
# Copyright 2016 The Charles Stark Draper Laboratory, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from PyQt5.QtWidgets import QWidget, QLabel, QPushButton, QApplication, QMessageBox
from PyQt5.QtCore import QCoreApplication, QObject, QEvent

from userale.ale import Ale

# Widget #1
class TestApplication (QWidget):

def __init__(self):
super().__init__()

self.initUI()

def initUI(self):

qbtn = QPushButton('Quit', self)
qbtn.setObjectName ("testApplicationButton")
qbtn.clicked.connect(QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(50, 50)

self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Quit button')
self.show()

def test_app ():
app = QApplication(sys.argv)
ex = TestApplication()
ale = Ale ()
# install globally
app.installEventFilter (ale)

sys.exit (app.exec_())
@@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-

"""
ZetCode PyQt5 tutorial
This is a simple drag and
drop example.
author: Jan Bodnar
website: zetcode.com
last edited: January 2015
"""

import sys
from PyQt5.QtWidgets import (QPushButton, QWidget,
QLineEdit, QApplication)

from userale.ale import Ale

class Button(QPushButton):

def __init__(self, title, parent):
super().__init__(title, parent)

self.setAcceptDrops(True)


def dragEnterEvent(self, e):

if e.mimeData().hasFormat('text/plain'):
e.accept()
else:
e.ignore()

def dropEvent(self, e):

self.setText(e.mimeData().text())


class Example(QWidget):

def __init__(self):
super().__init__()

self.initUI()


def initUI(self):

edit = QLineEdit('', self)
edit.setObjectName ("testLineEdit")
edit.setDragEnabled(True)
edit.move(30, 65)

button = Button("Button", self)
button.setObjectName ("testButton")
button.move(190, 65)

self.setWindowTitle('Simple drag & drop')
self.setGeometry(300, 300, 300, 150)


def test_drag ():
app = QApplication(sys.argv)
ale = Ale ()
# install globally
app.installEventFilter (ale)
ex = Example()
ex.show()
app.exec_()
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-

"""
ZetCode PyQt5 tutorial
In this program, we can press on a button with
a left mouse click or drag and drop the button
with the right mouse click.
author: Jan Bodnar
website: zetcode.com
last edited: January 2015
"""

import sys
from PyQt5.QtWidgets import QPushButton, QWidget, QApplication
from PyQt5.QtCore import Qt, QMimeData
from PyQt5.QtGui import QDrag

from userale.ale import Ale

class Button(QPushButton):

def __init__(self, title, parent):
super().__init__(title, parent)


def mouseMoveEvent(self, e):

if e.buttons() != Qt.RightButton:
return

mimeData = QMimeData()

drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())

dropAction = drag.exec_(Qt.MoveAction)


def mousePressEvent(self, e):

QPushButton.mousePressEvent(self, e)

if e.button() == Qt.LeftButton:
print('press')


class Example(QWidget):

def __init__(self):
super().__init__()

self.initUI()


def initUI(self):

self.setAcceptDrops(True)

self.button = Button('Button', self)
self.button.move(100, 65)

self.setWindowTitle('Click or Move')
self.setGeometry(300, 300, 280, 150)


def dragEnterEvent(self, e):

e.accept()


def dropEvent(self, e):

position = e.pos()
self.button.move(position)

e.setDropAction(Qt.MoveAction)
e.accept()

def test_drag2 ():
app = QApplication(sys.argv)
ex = Example()
ale = Ale ()
# install globally
app.installEventFilter (ale)
ex.show()
app.exec_()

0 comments on commit 2ec3c41

Please sign in to comment.