parameters: (self, filePath=None)
return_statement: return False
docstring: Load the specified file, or the last opened file if None.
docstring_summary: Load the specified file, or the last opened file if None.
docstring_tokens: Load the specified file or the last opened file if None .
function: def loadFile(self, filePath=None):
          """Load the specified file, or the last opened file if None."""
          if self.dirty:
              self.mayContinue()
          self.resetState()
          self.canvas.setEnabled(False)
          if filePath is None:
              filePath = self.settings.get(SETTING_FILENAME)
  
          # Make sure that filePath is a regular python string, rather than QString
          filePath = ustr(filePath)
          # Fix bug: An index error after select a directory when open a new file.
          unicodeFilePath = ustr(filePath)
          # unicodeFilePath = os.path.abspath(unicodeFilePath)
          # Tzutalin 20160906 : Add file list and dock to move faster
          # Highlight the file item
          if unicodeFilePath and self.fileListWidget.count() > 0:
              if unicodeFilePath in self.mImgList:
                  index = self.mImgList.index(unicodeFilePath)
                  fileWidgetItem = self.fileListWidget.item(index)
                  print('unicodeFilePath is', unicodeFilePath)
                  fileWidgetItem.setSelected(True)
                  ###
                  self.iconlist.clear()
                  self.additems5(None)
                  for i in range(5):
                      item_tooltip = self.iconlist.item(i).toolTip()
                      # print(i,"---",item_tooltip)
                      if item_tooltip == ustr(filePath):
                          titem = self.iconlist.item(i)
                          titem.setSelected(True)
                          self.iconlist.scrollToItem(titem)
                          break
              else:
                  self.fileListWidget.clear()
                  self.mImgList.clear()
                  self.iconlist.clear()
  
          # if unicodeFilePath and self.iconList.count() > 0:
          #     if unicodeFilePath in self.mImgList:
  
          if unicodeFilePath and os.path.exists(unicodeFilePath):
              self.canvas.verified = False
  
              cvimg = cv2.imdecode(np.fromfile(unicodeFilePath, dtype=np.uint8), 1)
              height, width, depth = cvimg.shape
              cvimg = cv2.cvtColor(cvimg, cv2.COLOR_BGR2RGB)
              image = QImage(cvimg.data, width, height, width * depth, QImage.Format_RGB888)
  
              if image.isNull():
                  self.errorMessage(u'Error opening file',
                                    u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath)
                  self.status("Error reading %s" % unicodeFilePath)
                  return False
              self.status("Loaded %s" % os.path.basename(unicodeFilePath))
              self.image = image
              self.filePath = unicodeFilePath
              self.canvas.loadPixmap(QPixmap.fromImage(image))
  
              if self.validFilestate(filePath) is True:
                  self.setClean()
              else:
                  self.dirty = False
                  self.actions.save.setEnabled(True)
  
              self.canvas.setEnabled(True)
              self.adjustScale(initial=True)
              self.paintCanvas()
              self.addRecentFile(self.filePath)
              self.toggleActions(True)
              self.showBoundingBoxFromPPlabel(filePath)
  
              self.setWindowTitle(__appname__ + ' ' + filePath)
  
              # Default : select last item if there is at least one item
              if self.labelList.count():
                  self.labelList.setCurrentItem(self.labelList.item(self.labelList.count() - 1))
                  self.labelList.item(self.labelList.count() - 1).setSelected(True)
  
              self.canvas.setFocus(True)
              return True
          return False
function_tokens: def loadFile ( self , filePath = None ) : if self . dirty : self . mayContinue ( ) self . resetState ( ) self . canvas . setEnabled ( False ) if filePath is None : filePath = self . settings . get ( SETTING_FILENAME ) # Make sure that filePath is a regular python string, rather than QString filePath = ustr ( filePath ) # Fix bug: An index error after select a directory when open a new file. unicodeFilePath = ustr ( filePath ) # unicodeFilePath = os.path.abspath(unicodeFilePath) # Tzutalin 20160906 : Add file list and dock to move faster # Highlight the file item if unicodeFilePath and self . fileListWidget . count ( ) > 0 : if unicodeFilePath in self . mImgList : index = self . mImgList . index ( unicodeFilePath ) fileWidgetItem = self . fileListWidget . item ( index ) print ( 'unicodeFilePath is' , unicodeFilePath ) fileWidgetItem . setSelected ( True ) ### self . iconlist . clear ( ) self . additems5 ( None ) for i in range ( 5 ) : item_tooltip = self . iconlist . item ( i ) . toolTip ( ) # print(i,"---",item_tooltip) if item_tooltip == ustr ( filePath ) : titem = self . iconlist . item ( i ) titem . setSelected ( True ) self . iconlist . scrollToItem ( titem ) break else : self . fileListWidget . clear ( ) self . mImgList . clear ( ) self . iconlist . clear ( ) # if unicodeFilePath and self.iconList.count() > 0: #     if unicodeFilePath in self.mImgList: if unicodeFilePath and os . path . exists ( unicodeFilePath ) : self . canvas . verified = False cvimg = cv2 . imdecode ( np . fromfile ( unicodeFilePath , dtype = np . uint8 ) , 1 ) height , width , depth = cvimg . shape cvimg = cv2 . cvtColor ( cvimg , cv2 . COLOR_BGR2RGB ) image = QImage ( cvimg . data , width , height , width * depth , QImage . Format_RGB888 ) if image . isNull ( ) : self . errorMessage ( u'Error opening file' , u"<p>Make sure <i>%s</i> is a valid image file." % unicodeFilePath ) self . status ( "Error reading %s" % unicodeFilePath ) return False self . status ( "Loaded %s" % os . path . basename ( unicodeFilePath ) ) self . image = image self . filePath = unicodeFilePath self . canvas . loadPixmap ( QPixmap . fromImage ( image ) ) if self . validFilestate ( filePath ) is True : self . setClean ( ) else : self . dirty = False self . actions . save . setEnabled ( True ) self . canvas . setEnabled ( True ) self . adjustScale ( initial = True ) self . paintCanvas ( ) self . addRecentFile ( self . filePath ) self . toggleActions ( True ) self . showBoundingBoxFromPPlabel ( filePath ) self . setWindowTitle ( __appname__ + ' ' + filePath ) # Default : select last item if there is at least one item if self . labelList . count ( ) : self . labelList . setCurrentItem ( self . labelList . item ( self . labelList . count ( ) - 1 ) ) self . labelList . item ( self . labelList . count ( ) - 1 ) . setSelected ( True ) self . canvas . setFocus ( True ) return True return False