I am trying to make a simple files app (or, file explorer app) and I am using the QTableWidget to Display the files and directories. When the user clicks an directory, I want the program to jump to that directory. I have used the QTableWidget.cellClicked signal, and it does not currently work.
The signal part:
self.filesTable.connect(print)#self.updateUiCellClick)
Added print instead of self.updateUiCellClick for debugging purposes.
Code (probably you do not need this):
#!/usr/bin/python3
print('i Import Modules')
print(' | Import sys')
import sys
print(' | Import PyQt5.QtCore')
from PyQt5.QtCore import *
print(' | Import PyQt5.QtGui')
from PyQt5.QtGui import *
print(' | Import PyQt5.QtWidgets')
from PyQt5.QtWidgets import * # PyQt5 Support
print(' | Import os')
import os
print(' | Import subprocess.Popen') # For backward-compatibility
from subprocess import Popen, PIPE
print(' | Done')
print('i Define class Form')
class root(QMainWindow):
def __init__(self, parent=None):
'''self.__init__ - Initializes QMainWindow'''
print(' self.__init__ - Initializes QMainWindow')
super(root, self).__init__(parent)
# Create Variables
self.currentPath = '/'
os.chdir(self.currentPath)
self.currentItems = os.listdir()
self.currentItemsLsProcess = Popen(['ls','-l'], stdout=PIPE, stderr=PIPE)
self.currentItemsLsProcessResult = self.currentItemsLsProcess.communicate()
if self.currentItemsLsProcessResult[1].decode('utf-8'):
QMessageBox.warning(self,'Files - ls -l Error','ls -l responded with non-blank stderr.Error is shown here:<br><code>{}</code><br><hr><br>Error LsStderr (e-lsstderr)<br><hr><br>If you want to support the team, go to the GitHub Repository.'.format(self.currentItemsLsProcessResult[1].decode('utf-8')))
self.currentItemsLs = self.currentItemsLsProcessResult[0].decode('utf-8').split('\n')[1:-1]
# Create Table Widget
self.filesTable = QTableWidget()
# Init Table Widget
self.filesTable.clear()
self.filesTable.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
self.filesTable.setRowCount(len(self.currentItems))
self.filesTable.setColumnCount(4)
self.filesTable.setHorizontalHeaderLabels(['Name','TimeStamp','Type','ls -l'])
# self.filesTable.setReadOnly(1)
# Create & Add Items
self.itemWidgets = [[],[],[],[]]
for i in range(len(self.currentItems)):
self.itemWidgets[0].append(QTableWidgetItem(self.currentItems[i]))
self.filesTable.setItem(i,0,self.itemWidgets[0][-1])
self.itemWidgets[3].append(QTableWidgetItem(self.currentItemsLs[i]))
self.filesTable.setItem(i,3,self.itemWidgets[3][-1])
# Init Widgets
# Align Widgets to root
self.setCentralWidget(self.filesTable)
# Signals-and-Slots
print('i Set self title')
self.setWindowTitle('{}'.format(self.currentPath))
def updateUi(self):
'''self.updateUi - None'''
os.chdir(self.currentPath)
self.currentItems = os.listdir()
self.currentItemsLsProcess = Popen(['ls','-l'], stdout=PIPE, stderr=PIPE)
self.currentItemsLsProcessResult = self.currentItemsLsProcess.communicate()
if self.currentItemsLsProcessResult[1].decode('utf-8'):
QMessageBox.warning(self,'Files - ls -l Error','ls -l responded with non-blank stderr.Error is shown here:<br><code>{}</code><br><hr><br>Error LsStderr (e-lsstderr)<br><hr><br>If you want to support the team, go to the GitHub Repository.'.format(self.currentItemsLsProcessResult[1].decode('utf-8')))
self.currentItemsLs = self.currentItemsLsProcessResult[0].decode('utf-8').split('\n')[1:-1]
self.filesTable.clear()
self.filesTable.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustToContents)
self.filesTable.setRowCount(len(self.currentItems))
self.filesTable.setColumnCount(4)
self.filesTable.setHorizontalHeaderLabels(['Name','TimeStamp','Type','ls -l'])
self.itemWidgets = [[],[],[],[]]
for i in range(len(self.currentItems)):
self.itemWidgets[0].append(QTableWidgetItem(self.currentItems[i]))
self.filesTable.setItem(i,0,self.itemWidgets[0][-1])
self.filesTable..connect(print)#self.updateUiCellClick)
self.itemWidgets[3].append(QTableWidgetItem(self.currentItemsLs[i]))
self.filesTable.setItem(i,3,self.itemWidgets[3][-1])
self.filesTable.resizeColumnsToContents()
self.setWindowTitle('{}'.format(self.currentPath))
def updateUiCellClick(self, row, column):
'''self.updateUiCellClick - None'''
print('self.updateUiCellClick - None')
self.currentpath += self.itemWidgets[0][row].text+'/'
self.updateUi()
print(' | Done')
if __name__ == '__main__':
print('i Execute instance')
app = QApplication(sys.argv)
root = root()
root.show()
app.exec_()
print(' | Done')
The connection should be as follows
self.filesTable.cellClicked.connect(self.updateUiCellClick)
^^^^^^^^^^^
signal
In addition to this it is not necessary to create the connection every time you fill in the table, it is enough when you create it.
If you look at code you see that many parts are repeating, which is not necessary, I take the boldness to make improvements to your code as the verification of path and reduce the code.
import sys
import os
from subprocess import Popen, PIPE
from PyQt5.QtWidgets import *
class Root(QMainWindow):
def __init__(self, parent=None):
print(' self.__init__ - Initializes QMainWindow')
QMainWindow.__init__(self, parent)
# Create Table Widget
self.filesTable = QTableWidget()
self.filesTable.cellClicked.connect(self.updateUiCellClick)
# Init Table Widget
self.filesTable.clear()
self.filesTable.setSizeAdjustPolicy(QTableWidget.AdjustToContents)
self.filesTable.setColumnCount(4)
self.filesTable.setHorizontalHeaderLabels(['Name', 'TimeStamp', 'Type', 'ls -l'])
# Init Widgets
self.setCentralWidget(self.filesTable)
self.populate_table("/")
def populate_table(self, path):
# Verify that it is a directory.
if not os.path.isdir(path):
return
os.chdir(path)
current_items = os.listdir()
currentItemsLsProcess = Popen(['ls', '-l'], stdout=PIPE, stderr=PIPE)
currentItemsLsProcessResult = currentItemsLsProcess.communicate()
if currentItemsLsProcessResult[1].decode('utf-8'):
QMessageBox.warning(self, 'Files - ls -l Error',
'ls -l responded with non-blank stderr.Error is shown here:'
'<br><code>{}</code><br><hr><br>Error LsStderr (e-lsstderr)<br>'
'<hr><br>If you want to support the team, go to the '
'GitHub Repository.'.format(
currentItemsLsProcessResult[1].decode('utf-8')))
return
self.filesTable.clear()
currentItemsLs = currentItemsLsProcessResult[0].decode('utf-8').split('\n')[1:-1]
self.filesTable.setRowCount(len(current_items))
for i, values in enumerate(zip(current_items, currentItemsLs)):
name, ls = values
self.filesTable.setItem(i, 0, QTableWidgetItem(name))
self.filesTable.setItem(i, 3, QTableWidgetItem(ls))
self.setWindowTitle('{}'.format(path))
def updateUiCellClick(self, row, _):
path = os.path.join(os.getcwd(), self.filesTable.item(row, 0).text())
self.populate_table(path)
if __name__ == '__main__':
print('i Execute instance')
app = QApplication(sys.argv)
root = Root()
root.show()
status = app.exec_()
print(' | Done')
sys.exit(status)
Related
Hello I am trying to create a PyQt6 widget that animates over a set of images, but at a precise frame rate that varies as a function of realtime parameters. I insert QPixmaps into the cache within a for loop, and am able to find the QPixmap objects through QPixmap.find() within the same for loop, but outside the loop .find() returns None.
Below is the script. I can include the image series if needed. Appreciate any help.
import sys
from PyQt6.QtWidgets import (
QApplication,
QMainWindow,
QLabel
)
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QPixmap, QPixmapCache
from pathlib import Path
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.animating_label = QLabel('animation here')
self.animating_label.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter)
self.animating_label.pixmap().size().setWidth(200)
self.animating_label.pixmap().size().setHeight(200)
self.setCentralWidget(self.animating_label)
parent_path = Path(__file__).parent
self.images_path = parent_path / 'images/animation_set/'
self.animating_label.setPixmap(QPixmap(self.images_path.__str__() + "/clock01.png"))
self.pixmapcache_keys: [str] = []
self.load_images()
test = QPixmapCache.find("clock02")
try:
self.animating_label.setPixmap(test)
except:
if test == None:
print("Failure: QPixMapCache.find() returned", test)
def load_images(self):
image_suffixes = ['.jpg', '.png', '.gif', '.bmp']
imgs_found_count = 0
for filepath in self.images_path.iterdir():
if filepath.suffix in image_suffixes:
imgs_found_count += 1
cache_key = filepath.stem
self.pixmapcache_keys.append(cache_key)
if not QPixmapCache.find(cache_key):
pixmap = QPixmap(filepath.__str__())
QPixmapCache.insert(cache_key, pixmap)
print("pixmap %s" % cache_key, QPixmapCache.find(cache_key))
print(imgs_found_count, "image(s) found in animation_set directory.", len(self.pixmapcache_keys),
"keys loaded into QPixmapCache")
app = QApplication(sys.argv)
window = MainWindow()
window.show()
# start Qt event loop
app.exec()
print("Script complete.")
sys.exit(1)
Here is the output:
pixmap clock04 <PyQt6.QtGui.QPixmap object at 0x101c84b30>
pixmap clock10 <PyQt6.QtGui.QPixmap object at 0x101c84970>
pixmap clock11 <PyQt6.QtGui.QPixmap object at 0x101c84b30>
pixmap clock05 <PyQt6.QtGui.QPixmap object at 0x101c84970>
...
24 image(s) found in animation_set directory. 24 keys loaded into QPixmapCache
Failure: QPixMapCache.find() returned None
Script complete.
I was able to get the animation working using a list of QPixmaps instead of QPixmapCache, but I am not sure if this is the optimal approach.
Generating Qpixmap list from files:
for filepath in sorted(self.images_path.iterdir()):
if filepath.suffix in image_suffixes:
qpixmap = QPixmap(filepath.__str__())
self.pixmaps.append(qpixmap)
called elsewhere on a timer
def advance(self):
if self.pixmap_current_index >= len(self.pixmaps) - 1:
self.pixmap_current_index = 0
else:
self.pixmap_current_index += 1
self.animating_label.setPixmap(self.pixmaps[self.pixmap_current_index])
self.timer.start(self.refresh_interval)
I am trying to record and use data with a Qdial.
For the recording every thing seems to be fine, but in order to use this data in while loop I have to reload the while loop. When I do so with signal and a subprocess, the loop seems to use every data recorded, another problem is that the loop don’t stop at the end of the process.
I have no doubt I am using the wrong method.
Sorry for my bad English, and thank you very much for your help.
So I am using 3 scripts: Qdial.py, Data.py, Loop.py.
The Data.py is an accumulation of data, here I use just one:
A1 = 10
The Loop.py is in deed my main script, here I resume:
import time
from Data import *
def loop():
while True:
print('A1 = ', A1)
time.sleep(0.1)
loop()
[edit] Instead of this Loop.py I will not use from Data import *,
but this one witch don't raise errors (but there is always the problem of the continuous looping after the exit on Qdial.py):
import time
def loop():
with open('/address/Data.py', 'r') as file:
lines = file.readlines()
A1 = lines[0]
A1 = float(A1[4:-1])
print('A1 = ', A1)
while True:
loop()
time.sleep(0.09)
[/edit]
The Qdial.py is a common one, with the signal and a subprocess that raise false values:
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
from Data import *
import sys, signal, subprocess, time
[edit] This line is no longer needed, and cause an endless loop.
I launch Loop.py with a subprocess:
proc = subprocess.Popen(['python3', '/address/Loop.py'])
[/edit]
Then it’s the writing for the Qdial:
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(300, 300, 150, 150)
vbox = QVBoxLayout()
self.a1 = QDial(self)
self.value = int(A1)
self.a1.setValue(self.value)
self.value = self.a1.value()
self.lab1 = QtWidgets.QLabel(self)
self.lab1.setText('A1 = ' + str(A1) + 's')
self.a1.valueChanged.connect(self.dial)
vbox.addWidget(self.a1)
vbox.addWidget(self.lab1)
self.setLayout(vbox)
self.show()
def dial(self):
val1 = self.a1.value()
self.lab1.setText('A1 = ' + str(val1) + 's')
with open('/address/data.py', 'r') as file:
lines = file.readlines()
lines[0] = 'A1 = ' + str(val1) + '\n'
with open('/address/data.py', 'w') as file:
for line in lines:
file.write(line)
file.close()
[edit] Thoses lines are no longer define or needed.
Here I use signal and subprocess in order to reload the data in Loop.py:
proc.send_signal(signal.SIGINT)
subprocess.Popen(['python3', '/address/Loop.py'])
[/edit]
And I finish:
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())
[edit] A solution to escape the endless loop was to run both scripts (Qdial.py & Loop.py) as subprocess from a main script and use Popen.wait(), Main.py:
import subprocess, signal
Qd = subprocess.Popen(['python3', '/address/Qdial.py'])
Lo = subprocess.Popen(['python3', '/address/Loop.py'])
if Qd.wait() != None:
Lo.send_signal(signal.SIGINT)
[/edit]
Of course I don’t understand what is wrong, sorry for the length of this post...Thanks again.
I'm trying make an exe application from my scripts using py2exe. The problem is that if I run it by doubleclicking on exe file, it closes immediately after open. If I run it from cmd, it works perfect.
I've tried to make a table global but it did not helped. I've already tried to keep the reference - no effect.
Here is the code of GUI in case it helps:
from PyQt4.QtGui import QTableWidget, QTableWidgetItem,QApplication
import sys
from PyQt4.QtGui import *
import os
from meteo import mesiac,den
class MyTable(QTableWidget):
def __init__(self, data, *args):
QTableWidget.__init__(self, *args)
self.data = data
self.setmydata()
self.resizeColumnsToContents()
self.resizeRowsToContents()
def setmydata(self):
horHeaders = []
for n, key in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
'min tlak','avg teplota','avg vlhkost','avg tlak']):
horHeaders.append(key)
for m, item in enumerate(self.data[key]):
newitem = QTableWidgetItem(str(item))
self.setItem(m, n, newitem)
self.setHorizontalHeaderLabels(horHeaders)
vertical_headers = ['{}.'.format(x+1) for x in xrange(len(self.data.values()[0])-1)]+['Mesiac:']
self.setVerticalHeaderLabels(vertical_headers)
self.setWindowTitle('Meteo')
def show_table():
global table
table = MyTable(data, len(data.values()[0]), len(data.keys()))
table.setFixedHeight(len(data.values()[0])*20)
table.setFixedWidth(len(data.keys())*95)
table.show()
return table
if __name__ == '__main__':
data = {}
os.system("mode con: cols=100 lines=40")
filenames = next(os.walk('mesiac'))[2]
list_of_den = []
for filename in filenames:
list_of_den.append(den(filename,filename[:-4]))
m = mesiac(list_of_den)
for den in list_of_den:
for n,attr in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
'min tlak','avg teplota','avg vlhkost','avg tlak']):
try:
data[attr].append(den.to_list()[n])
except:
data[attr]=[den.to_list()[n]]
m_list = m.to_list()
for n,attr in enumerate(['max teplota','min teplota','max vlhkost','min vlhkost','max tlak',
'min tlak','avg teplota','avg vlhkost','avg tlak']):
try:
data[attr].append(m_list[n])
except:
data[attr]=[m_list[n]]
app = QApplication(sys.argv)
t = show_table()
sys.exit(app.exec_())
And for sure - here is a setup.py file:
from distutils.core import setup
import py2exe
options ={"py2exe":{"includes":["sip","PyQt4.QtGui","PyQt4.QtCore","meteo"],"dll_excludes": ["MSVCP90.dll", "HID.DLL", "w9xpopen.exe"]}}
setup(window=['table.py'],options=options)
How to make it visible?
I borrowed this code from another StackOverflow answer:
from PyQt4 import QtCore
#QtCore.pyqtSlot(str)
def directory_changed(path):
print('Directory Changed!!!')
#QtCore.pyqtSlot(str)
def file_changed(path):
print('File Changed!!!')
fs_watcher = QtCore.QFileSystemWatcher(['/path/to/files_1', '/path/to/files_2', '/path/to/files_3'])
fs_watcher.connect(fs_watcher, QtCore.SIGNAL('directoryChanged(QString)'), directory_changed)
fs_watcher.connect(fs_watcher, QtCore.SIGNAL('fileChanged(QString)'), file_changed)
The problem is, file_changed never gets called, no matter what. directory_changed is reliably called when a file is added, for example, but changing the files content does not result in file_changed being called.
I called a few variations of QtCore.SIGNAL('fileChanged(QString)'), eg, QtCore.SIGNAL('fileChanged(const QString &)'), to no avail. There are no warnings, or errors -- it simply does not trigger the function.
Recommendations?
It's hard to be certain what's going wrong, because the example code is incomplete, and so cannot work at all as it stands.
However, assuming the real code you are running is more or less sane/complete, your problem is probably caused by not adding the directory itself to the list of paths.
A basic script should look something like this:
import sys
from PyQt4 import QtCore
def directory_changed(path):
print('Directory Changed: %s' % path)
def file_changed(path):
print('File Changed: %s' % path)
app = QtCore.QCoreApplication(sys.argv)
paths = [
'/path/to',
'/path/to/files_1',
'/path/to/files_2',
'/path/to/files_3',
]
fs_watcher = QtCore.QFileSystemWatcher(paths)
fs_watcher.directoryChanged.connect(directory_changed)
fs_watcher.fileChanged.connect(file_changed)
sys.exit(app.exec_())
import argparse
import configparser
import os
import sys
from PyQt5 import QtCore
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QDesktopWidget, QMessageBox
from PyQt5.QtWidgets import QMainWindow
from ProgressBar_ui import Ui_Form
class ProgressBarWindow(QMainWindow, Ui_Form):
def __init__(self):
super().__init__()
self.ui = Ui_Form()
self.ui.setupUi(self)
self.ui.progressBar.setMinimum(0)
self.ui.progressBar.setMaximum(0)
self.ui.progressBar.setValue(0)
self.setWindowTitle("Progress Bar")
self.MSversion = ""
self.LOADING_LOG_PATH = ""
mainIco = ("Icons\myIcon.ico")
self.setWindowIcon(QIcon(mainIco))
self.ui.label.setText("")
self.ui.label.setWordWrap(True)
def location_on_the_screen(self):
ag = QDesktopWidget().availableGeometry()
sg = QDesktopWidget().screenGeometry()
widget = self.geometry()
x = ag.width() - widget.width()
y = 2 * ag.height() - sg.height() - widget.height()
self.move(x, y)
def file_changed(self, pathPassed):
if os.path.exists(pathPassed):
f = open(pathPassed, "r")
for x in f:
#print(x)
label =x
self.ui.label.setText(label)
if x == "CloseLoading":
self.close()
def main():
app = QApplication(sys.argv)
w = ProgressBarWindow()
w.setWindowFlags(w.windowFlags() & ~QtCore.Qt.WindowMaximizeButtonHint)
parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser(description='ProgressBar Arguments')
parser.add_argument('version', action="store", type=str)
args = vars(parser.parse_args())
if len(sys.argv) < 1:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
errorMsg = "There are less than 2 command line arguments provided.\nLauncher can not be run."
msg.setText(errorMsg)
msg.setWindowTitle("Save paths..")
msg.exec_()
sys.exit()
p= '/path/toFile/'
paths = [ p ]
fs_watcher = QtCore.QFileSystemWatcher(paths)
#fs_watcher.directoryChanged.connect(w.directory_changed)
fs_watcher.fileChanged.connect(w.file_changed)
w.location_on_the_screen()
w.show()
app.exec_()
if __name__ == "__main__":
sys.exit(main())
Im writing a PyQt app that takes some input in one widget, and then processes some text files.
What ive got at the moment is when the user clicks the "process" button a seperate window with a QTextEdit in it pops up, and ouputs some logging messages.
On Mac OS X this window is refreshed automatically and you cna see the process.
On Windows, the window reports (Not Responding) and then once all the proccessing is done, the log output is shown. Im assuming I need to refresh the window after each write into the log, and ive had a look around at using a timer. etc, but havnt had much luck in getting it working.
Below is the source code. It has two files, GUI.py which does all the GUI stuff and MOVtoMXF that does all the processing.
GUI.py
import os
import sys
import MOVtoMXF
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Form(QDialog):
def process(self):
path = str(self.pathBox.displayText())
if(path == ''):
QMessageBox.warning(self, "Empty Path", "You didnt fill something out.")
return
xmlFile = str(self.xmlFileBox.displayText())
if(xmlFile == ''):
QMessageBox.warning(self, "No XML file", "You didnt fill something.")
return
outFileName = str(self.outfileNameBox.displayText())
if(outFileName == ''):
QMessageBox.warning(self, "No Output File", "You didnt do something")
return
print path + " " + xmlFile + " " + outFileName
mov1 = MOVtoMXF.MOVtoMXF(path, xmlFile, outFileName, self.log)
self.log.show()
rc = mov1.ScanFile()
if( rc < 0):
print "something happened"
#self.done(0)
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.log = Log()
self.pathLabel = QLabel("P2 Path:")
self.pathBox = QLineEdit("")
self.pathBrowseB = QPushButton("Browse")
self.pathLayout = QHBoxLayout()
self.pathLayout.addStretch()
self.pathLayout.addWidget(self.pathLabel)
self.pathLayout.addWidget(self.pathBox)
self.pathLayout.addWidget(self.pathBrowseB)
self.xmlLabel = QLabel("FCP XML File:")
self.xmlFileBox = QLineEdit("")
self.xmlFileBrowseB = QPushButton("Browse")
self.xmlLayout = QHBoxLayout()
self.xmlLayout.addStretch()
self.xmlLayout.addWidget(self.xmlLabel)
self.xmlLayout.addWidget(self.xmlFileBox)
self.xmlLayout.addWidget(self.xmlFileBrowseB)
self.outFileLabel = QLabel("Save to:")
self.outfileNameBox = QLineEdit("")
self.outputFileBrowseB = QPushButton("Browse")
self.outputLayout = QHBoxLayout()
self.outputLayout.addStretch()
self.outputLayout.addWidget(self.outFileLabel)
self.outputLayout.addWidget(self.outfileNameBox)
self.outputLayout.addWidget(self.outputFileBrowseB)
self.exitButton = QPushButton("Exit")
self.processButton = QPushButton("Process")
self.buttonLayout = QHBoxLayout()
#self.buttonLayout.addStretch()
self.buttonLayout.addWidget(self.exitButton)
self.buttonLayout.addWidget(self.processButton)
self.layout = QVBoxLayout()
self.layout.addLayout(self.pathLayout)
self.layout.addLayout(self.xmlLayout)
self.layout.addLayout(self.outputLayout)
self.layout.addLayout(self.buttonLayout)
self.setLayout(self.layout)
self.pathBox.setFocus()
self.setWindowTitle("MOVtoMXF")
self.connect(self.processButton, SIGNAL("clicked()"), self.process)
self.connect(self.exitButton, SIGNAL("clicked()"), self, SLOT("reject()"))
self.ConnectButtons()
class Log(QTextEdit):
def __init__(self, parent=None):
super(Log, self).__init__(parent)
self.timer = QTimer()
self.connect(self.timer, SIGNAL("timeout()"), self.updateText())
self.timer.start(2000)
def updateText(self):
print "update Called"
AND MOVtoMXF.py
import os
import sys
import time
import string
import FileUtils
import shutil
import re
class MOVtoMXF:
#Class to do the MOVtoMXF stuff.
def __init__(self, path, xmlFile, outputFile, edit):
self.MXFdict = {}
self.MOVDict = {}
self.path = path
self.xmlFile = xmlFile
self.outputFile = outputFile
self.outputDirectory = outputFile.rsplit('/',1)
self.outputDirectory = self.outputDirectory[0]
sys.stdout = OutLog( edit, sys.stdout)
class OutLog():
def __init__(self, edit, out=None, color=None):
"""(edit, out=None, color=None) -> can write stdout, stderr to a
QTextEdit.
edit = QTextEdit
out = alternate stream ( can be the original sys.stdout )
color = alternate color (i.e. color stderr a different color)
"""
self.edit = edit
self.out = None
self.color = color
def write(self, m):
if self.color:
tc = self.edit.textColor()
self.edit.setTextColor(self.color)
#self.edit.moveCursor(QtGui.QTextCursor.End)
self.edit.insertPlainText( m )
if self.color:
self.edit.setTextColor(tc)
if self.out:
self.out.write(m)
self.edit.show()
If any other code is needed (i think this is all that is needed) then just let me know.
Any Help would be great.
Mark
It looks like your are running an external program, capturing its output into a QTextEdit. I didn't see the code of Form.process, but I am guessing on windows your function waits for the external program to finish, then quickly dumps everything to the QTextEdit.
If your interface really is waiting for the other process to finish, then it will hang in the manner you describe. You'll need to look at subprocess or perhaps even popen to get the program's output in a "non-blocking" manner.
The key to avoiding "(Not Responding)" is to call QApplication.processEvents a few times every few seconds. The QTimer is not going to help in this case, because if Qt cannot process its events, it cannot call any signal handlers.