diff options
author | Mark Sims <mark@nanorex.com> | 2008-06-05 17:34:16 +0000 |
---|---|---|
committer | Mark Sims <mark@nanorex.com> | 2008-06-05 17:34:16 +0000 |
commit | db52775f54e34ff35b9bd2d8c54f5f1f0f1f2b58 (patch) | |
tree | c2498d87b28a567aa3c7a4124ce75e367c28cc1a | |
parent | aa21f5a872ffa509159b9cfb0672b3cf99a99c99 (diff) | |
download | nanoengineer-theirix-db52775f54e34ff35b9bd2d8c54f5f1f0f1f2b58.tar.gz nanoengineer-theirix-db52775f54e34ff35b9bd2d8c54f5f1f0f1f2b58.zip |
Fixed bug 2886: cancel button to abort reading a huge file doesn't work
-rw-r--r-- | cad/src/dna/commands/BuildDuplex/DnaDuplex.py | 2 | ||||
-rwxr-xr-x | cad/src/dna/commands/BuildDuplex_old/DnaGenHelper.py | 2 | ||||
-rwxr-xr-x | cad/src/files/mmp/files_mmp.py | 70 | ||||
-rwxr-xr-x | cad/src/model/prefsTree.py | 2 | ||||
-rwxr-xr-x | cad/src/operations/ops_files.py | 31 | ||||
-rwxr-xr-x | cad/src/utilities/constants.py | 7 |
6 files changed, 87 insertions, 27 deletions
diff --git a/cad/src/dna/commands/BuildDuplex/DnaDuplex.py b/cad/src/dna/commands/BuildDuplex/DnaDuplex.py index e5a6e9a81..eff722153 100644 --- a/cad/src/dna/commands/BuildDuplex/DnaDuplex.py +++ b/cad/src/dna/commands/BuildDuplex/DnaDuplex.py @@ -1031,7 +1031,7 @@ class Dna: #directly use self.baseList instead? Only comments are added for #now. See also self.make()(the caller) try: - grouplist = readmmp(self.assy, filename, isInsert = True) + ok, grouplist = readmmp(self.assy, filename, isInsert = True) except IOError: raise PluginBug("Cannot read file: " + filename) if not grouplist: diff --git a/cad/src/dna/commands/BuildDuplex_old/DnaGenHelper.py b/cad/src/dna/commands/BuildDuplex_old/DnaGenHelper.py index 743cbd5a4..6afaffbde 100755 --- a/cad/src/dna/commands/BuildDuplex_old/DnaGenHelper.py +++ b/cad/src/dna/commands/BuildDuplex_old/DnaGenHelper.py @@ -136,7 +136,7 @@ class Dna: @type position: L{V} """ try: - grouplist = readmmp(assy, filename, isInsert = True) + ok, grouplist = readmmp(assy, filename, isInsert = True) except IOError: raise PluginBug("Cannot read file: " + filename) if not grouplist: diff --git a/cad/src/files/mmp/files_mmp.py b/cad/src/files/mmp/files_mmp.py index 34456d080..b2ea65514 100755 --- a/cad/src/files/mmp/files_mmp.py +++ b/cad/src/files/mmp/files_mmp.py @@ -58,6 +58,7 @@ from utilities.debug import print_compact_stack from utilities.constants import gensym from utilities.constants import interpret_dispName +from utilities.constants import SUCCESS, ABORTED, READ_ERROR from model.bond_constants import find_bond from model.bond_constants import V_SINGLE @@ -1479,6 +1480,7 @@ def readmmp_info( card, currents, interp ): #bruce 050217; revised 050421, 05051 return # == +_readmmp_aborted = False def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): """ @@ -1509,7 +1511,9 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): a file. Default is False. @type showProgressDialog: boolean - @return: the tuple (grouplist or None, listOfAtomsInFileOrder) + @return: the tuple (ok, grouplist or None, listOfAtomsInFileOrder), where + ok is "SUCCESS", "ABORTED", or "READ ERROR". + @rtype: (string, list, list) """ #bruce 050405 revised code & docstring #ericm 080409 revised return value to contain listOfAtomsInFileOrder @@ -1521,7 +1525,7 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): # within a ZIP file. To test, create a zipfile (i.e. "part.zip") which # contains an MMP file named "main.mmp", then rename "part.zip" to # "part.mmp". Set the constant READ_MAINMMP_FROM_ZIPFILE = True, - # then run NE1 and open "part.mpp" using "File > Open...". + # then run NE1 and open "part.mmp" using "File > Open...". # Mark 2008-02-03 READ_MAINMMP_FROM_ZIPFILE = False # Don't commit with True. @@ -1534,12 +1538,17 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): lines = _bytes.splitlines() else: # The normal way to read an MMP file. - lines = open(filename,"rU").readlines() - # 'U' in filemode is for universal newline support - - if not isInsert: - assy.filename = filename ###e would it be better to do this at the end, and not at all if we fail? + try: + lines = open(filename,"rU").readlines() + # 'U' in filemode is for universal newline support + except: + return READ_ERROR, None, [] + # Commented this out since the assy.filename should be (and is) set by + # another caller based on success. + #if not isInsert: + # assy.filename = filename ###e would it be better to do this at the end, and not at all if we fail? + # Create and display a Progress dialog while reading the MMP file. # One issue with this implem is that QProgressDialog always displays # a "Cancel" button, which is not hooked up. I think this is OK for now, @@ -1557,8 +1566,26 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): win.progressDialog.setRange(0, _progressFinishValue) _progressDialogDisplayed = False _timerStart = time.time() + + # Ask Bruce to review this approach. [mark 2008-06-05] + def abort_readmmp(): + """ + This slot is called when the user aborts opening a large + MMP file by pressing the "Cancel" button in the progress dialog. + """ + global _readmmp_aborted # Ask Bruce about this. + _readmmp_aborted = True + win.disconnect(win.progressDialog, SIGNAL("canceled()"), abort_readmmp) + return + + from PyQt4.Qt import SIGNAL + win.connect(win.progressDialog, SIGNAL("canceled()"), abort_readmmp) for card in lines: + if _readmmp_aborted: # User aborted while reading the MMP file. + global _readmmp_aborted + _readmmp_aborted = False # Reset global to False for next time. + return ABORTED, None, [] try: errmsg = state.readmmp_line( card) # None or an error message except: @@ -1607,7 +1634,7 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): break if len(grouplist) == 0: state.format_error("nothing in file") - return None, [] + return SUCCESS, None, [] elif len(grouplist) == 1: state.guess_sim_input('one_part') # note: 'one_part' gives same warning as 'missing_group_or_chunk' as of 050406 @@ -1632,7 +1659,7 @@ def _readmmp(assy, filename, isInsert = False, showProgressDialog = False): if showProgressDialog: # Make the progress dialog go away. win.progressDialog.setValue(_progressFinishValue) - return grouplist, listOfAtomsInFileOrder # from _readmmp + return SUCCESS, grouplist, listOfAtomsInFileOrder # from _readmmp def readmmp(assy, filename, @@ -1676,6 +1703,12 @@ def readmmp(assy, appeared. If False (the default), returns the group list. @type returnListOfAtoms: boolean + + @return: the tuple (ok, grouplist) where ok is + - "SUCCESS", + - "ABORTED", or + - "READ ERROR". + @rtype: (string, list) """ kluge_main_assy = env.mainwindow().assy # use this instead of assy to fix logic bug in use of assy_valid flag @@ -1686,10 +1719,10 @@ def readmmp(assy, kluge_main_assy.assy_valid = False # disable updaters during _readmmp # [bruce 080117/080124, revised 080319] try: - grouplist, listOfAtomsInFileOrder = _readmmp(assy, - filename, - isInsert, - showProgressDialog) + ok, grouplist, listOfAtomsInFileOrder = _readmmp(assy, + filename, + isInsert, + showProgressDialog) # warning: can show a dialog, which can cause paintGL calls. finally: kluge_main_assy.assy_valid = True @@ -1698,8 +1731,8 @@ def readmmp(assy, # note: handles grouplist is None (though not very well) # note: runs all updaters when done, and sets per-part viewdata if (returnListOfAtoms): - return listOfAtomsInFileOrder - return grouplist + return ok, listOfAtomsInFileOrder + return ok, grouplist def _reset_grouplist(assy, grouplist): """ @@ -1828,9 +1861,10 @@ def insertmmp(assy, filename): #bruce 050405 revised to fix one or more assembly try: #Fixes bug 2825 (_readmmp returns 2 vals so added 'listOfAtomsInFileOrder' #below. - grouplist, listOfAtomsInFileOrder = _readmmp(assy, - filename, - isInsert = True) + ok, grouplist, listOfAtomsInFileOrder = _readmmp(assy, + filename, + isInsert = True, + showProgressDialog = True) del listOfAtomsInFileOrder diff --git a/cad/src/model/prefsTree.py b/cad/src/model/prefsTree.py index 41d6f09b9..3e72bc717 100755 --- a/cad/src/model/prefsTree.py +++ b/cad/src/model/prefsTree.py @@ -202,7 +202,7 @@ def read_mmp_single_part(assy, filename): from utilities.constants import noop history.message = noop # don't bother user with this file being nonstd (bad, should pass a flag, so other errors seen) try: - grouplist = readmmp(assy, filename, isInsert = True) + ok, grouplist = readmmp(assy, filename, isInsert = True) finally: history.message = oldmessage if grouplist: diff --git a/cad/src/operations/ops_files.py b/cad/src/operations/ops_files.py index 32d5be0ac..30be96430 100755 --- a/cad/src/operations/ops_files.py +++ b/cad/src/operations/ops_files.py @@ -61,6 +61,8 @@ from utilities.prefs_constants import toolbar_state_prefs_key from utilities.debug_prefs import Choice_boolean_False from utilities.debug_prefs import debug_pref +from utilities.constants import SUCCESS, ABORTED, READ_ERROR + debug_babel = False # DO NOT COMMIT with True def set_waitcursor(on_or_off): @@ -735,12 +737,28 @@ class fileSlotsMixin: #bruce 050907 moved these methods out of class MWsemantics # This puts up the hourglass cursor while opening a file. QApplication.setOverrideCursor( QCursor(Qt.WaitCursor) ) + ok = SUCCESS + if fn[-3:] == "mmp": - listOfAtoms = readmmp(self.assy, fn, showProgressDialog = True, returnListOfAtoms = True) + ok, listOfAtoms = readmmp(self.assy, + fn, + showProgressDialog = True, + returnListOfAtoms = True) #bruce 050418 comment: we need to check for an error return # and in that case don't clear or have other side effects on assy; # this is not yet perfectly possible in readmmmp. - _openmsg = "MMP file opened: [ " + os.path.normpath(fn) + " ]" + #mark 2008-06-05 comment: I included an error return value + # for readmmp (ok) checked below. The code below needs to + # be cleaned up, but I need Bruce's help to do that. + if ok == SUCCESS: + _openmsg = "MMP file opened: [ " + os.path.normpath(fn) + " ]" + elif ok == ABORTED: + _openmsg = orangemsg("Open cancelled: [ " + os.path.normpath(fn) + " ]") + elif ok == READ_ERROR: + _openmsg = redmsg("Error reading: [ " + os.path.normpath(fn) + " ]") + else: + msg = "Unknown return value '%s'" % ok + print_compact_traceback(msg) isMMPFile = True if (gromacsCoordinateFile): newPositions = readGromacsCoordinates(gromacsCoordinateFile, listOfAtoms) @@ -749,10 +767,11 @@ class fileSlotsMixin: #bruce 050907 moved these methods out of class MWsemantics else: env.history.message(redmsg(newPositions)) - dir, fil, ext = _fileparse(fn) - # maybe: could replace some of following code with new method just now split out of saved_main_file [bruce 050907 comment] - self.assy.name = fil - self.assy.filename = fn + if ok == SUCCESS: + dir, fil, ext = _fileparse(fn) + # maybe: could replace some of following code with new method just now split out of saved_main_file [bruce 050907 comment] + self.assy.name = fil + self.assy.filename = fn self.assy.reset_changed() # The file and the part are now the same self.update_mainwindow_caption() diff --git a/cad/src/utilities/constants.py b/cad/src/utilities/constants.py index ebf47157b..863f2cdeb 100755 --- a/cad/src/utilities/constants.py +++ b/cad/src/utilities/constants.py @@ -458,6 +458,13 @@ BONDPOINT_REPLACED_WITH_HYDROGEN = "BONDPOINT_REPLACED_WITH_HYDROGEN" # == +# constants for readmmp +SUCCESS = 'SUCCESS' +ABORTED = 'ABORTED' +READ_ERROR = 'READ ERROR' + +# == + def filesplit(pathname): """ Splits pathname into directory part (not ending with '/'), |