This repository has been archived by the owner. It is now read-only.
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_() | ||
|