Monday, 15 July 2013

python - PyQt program randomly not responding without a Traceback -


I wrote the batch to change the file name of several pictures, using PyQt5.

This, it runs successfully through some pictures, and randomly crash without a dragon traceback, shows that "has stopped working" in Windows 8.1. Even if I use the same testcoses, the program sometimes crashes after 20+ images, sometimes sometimes only 2, sometimes goes to the end.

I do not even know which line the program crashed. How do I solve this problem?

Here's the program, I've still worked, which has reduced the code, and randomly crash as before.

  # - * - coding: utf -8 - * - PyQt5 import the QT sys import os import does it again, then __name__ == '__main__': application_Variable = Qt.QApplication ( Syskargv) filename import Ui_FileName_Widget class filename_class MainWindow import Ui_MainWindow_Widget: # only way to get a class, file name, def __init __ (self, Puarnpth) Add: self.re_path_temp = re.match (r. " + / ", Full path) self.path = self.re_path_temp.group (0) self.name = fullpath [lane (self.append = self.name [len (self.name [: self.name.rfind ('.' )] - lane (self. Name) +1:] class filename dfin_ widget (qtq.weedet): # Renaming widget def __init __ (name of self-file): Super (fileNameDefine_Widget, self) .__ init __ () self.fileWidget = Ui_FileName_Widget () self.fileWidget.setupUi (self) self.filename = filenam e self.file_append = Filename_class (self.filename) to get .append # to app.fileWidget.InputFileName_LineEdit.textChanged.connect (self.input_file_name_Change) def input_file_name_Change (auto): self.export_name = self.fileWidget.InputFileName_LineEdit.text () + " . "+ Self.file_append self.fileWidget.ExportFileName_LineEdit.setText (self.export_name) self.fileWidget.InputFileName_LineEdit.setEnabled (True) class MainWindow_Class (Qt.QWidget): # Main widget def __init __ (self): super (MainWindow_Class, Self) .__ init (__ () self.main = Ui_MainWindow_Widget () #init self.main.setupUi (Self) self.root_directory = r 'D: \ TLCTest "self.file_list = Qt.QFileDialog.getOpenFileNames (caption =" Select File "directory = Self.root_directory) [0] self.count = 0 # calculated went file self.show () is self-processing () Selfkinitiate_change_filename () Def Start_change_filename (self): file = Selfkfile_list [Selfkcount] Show # picture self.pixmap = Qt.QPixmap () self. pixmap.load (file) self.graphicsPixmapItem = Qt.QGraphicsPixmapItem (self.pixmap) self.graphicsScene = Qt.QGraphicsScene () self.graphicsScene.addItem (self.graphicsPi XmapItem) self.main.graphicsView.setScene (self.graphicsScene) # Rename widgets self.fileName_Widget = filenameDefin_ widget (file) self.fileName_Widget.fileWidget.InputFileName_LineEdit.return.press.con nect (self.submit) # Enter to submit themselves to FileName_Widgetkshow () Presents Def (self): filename = name self.fileName_Widget.filename path = Filename_class (file) .path final_name = self.fileName_Widget. FileWidgetkExportFileName_LineEditktext () Oskrename (filename, path + final_name) Self .count + = 1 if self.count == len (self.file_list): exit () and: self.fileName_Widget.close () Self.initiate_change_filename () if __name__ == '__main__': my_Qt_Program = MainWindow_Class () my_Qt_Program Show () sys.exit (application_Variable.exec_ ())  

Comment of the Akhumoro as a result, the

  def begin _change_filename (self): self.fileName_Widget = fileNameDefine_Widget (file)  

in instead, should one make this object, and init it is necessary every time, like:

  class TLC_processor_Class (Qt.QWidget): def init (self): # Blabla self.fileName_Widget = fileNameDefine_Widget (file) start def _change_filename (self): self.fileName_Widget .__ init __ (file)  

No comments:

Post a Comment