I have created a modelEditor in Maya using PyQt4 and code from internet, but I don't know how to close it when I run this script again. I've tried using sys.exit(app.exec_()) but that doesn't work.
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
import sys
global app
class MyDialog(QtGui.QDialog):
def __init__(self, parent, **kwargs):
super(MyDialog, self).__init__(parent, **kwargs)
self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setObjectName("mainLayout")
layout = mui.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
cmds.setParent(layout)
self._cameraName = cmds.camera()[0]
self.newEditor = cmds.modelEditor()
nodeName = cmds.modelEditor(self.newEditor,cam=self._cameraName,edit = True,hud = 0,alo = 0,pm = 1,da = "smoothShaded")
ptr = mui.MQtUtil.findControl(nodeName)
self.modelPanel = sip.wrapinstance(long(ptr), QtCore.QObject)
self.verticalLayout.addWidget(self.modelPanel)
def show(self):
super(MyDialog, self).show()
self.modelPanel.repaint()
def show():
if (cmds.window(MyDialog,ex = True)):
cmds.deleteUI(MyDialog)
global app
app = QtGui.QApplication.instance()
ptr = mui.MQtUtil.mainWindow()
win = sip.wrapinstance(long(ptr), QtCore.QObject)
d = MyDialog(win)
d.show()
Here's one way you can go about it.
Have a class singleton that will hold the class's instance. Then in the constructor you can check if an instance exists; if it does, then delete it and reset the variable.
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
import sys
global app
class MyDialog(QtGui.QDialog):
instance = None # This will contain an instance of this class.
def __init__(self, parent, **kwargs):
# Delete any existing instance, then set this as the current instance.
self.delete_instance()
self.__class__.instance = self
super(MyDialog, self).__init__(parent, **kwargs)
self.setObjectName("MyWindow")
self.resize(800, 600)
self.setWindowTitle("PyQt ModelPanel Test")
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setObjectName("mainLayout")
layout = mui.MQtUtil.fullName(long(sip.unwrapinstance(self.verticalLayout)))
cmds.setParent(layout)
self._cameraName = cmds.camera()[0]
self.newEditor = cmds.modelEditor()
nodeName = cmds.modelEditor(self.newEditor,cam=self._cameraName,edit = True,hud = 0,alo = 0,pm = 1,da = "smoothShaded")
ptr = mui.MQtUtil.findControl(nodeName)
self.modelPanel = sip.wrapinstance(long(ptr), QtCore.QObject)
self.verticalLayout.addWidget(self.modelPanel)
def delete_instance(self):
if self.__class__.instance is not None:
try:
self.__class__.instance.deleteLater()
except Exception as e:
pass
def show(self):
super(MyDialog, self).show()
self.modelPanel.repaint()
def show():
global app
app = QtGui.QApplication.instance()
ptr = mui.MQtUtil.mainWindow()
win = sip.wrapinstance(long(ptr), QtCore.QObject)
d = MyDialog(win)
d.show()
Do note that if you have an instance open and reload() the module, it won't delete the opened instance because the class will be different!
Related
when clicking a button in the PyQt5 Ui iam starting a mitmproxy. When the proxy is started, i try to change a listWidget with Data from the Proxy.
main.py
import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
from MainWindow import Ui_MainWindow
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setupUi(self)
self.pushButton.clicked.connect(self.Start)
def Start(self):
x = threading.Thread(target=self.StartMITM)
x.start()
def StartMITM(self):
os.system("mitmweb -s mitmproxy.py -q --no-web-open-browser")
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MainWindow()
win.show()
sys.exit(app.exec_())
mitmproxy.py - this is the error part
from mitmproxy import http
from main import MainWindow
def response(flow):
MainWindow.listWidget.addItem(flow.request.pretty_url)
Can I connect to the Widgets from another File?
It has 2 independent processes: The GUI and the mitmproxy script. And communicating both processes does not imply importing modules since you would be creating another widget, also objects should not be accessed through classes (I recommend you check your basic python notes).
In this the solution is to use some Inter process communication (IPC), in this case you can use Qt Remote Objects (QtRO):
main.py
from functools import cached_property
from PyQt5 import QtCore, QtRemoteObjects, QtWidgets
class Bridge(QtCore.QObject):
messageChanged = QtCore.pyqtSignal(str)
#QtCore.pyqtSlot(str)
def add_message(self, message):
self.messageChanged.emit(message)
class MitmwebManager(QtCore.QObject):
logChanged = QtCore.pyqtSignal(str)
def __init__(self, parent=None):
super().__init__(parent)
# self.process.setProcessChannelMode(QtCore.QProcess.MergedChannels)
self.process.readyReadStandardOutput.connect(self.handle_log)
self.process.setProgram("mitmweb")
#cached_property
def process(self):
return QtCore.QProcess()
def start(self, arguments):
self.process.setArguments(arguments)
self.process.start()
def stop(self):
self.process.kill()
def handle_log(self):
data = self.process.readAllStandardOutput()
codec = QtCore.QTextCodec.codecForName("UTF-8")
message = codec.toUnicode(data)
self.logChanged.emit(message)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.button = QtWidgets.QPushButton("Start", checkable=True)
self.listwidget = QtWidgets.QListWidget()
self.logview = QtWidgets.QPlainTextEdit(readOnly=True)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
lay = QtWidgets.QGridLayout(central_widget)
lay.addWidget(self.button, 0, 0, 1, 2)
lay.addWidget(self.listwidget, 1, 0)
lay.addWidget(self.logview, 1, 1)
self.register_node = QtRemoteObjects.QRemoteObjectRegistryHost(
QtCore.QUrl("local:registry")
)
self.source_node = QtRemoteObjects.QRemoteObjectHost(
QtCore.QUrl("local:replica"), QtCore.QUrl("local:registry")
)
self.source_node.enableRemoting(self.bridge, "bridge")
self.button.toggled.connect(self.handle_toggled)
self.mitmweb.logChanged.connect(self.handle_log_changed)
self.bridge.messageChanged.connect(self.handle_message_changed)
self.resize(640, 480)
#cached_property
def mitmweb(self):
return MitmwebManager()
#cached_property
def bridge(self):
return Bridge()
def handle_toggled(self, checked):
if checked:
self.mitmweb.start(["-s", "script.py", "--no-web-open-browser"])
self.button.setText("Stop")
else:
self.mitmweb.stop()
self.button.setText("Start")
def handle_log_changed(self, message):
self.logview.insertPlainText(message)
def closeEvent(self, event):
super().closeEvent(event)
self.mitmweb.stop()
def handle_message_changed(self, message):
item = QtWidgets.QListWidgetItem(message)
self.listwidget.addItem(item)
def main():
app = QtWidgets.QApplication([])
view = MainWindow()
view.show()
app.exec_()
if __name__ == "__main__":
main()
script.py
from mitmproxy import http
from PyQt5 import QtCore, QtRemoteObjects
class Bridge(QtCore.QObject):
def __init__(self, bridge, parent=None):
super().__init__(parent)
self._message = ""
self._bridge = bridge
self.bridge.initialized.connect(self.handle_initialized)
#property
def bridge(self):
return self._bridge
#property
def message(self):
return self._message
def send_message(self, message):
self._message = message
#QtCore.pyqtSlot()
def handle_initialized(self):
self.bridge.add_message(self._message)
QtCore.QTimer.singleShot(0, QtCore.QCoreApplication.quit)
def send_qt(message):
qt_app = QtCore.QCoreApplication([])
replica_node = QtRemoteObjects.QRemoteObjectNode(QtCore.QUrl("local:registry"))
replica_bridge = replica_node.acquireDynamic("bridge")
bridge = Bridge(replica_bridge)
bridge.send_message(message)
qt_app.exec_()
def response(flow):
send_qt(flow.request.pretty_url)
I am stack trying to include MenuBar from separate file and trying to connect with function
I include some code that I have the same problem
foo.py
from PyQt5.QtWidgets import *
from PyQt5.uic import loadUiType
import os
import sys
from foomenu import menu
FROM_MAIN, _ = loadUiType(os.path.join(os.path.dirname(__file__), "SalesGui.ui"))
class Main(QMainWindow, FROM_MAIN):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.MyMenu = menu(self)
self.MyMenu.NewProduct.triggered.connect(self.NewProduct())
def NewProduct(self):
print("foo")
def main():
app = QApplication(sys.argv)
window = Main()
window.show()
app.exec_()
if __name__ == '__main__':
try:
main()
except Exception as why:
print(why)
and foomenu.py
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction, QMenu
def menu(self):
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('FooMenu')
NewProduct = QAction(QIcon('icons/exit.png'), 'Foo', self)
NewProduct.setShortcut('Ctrl+Q')
NewProduct.setStatusTip('FooAction')
fileMenu.addAction(NewProduct)
When Trying to connect the "NewProduct" button with "New Product" function I get the following error
'NoneType' object has no attribute 'NewProduct'
Try it:
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction, QMenu
#from PyQt5.uic import loadUiType
#from foomenu import menu
#FROM_MAIN, _ = loadUiType(os.path.join(os.path.dirname(__file__), "SalesGui.ui"))
def menu(self):
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('FooMenu')
self.NewProduct = QAction(QIcon('exit.png'), 'Foo', self) # 'icons/exit.png' # + self
self.NewProduct.setShortcut('Ctrl+Q')
self.NewProduct.setStatusTip('FooAction')
fileMenu.addAction(self.NewProduct)
return self.NewProduct # +++
class Main(QMainWindow):#, FROM_MAIN):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
# self.setupUi(self)
self.MyMenu = menu(self)
# self.MyMenu.NewProduct.triggered.connect(self.funcNewProduct) # - ()
self.MyMenu.triggered.connect(self.funcNewProduct) # +
def funcNewProduct(self):
print("foo")
qApp.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Main()
window.show()
app.exec_()
It is much more elegant to subclass and setup the menubar in this another python file then import and instance this class in your file that holds the Main class.
In the MyMenu class you can binding the signal a socket locally that can provide from here the sender object for the parent class.
BTW you can iterate over the action object of the menubar/menus but it is much more harder to maintain and control then the explicit describe where to connect the potential different actions.
Menu.py:
class MyMenu(QMenuBar):
new_product_clicked = Signal(object)
def __init__(self, parent=None):
super(MyMenu, self).__init__(parent)
file_menu = QMenu("File menu", self)
new_product_action = QAction('Foo', self)
new_product_action.setShortcut('Ctrl+Q')
new_product_action.setStatusTip('FooAction')
new_product_action.triggered.connect(self.new_product_clicked)
file_menu.addAction(new_product_action)
self.addMenu(file_menu)
def new_product_clicked(self):
""" Call a method from the parent class. """
self.new_product_clicked.emit(self.sender())
Main.py:
from Menu import MyMenu
class Main(QMainWindow):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
my_menu = MyMenu(self)
self.setMenuBar(my_menu)
self.my_menu.new_product_clicked.connect(self.product_clicked)
def product_clicked(self, action):
""" Socket for the clicked action """
clicked_action = action
print clicked_action.text()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Main()
window.show()
app.exec_()
I want to access a list created on my main window based on user selection, on my second window.
the list was created in MainWindow under the on_cc_pick method. List creditcards.
on the second window, I would like to access it on CreditCardForm
When i try.MainWindow.creditcards or MainWindow.creditcardsb it tells me object has no attribute creditcards/b.
When I try doing a global variable under MainWindow Class:
class MainWindow(QtWidgets.QWidget):
creditcards = []
it always defaults to an empty list.
here is my code, in essence I want to access the list called creditcardsb created on class MainWindow under def on_cc_pick(self,text): on class CreditCardForm under def savecsv(self):
class AddCreditCard(QtWidgets.QMainWindow):
def __init__(self, parent = None):
super(AddCreditCard, self).__init__(parent)
creditcardform = CreditCardForm(self)
self.setCentralWidget(creditcardform)
class CreditCardForm(QtWidgets.QWidget):
def savecsv(self):
**print(MainWindow.creditcardsb)**
def __init__(self, parent):
super(CreditCardForm, self).__init__(parent)
self.addname = QtWidgets.QPushButton('Save')
self.connect(self.addname,QtCore.SIGNAL("clicked()"), self.savecsv)
class MainWindow(QtWidgets.QWidget):
def CreateCCForm(self):
self.addwindow.show()
def on_cc_pick(self, text):
NickName = []
Account = []
with open(refdirectory + '/' + str(text) + '.csv') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
NickName.append(row[0])
Account.append(row[1])
**creditcardsb = list(zip(NickName,Account))
self.creditcards = creditcardsb**
def __init__(self, parent = None):
super(MainWindow,self).__init__(parent)
self.pickcard = QtWidgets.QComboBox(self)
CreditCardNames = ['cc1','cc2','cc3']
for cc in CreditCardNames:
self.pickcard.addItem(cc)
self.addcard = QtWidgets.QPushButton('Add Card')
self.pickcard.activated[str].connect(self.on_cc_pick)
self.connect(self.addcard, QtCore.SIGNAL("clicked()"),self.CreateCCForm)
self.addwindow = AddCreditCard(self)
These are the imports I am using, not all relatable to my issue:
from subprocess import Popen
from selenium import webdriver
from bs4 import BeautifulSoup
import string
import time
import random
import csv
import pandas as pd
from pick import pick
import requests
import re
import urllib.request
from urllib.request import urlopen
from selenium.webdriver.common.by import By
from tkinter import *
import tkinter as tk
import tkinter.filedialog as filedialog
import os
import pyodbc
from decimal import *
import sys
from PySide2 import QtCore, QtGui, QtWidgets
from datetime import datetime, date
from decimal import Decimal
Do not use static variables since the property you want to transmit depends not on the class but on the objects. So the correct thing is to create a method that updates the data of the window. In addition, assuming that CreditCardForm will always be a child of AddCreditCard, you can obtain AddCreditCard using parentWidget() from CreditCardForm.
import os
import csv
from PySide2 import QtCore, QtWidgets
class AddCreditCard(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(AddCreditCard, self).__init__(parent)
creditcardform = CreditCardForm()
self.setCentralWidget(creditcardform)
self._creditcards = []
def setCreditcards(self, creditcards):
self._creditcards = creditcards
def creditcards(self):
return self._creditcards
class CreditCardForm(QtWidgets.QWidget):
def __init__(self, parent=None):
super(CreditCardForm, self).__init__(parent)
self.addname = QtWidgets.QPushButton('Save')
self.addname.clicked.connect(self.savecsv)
lay = QtWidgets.QHBoxLayout(self)
lay.addWidget(self.addname)
#QtCore.Slot()
def savecsv(self):
creditcards = self.parentWidget().creditcards()
print(creditcards)
class MainWindow(QtWidgets.QWidget):
def __init__(self, parent = None):
super(MainWindow,self).__init__(parent)
self.addwindow = AddCreditCard(self)
self.pickcard = QtWidgets.QComboBox()
self.pickcard.activated[str].connect(self.on_cc_pick)
creditcardnames = ['cc1','cc2','cc3']
self.pickcard.addItems(creditcardnames)
self.addcard = QtWidgets.QPushButton('Add Card')
self.addcard.clicked.connect(self.addwindow.show)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.addcard)
lay.addWidget(self.pickcard)
#QtCore.Slot(str)
def on_cc_pick(self, text):
creditcards = []
refdirectory = ""
filename = os.path.join(refdirectory, "{}.csv".format(text))
with open(filename) as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
creditcards.append((row[0], row[1]))
self.addwindow.setCreditcards(creditcards)
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
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'am a beginner with PyQt. All is in the title :I don't understand how can I get the path (and the name) from the selected file?
I wish later update a QListView with this path.
Here my script :
# -*- coding: utf-8 -*-
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import sys
class MyWidget(QWidget):
# SIGNAUX
tree_model_indexSig = pyqtSignal(QModelIndex)
def __init__(self, parent=None):
super(MyWidget, self).__init__(parent)
# connect signaux to slots
self.tree_model_indexSig.connect(self.indexSlot)
self.model = QFileSystemModel()
self.model.setRootPath(QDir.rootPath())
''' GUI '''
# instantiation du treeview et du listview
self.treeView = QTreeView(self)
self.treeView.setGeometry(QRect(10, 20, 601, 231))
self.treeView.setObjectName("treeView")
''' END GUI '''
self.treeView.setModel(self.model)
self.treeView.setRootIndex(self.model.index(QDir.rootPath()))
# clicked.CONNECT
self.treeView.clicked.connect(self.treeClicked)
self.treeView.show()
def treeClicked(self, checked=False):
# EMIT
self.tree_model_indexSig.emit(self.model.index(QDir.rootPath()))
# Definition des slots
def indexSlot(self, *args):
# 1 argument --> ModelIndex
path = QDirModel(args[0]).filePath(args[0].currentIndex())
print path
'''
How get the path from the selected file ??
'''
if __name__=='__main__':
app = QApplication(sys.argv)
widget = MyWidget()
widget.show()
app.exec_()
Thanks for help!
Something like this should work for you:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
class MyWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.pathRoot = QtCore.QDir.rootPath()
self.model = QtGui.QFileSystemModel(self)
self.model.setRootPath(self.pathRoot)
self.indexRoot = self.model.index(self.model.rootPath())
self.treeView = QtGui.QTreeView(self)
self.treeView.setModel(self.model)
self.treeView.setRootIndex(self.indexRoot)
self.treeView.clicked.connect(self.on_treeView_clicked)
self.labelFileName = QtGui.QLabel(self)
self.labelFileName.setText("File Name:")
self.lineEditFileName = QtGui.QLineEdit(self)
self.labelFilePath = QtGui.QLabel(self)
self.labelFilePath.setText("File Path:")
self.lineEditFilePath = QtGui.QLineEdit(self)
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.addWidget(self.labelFileName, 0, 0)
self.gridLayout.addWidget(self.lineEditFileName, 0, 1)
self.gridLayout.addWidget(self.labelFilePath, 1, 0)
self.gridLayout.addWidget(self.lineEditFilePath, 1, 1)
self.layout = QtGui.QVBoxLayout(self)
self.layout.addLayout(self.gridLayout)
self.layout.addWidget(self.treeView)
#QtCore.pyqtSlot(QtCore.QModelIndex)
def on_treeView_clicked(self, index):
indexItem = self.model.index(index.row(), 0, index.parent())
fileName = self.model.fileName(indexItem)
filePath = self.model.filePath(indexItem)
self.lineEditFileName.setText(fileName)
self.lineEditFilePath.setText(filePath)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('MyWindow')
main = MyWindow()
main.resize(666, 333)
main.move(app.desktop().screen().rect().center() - main.rect().center())
main.show()
sys.exit(app.exec_())