Consider the following minimal example. How can I modify it, that it does something else, when a modifier key is pressed during the drop event as indicated in the comment in the code snipped below. Suppose you drop a file from nautilus or something like that to my example.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class MyDropLabel(QLabel):
myDroppedSignal = pyqtSignal(str)
myDroppedSignalModified = pyqtSignal()
def __init__(self,text):
super(MyDropLabel, self).__init__(text)
self.setAcceptDrops(True)
def dragMoveEvent(self, e):
e.accept()
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
if e.mimeData().hasUrls():
s = e.mimeData().urls()[0].path()
self.myDroppedSignal.emit(s)
e.accept()
##if a modifier key, for example shift or ctrl was pressed to something else and emit myDroppedSignalModified
class MyWidget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.hlayout = QHBoxLayout()
self.setLayout(self.hlayout)
self.label = MyDropLabel("Drop something here")
self.hlayout.addWidget(self.label)
#self.setCentralWidget(self.label)
self.label.myDroppedSignal.connect(self.myDroppedHandler)
def myDroppedHandler(self,s):
self.label.setText(QString(s))
if __name__ == "__main__":
app = QApplication(sys.argv)
da = MyWidget()
da.show()
sys.exit(app.exec_())
You can, for example, set a self.keyIsPressed state by installEventFilter( QObject * filterObj ) to filter the QEvent.KeyPress that you define.
This is an example using QApplication.keyboardModifiers:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import os
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class droppableLabel(QLabel):
fileDropped = pyqtSignal(list)
def __init__(self, type, parent=None):
super(droppableLabel, self).__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.fileDropped.emit(links)
else:
event.ignore()
class droppableWidget(QWidget):
def __init__(self, parent=None):
super(droppableWidget, self).__init__(parent)
self.label = droppableLabel(self)
self.label.fileDropped.connect(self.on_label_fileDropped)
self.label.setText("Press CTRL/SHIFT/None and drop some files here")
self.label.setMinimumSize(QSize(40, 100))
self.verticalLayout = QVBoxLayout(self)
self.verticalLayout.addWidget(self.label)
self.verticalLayout.setMargin(0)
#pyqtSlot(list)
def on_label_fileDropped(self, fileNames):
droppedFiles = [ fileName
for fileName in fileNames
if os.path.exists(fileName)
]
if droppedFiles:
keyModifiers = QApplication.keyboardModifiers()
if keyModifiers == Qt.ShiftModifier:
print "SHIFT"
formatter = "\n"
elif keyModifiers == Qt.ControlModifier:
print "CTRL"
formatter = ","
else:
print "NONE"
formatter = "|"
self.label.setText(formatter.join(droppedFiles))
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
main = droppableWidget()
main.show()
sys.exit(app.exec_())
Related
I have a number of QTreeWidget. Here, there are two trees.
the left one has "a" , "b".
I want to drag this item into the right tree.
I have no error but the item become empty.
How should I do for dragging the left data to the right tree?
and why?
data is this.
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x02\x00a\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\x00\x02\x00b'
from PySide import QtCore
from PySide import QtGui
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=None)
self.sequoia = Sequoia()
self.baobab = Baobab()
self.c_widget = QtGui.QWidget()
h_boxlayout = QtGui.QHBoxLayout()
h_boxlayout.addWidget(self.sequoia, 30)
h_boxlayout.addWidget(self.baobab, 70)
self.c_widget.setLayout(h_boxlayout)
self.setCentralWidget(self.c_widget)
class Sequoia(QtGui.QTreeWidget):
def __init__(self, parent=None):
super(Sequoia, self).__init__(parent=None)
self.setColumnCount(2)
self.setAcceptDrops(True)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.sampleitem = QtGui.QTreeWidgetItem()
self.sampleitem.setText(0, "a")
self.sampleitem.setText(1, "b")
self.addTopLevelItem(self.sampleitem)
class Baobab(QtGui.QTreeWidget):
def __init__(self, parent=None):
super(Baobab, self).__init__(parent=None)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.setColumnCount(2)
def dragEnterEvent(self, event):
if event.mimeData().hasFormat('application/x-qabstractitemmodeldatalist'):
event.accept()
return QtGui.QTreeWidget.dragEnterEvent(self, event)
def dragMoveEvent(self, event):
if event.mimeData().hasFormat('application/x-qabstractitemmodeldatalist') and not isinstance(event, QtGui.QDropEvent):
event.accept()
return QtGui.QTreeWidget.dragMoveEvent(self, event)
def dropEvent(self, event):
if event.mimeData().hasFormat('application/x-qabstractitemmodeldatalist'):
bytearray = event.mimeData().data('application/x-qabstractitemmodeldatalist')
datastream = QtCore.QDataStream(bytearray, QtCore.QIODevice.ReadOnly)
print(3306, bytearray.data())
item = QtGui.QTreeWidgetItem()
item.setFlags(QtCore.Qt.ItemFlag.ItemIsEditable|QtCore.Qt.ItemFlag.ItemIsEnabled|QtCore.Qt.ItemFlag.ItemIsSelectable|QtCore.Qt.ItemIsDragEnabled|QtCore.Qt.ItemIsDropEnabled)
item.read(datastream)
self.addTopLevelItem(item)
def main():
try:
QtGui.QApplication([])
except Exception as e:
print(e)
mw = MainWindow()
mw.show()
sys.exit(QtGui.QApplication.exec_())
if __name__ == "__main__":
main()
It is not necessary to implement your own drag-and-drop method between in QTreeWidget, you just have to configure it correctly:
from PySide import QtCore, QtGui
import sys
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent=None)
self.sequoia = Sequoia()
self.baobab = Baobab()
self.c_widget = QtGui.QWidget()
h_boxlayout = QtGui.QHBoxLayout(self.c_widget)
self.setCentralWidget(self.c_widget)
h_boxlayout.addWidget(self.sequoia, 30)
h_boxlayout.addWidget(self.baobab, 70)
class Sequoia(QtGui.QTreeWidget):
def __init__(self, parent=None):
super(Sequoia, self).__init__(parent=None)
self.setColumnCount(2)
self.setDefaultDropAction(QtCore.Qt.CopyAction)
self.setDragDropMode(QtGui.QAbstractItemView.InternalMove)
self.setAcceptDrops(True)
self.sampleitem = QtGui.QTreeWidgetItem()
self.sampleitem.setText(0, "a")
self.sampleitem.setText(1, "b")
self.addTopLevelItem(self.sampleitem)
class Baobab(QtGui.QTreeWidget):
def __init__(self, parent=None):
super(Baobab, self).__init__(parent=None)
self.setColumnCount(2)
self.setAcceptDrops(True)
def main():
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
If you still want to implement it manually then if we use your perspective a possible solution is:
def dropEvent(self, event):
if event.mimeData().hasFormat(
"application/x-qabstractitemmodeldatalist"
):
ba = event.mimeData().data(
"application/x-qabstractitemmodeldatalist"
)
ds = QtCore.QDataStream(
ba, QtCore.QIODevice.ReadOnly
)
i = 0
item = QtGui.QTreeWidgetItem()
while not ds.atEnd():
row = ds.readInt32()
column = ds.readInt32()
map_items = ds.readInt32()
self.addTopLevelItem(item)
for _ in range(map_items):
role = ds.readInt32()
value = ds.readQVariant()
item.setData(i, role, value)
i = (i + 1) % self.columnCount()
But the above is forced, a better solution is to use the dropMimeData method of the model:
def dropEvent(self, event):
if event.mimeData().hasFormat(
"application/x-qabstractitemmodeldatalist"
):
parent = self.indexAt(event.pos())
self.model().dropMimeData(
event.mimeData(), event.dropAction(), 0, 0, parent
)
I am trying to filter elements in listview from the dropdown option user selected. Here is my code so far.
class DirectoryView(QWidget):
def __init__(self):
super().__init__()
self.layout = QHBoxLayout(self)
self.listview = QListView()
self.layout.addWidget(self.listview)
self.setAcceptDrops(True)
self.listview.setSelectionMode(
QtWidgets.QAbstractItemView.ExtendedSelection
)
self.fileModel = QFileSystemModel()
self.listview.setModel(self.fileModel)
self.cb = QComboBox()
self.layout.addWidget(self.cb)
self.cb.currentTextChanged.connect(self.filterClicked)
self.cb.addItem(".mp4")
self.cb.addItem(".gif")
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
if e.mimeData().hasUrls():
e.accept()
for url in e.mimeData().urls():
print(url)
fname = str(url.toLocalFile())
self.updateDirectoryView(fname)
def updateDirectoryView(self,path):
self.listview.setRootIndex(self.fileModel.setRootPath(path))
def filterClicked(self):
print("todo")
I want to filter elements when user change option of the dropdown.
You have to use setNameFilters() and pass a list of wildcards in addition set False to nameFilterDisables:
from PyQt5 import QtCore, QtGui, QtWidgets
class DirectoryView(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setAcceptDrops(True)
self.listview = QtWidgets.QListView()
self.listview.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.fileModel = QtWidgets.QFileSystemModel(nameFilterDisables=False)
self.listview.setModel(self.fileModel)
self.cb = QtWidgets.QComboBox()
self.cb.currentTextChanged.connect(self.filterChanged)
layout = QtWidgets.QHBoxLayout(self)
layout.addWidget(self.listview)
layout.addWidget(self.cb)
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
if e.mimeData().hasUrls():
e.accept()
for url in e.mimeData().urls():
if url.isLocalFile():
if self.updateDirectoryView(url.toLocalFile()):
break
def updateDirectoryView(self, path):
fi = QtCore.QFileInfo(path)
if fi.isDir():
self.listview.setRootIndex(self.fileModel.setRootPath(path))
d = QtCore.QDir(path)
suffixes = set()
for fi in d.entryInfoList(filters=QtCore.QDir.Files):
if fi.isFile():
suffixes.add("."+fi.suffix())
self.cb.clear()
self.cb.addItems(sorted(suffixes))
return True
return False
#QtCore.pyqtSlot(str)
def filterChanged(self, text):
self.fileModel.setNameFilters(["*"+text])
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = DirectoryView()
w.show()
sys.exit(app.exec_())
is there a way to update the tooltip of a QLabel (or whatever) continuously?
e.g. the following code uses a timer that continuously updates a label and its tooltip.
while i can see the label change, if i hover over the QLabel i will get a tooltip with the last current value. the tooltip stays "fixed", until i move the mouse, which updates the tooltip to it's new value.
!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.value=0
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
self.lbl = QtGui.QLabel(self)
self.lbl.setText("foo")
self.lbl.setToolTip("bar")
self.timer = QtCore.QBasicTimer()
self.timer.start(100, self)
hbox.addWidget(self.lbl)
self.setLayout(hbox)
self.show()
def timerEvent(self, x):
self.value=self.value+1
self.lbl.setText("foo: %03d" % self.value)
self.lbl.setToolTip("bar: %03d" % self.value)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
is there a way to update the tooltip without having to move the mouse?
Well it wasn't easy, but here is the code that should do what you want:
!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
hbox = QtGui.QHBoxLayout(self)
self.lbl = MyLabel(self)
self.lbl.setText("foo")
self.lbl.setToolTip("bar")
hbox.addWidget(self.lbl)
label2 = QtGui.QLabel('another label')
hbox.addWidget(label2)
label2.setToolTip('a normal tooltip')
self.setLayout(hbox)
self.show()
class MyLabel(QtGui.QLabel):
def __init__(self,*args,**kwargs):
QtGui.QLabel.__init__(self,*args,**kwargs)
self._timer = QtCore.QBasicTimer()
self._timer.start(100, self)
self._value = 0
self._last_event_pos = None
def event(self,event):
if event.type() == QtCore.QEvent.ToolTip:
self._last_event_pos = event.globalPos()
return True
elif event.type() == QtCore.QEvent.Leave:
self._last_event_pos = None
QtGui.QToolTip.hideText()
return QtGui.QLabel.event(self,event)
def timerEvent(self, x):
self._value += 1
if self._last_event_pos:
QtGui.QToolTip.hideText()
QtGui.QToolTip.showText(self._last_event_pos, "bar: %03d" % self._value)
self.setText("foo: %03d" % self._value)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
so following #three_pineapples original proposal, this is what i came up with:
override the setToolTip() function to call hideText();showText(), but only
if the mouse-pointer is currently hovering over the label (detected in event())
here's the code:
class MyLabel(QtGui.QLabel):
def __init__(self,*args,**kwargs):
QtGui.QLabel.__init__(self,*args,**kwargs)
self._setToolTip=QtGui.QLabel.setToolTip
self._last_event_pos = None
self._tooltip=QtGui.QLabel.toolTip(self)
def event(self,event):
if event.type() == QtCore.QEvent.ToolTip:
self._last_event_pos = event.globalPos()
return True
elif event.type() == QtCore.QEvent.Leave:
self._last_event_pos = None
QtGui.QToolTip.hideText()
return QtGui.QLabel.event(self,event)
def setToolTip(self, tt):
self._setToolTip(self, tt)
if self._last_event_pos:
QtGui.QToolTip.hideText()
QtGui.QToolTip.showText(self._last_event_pos,
QtGui.QLabel.toolTip(self))
I've been working on this for some time now and I can't figure out what I'm doing wrong. I hope someone here can help.
I'm trying to get hover events to work when I mouse over an Svg item that's in a QGraphicsScene. Here's the code that I've been playing with.
#!/usr/bin/python
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
class Main(QWidget):
def __init__(self):
super(Main, self).__init__()
hbox = QHBoxLayout()
self.setLayout(hbox)
self.view = MyView(self)
self.scene = QGraphicsScene()
self.view.setScene(self.scene)
hbox.addWidget(self.view)
class MyView(QGraphicsView):
def __init__(self, parent):
super(MyView, self).__init__(parent)
self.parent = parent
def mousePressEvent(self, event):
super(MyView, self).mousePressEvent(event)
test = MySvg()
self.parent.scene.addItem(test.image)
class MySvg(QGraphicsSvgItem):
def __init__(self):
super(MySvg, self).__init__()
self.image = QGraphicsSvgItem('ubuntu.svg')
self.image.setFlags(QGraphicsItem.ItemIsSelectable|
QGraphicsItem.ItemIsMovable)
self.setAcceptsHoverEvents(True)
def hoverEnterEvent(self, event):
print 'Enter'
def hoverLeaveEvent(self, event):
print 'Leave'
def hoverMoveEvent(self, event):
print 'Moving'
def runMain():
app = QApplication(sys.argv)
ex = Main()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
runMain()
Hope someone can help.
You are monitoring hover events for MySvg but you are adding another QGraphicsSvgItem to the view that is just an instance (MySvg.image) in MySvg. Your MySvg is not even in the view. Try like this:
#!/usr/bin/python
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtSvg import *
class Main(QWidget):
def __init__(self):
super(Main, self).__init__()
hbox = QHBoxLayout()
self.setLayout(hbox)
self.view = MyView(self)
self.scene = QGraphicsScene()
self.view.setScene(self.scene)
hbox.addWidget(self.view)
class MyView(QGraphicsView):
def __init__(self, parent):
super(MyView, self).__init__(parent)
self.parent = parent
def mousePressEvent(self, event):
super(MyView, self).mousePressEvent(event)
test = MySvg()
self.parent.scene.addItem(test)
class MySvg(QGraphicsSvgItem):
def __init__(self):
super(MySvg, self).__init__('ubuntu.svg')
self.setFlags(QGraphicsItem.ItemIsSelectable|
QGraphicsItem.ItemIsMovable)
self.setAcceptsHoverEvents(True)
def hoverEnterEvent(self, event):
print 'Enter'
def hoverLeaveEvent(self, event):
print 'Leave'
def hoverMoveEvent(self, event):
print 'Moving'
def runMain():
app = QApplication(sys.argv)
ex = Main()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
runMain()
I've been coding a OCR book scanning thing (it renames pages by reading the page number), and have switched to a GUI from my basic CLI Python script.
I'm using PyQT4 and looked at a ton of documents on drag and drop, but no luck. It just refuses to take those files! I was using these to articles for my UI design:
http://tech.xster.net/tips/pyqt-drag-images-into-list-widget-for-thumbnail-list/
http://zetcode.com/tutorials/pyqt4/dragdrop/
I noticed that there are a TON of ways to setup a PyQT4 GUI. Which one works the best?
Oops, here's the source code for the project.
The main script:
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4.QtGui import QListWidget
from layout import Ui_window
class StartQT4(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_window()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.listWidget, QtCore.SIGNAL("dropped"), self.picture_dropped)
def picture_dropped(self, l):
for url in l:
if os.path.exists(url):
picture = Image.open(url)
picture.thumbnail((72, 72), Image.ANTIALIAS)
icon = QIcon(QPixmap.fromImage(ImageQt.ImageQt(picture)))
item = QListWidgetItem(os.path.basename(url)[:20] + "...", self.pictureListWidget)
item.setStatusTip(url)
item.setIcon(icon)
class DragDropListWidget(QListWidget):
def __init__(self, type, parent = None):
super(DragDropListWidget, self).__init__(parent)
self.setAcceptDrops(True)
self.setIconSize(QSize(72, 72))
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(Qt.CopyAction)
event.accept()
l = []
for url in event.mimeData().urls():
l.append(str(url.toLocalFile()))
self.emit(SIGNAL("dropped"), l)
else:
event.ignore()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())
And the UI file...
# Form implementation generated from reading ui file 'layout.ui'
#
# Created: Thu Nov 11 00:22:52 2010
# by: PyQt4 UI code generator 4.8.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_window(object):
def setupUi(self, window):
window.setObjectName(_fromUtf8("window"))
window.resize(543, 402)
window.setAcceptDrops(True)
self.centralwidget = QtGui.QWidget(window)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.listWidget = QtGui.QListWidget(self.centralwidget)
self.listWidget.setProperty(_fromUtf8("cursor"), QtCore.Qt.SizeHorCursor)
self.listWidget.setAcceptDrops(True)
self.listWidget.setObjectName(_fromUtf8("listWidget"))
self.verticalLayout.addWidget(self.listWidget)
window.setCentralWidget(self.centralwidget)
self.retranslateUi(window)
QtCore.QMetaObject.connectSlotsByName(window)
def retranslateUi(self, window):
window.setWindowTitle(QtGui.QApplication.translate("window", "PyNamer OCR", None, QtGui.QApplication.UnicodeUTF8))
Thanks to anybody who can help!
The code you're using as an example seem to work fine and looks quite clean. According to your comment your list widget is not getting initialized; this should be the root cause of your issue. I've simplified your code a bit a tried it on my Ubuntu 10.04LTS and it worked fine. My code is listed below, see if it would for you also. You should be able to drag and drop a file into the list widget; once it's dropped a new item is added showing the image and image's file name.
import sys
import os
from PyQt4 import QtGui, QtCore
class TestListView(QtGui.QListWidget):
def __init__(self, type, parent=None):
super(TestListView, self).__init__(parent)
self.setAcceptDrops(True)
self.setIconSize(QtCore.QSize(72, 72))
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls:
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
links.append(str(url.toLocalFile()))
self.emit(QtCore.SIGNAL("dropped"), links)
else:
event.ignore()
class MainForm(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainForm, self).__init__(parent)
self.view = TestListView(self)
self.connect(self.view, QtCore.SIGNAL("dropped"), self.pictureDropped)
self.setCentralWidget(self.view)
def pictureDropped(self, l):
for url in l:
if os.path.exists(url):
print(url)
icon = QtGui.QIcon(url)
pixmap = icon.pixmap(72, 72)
icon = QtGui.QIcon(pixmap)
item = QtGui.QListWidgetItem(url, self.view)
item.setIcon(icon)
item.setStatusTip(url)
def main():
app = QtGui.QApplication(sys.argv)
form = MainForm()
form.show()
app.exec_()
if __name__ == '__main__':
main()
hope this helps, regards