def __init__(self, p, size): thumbSize = config("search.similarSearchThumbSize") super().__init__(p, size,[ Field("action", "操作", hasValue=False, delegateClass=ActionDelegate), Field("predict", "智能分类", formatMethod=self.getClassifyName), Field("thumb", "缩略图", defaultSize=thumbSize[0], delegateClass=ThumbDelegate, delegateParameters=(thumbSize,)), ],closeFields=["updatedTime","accessTime"]) self.classifyName = None self.className = None self.classDirs = None
def __init__(self, p, size): super().__init__( p, size, [ Field("action", "操作", hasValue=False, delegateClass=ActionDelegate), Field("predict", "智能分类", formatMethod=self.getClassifyName) ], closeFields=["updatedTime", "accessTime"]) self.className = None self.classDirs = None
def __init__(self, p, size): super().__init__( p, size, [ Field("action", "操作", hasValue=False, delegateClass=ActionDelegate), Field("predict", "智能分类", formatMethod=lambda i: "未命名分类{0}".format(i + 1)), ], closeFields=["updatedTime", "accessTime"]) self.classCount = None
def __init__(self, p, size): super().__init__(p, size, [ Field("action", "操作", hasValue=False, delegateClass=ActionDelegate), ], closeFields=["accessTime", "updatedTime"])
def __init__(self, p, size): super().__init__(p, size,[ Field("action", "操作", editable=True, hasValue=False, delegateClass=ActionDelegate), ]) self.queueFiles = [] self.timer: QTimer = None self.fullResult = False self.firstInsert = True self.setObjectName("normalSearchResult") self.submitState = None
def __init__(self, p, size): thumbSize = config("search.similarSearchThumbSize") super().__init__(p, size, [ Field("action", "操作", hasValue=False, delegateClass=ActionDelegate), Field("thumb", "缩略图", defaultSize=thumbSize[0], delegateClass=ThumbDelegate, delegateParameters=(thumbSize, )), Field("similarPercentage", "相似度") ], closeFields=["updatedTime", "accessTime"]) eventSystem.listen("finishedSimilarImageSearch", self.getResults, self) self.setObjectName("similarImageSearchResult") self.tableView.verticalHeader().setDefaultSectionSize(thumbSize[1])
def __openFile ( self ): print ( "PuzzleSolver::openFile: Opening puzzle file" ) file_path = QtGui.QFileDialog ().getOpenFileName ( self , "Open file" , "" , "Files (*)" ) print ( "Trying to open file:" , file_path ) try: file = open ( file_path , "r" ) except IOError: print ( "Error opening file. Try again" ) return file_contents = [] for line in file: clean_line = line.rstrip () words = clean_line.split ( " " ) if len ( words ) == 1: if words[ 0 ] == "": continue file_contents.extend ( words ) # Remove empty words while file_contents.count ( "" ) > 0: file_contents.remove ( "" ) file.close () # Convert the contents of the file into a queue file_queue = deque ( file_contents ) puzzle_width = int ( file_queue.popleft () ) puzzle_height = int ( file_queue.popleft () ) self.__field = Field ( puzzle_width , puzzle_height ) piece_amount = int ( file_queue.popleft () ) # Clean all self.__puzzle_pieces[:] = [] for i in range ( 0 , piece_amount ): piece = Piece () piece.load ( file_queue ) self.__puzzle_pieces.append ( piece ) self.__puzzle_viewer.clean () self.__puzzle_viewer.setSize ( puzzle_width , puzzle_height ) print ( "File loaded" )
def createModel(self,specialFields, closeFields): if specialFields == None: specialFields = [] fields = specialFields normalFields = [ Field("fileName", "文件名", defaultSize=120), Field("fileSize", "文件大小", defaultSize=60,formatMethod=fileSizeConvertToFitUnit), Field("createdTime", "创建时间", defaultSize=160, formatMethod=timestampConvertToString), Field("updatedTime", "修改时间", defaultSize=160,formatMethod=timestampConvertToString), Field("accessTime", "最近一次访问时间", defaultSize=160, formatMethod=timestampConvertToString), Field("path", "所属目录",defaultSize=250) ] for field in normalFields: if field.id not in closeFields: fields.append(field) self.model = FileTableModel(fields) return fields
class PuzzleSolver ( QtGui.QWidget ): """Main container of the program""" def __init__ ( self ): super ( PuzzleSolver , self ).__init__ () # Create the main container self.__horizontal_layout = QtGui.QHBoxLayout () # Create components self.__puzzle_actions = PuzzleActions () self.__puzzle_viewer = PuzzleViewer () # Add components self.setLayout ( self.__horizontal_layout ) self.__horizontal_layout.addWidget ( self.__puzzle_viewer ) self.__horizontal_layout.addWidget ( self.__puzzle_actions ) # Connect signals and slots self.__puzzle_actions.signal_open_file.connect ( self.__openFile ) self.__puzzle_actions.signal_run_puzzle.connect ( self.__runPuzzle ) self.__puzzle_pieces = [] def __openFile ( self ): print ( "PuzzleSolver::openFile: Opening puzzle file" ) file_path = QtGui.QFileDialog ().getOpenFileName ( self , "Open file" , "" , "Files (*)" ) print ( "Trying to open file:" , file_path ) try: file = open ( file_path , "r" ) except IOError: print ( "Error opening file. Try again" ) return file_contents = [] for line in file: clean_line = line.rstrip () words = clean_line.split ( " " ) if len ( words ) == 1: if words[ 0 ] == "": continue file_contents.extend ( words ) # Remove empty words while file_contents.count ( "" ) > 0: file_contents.remove ( "" ) file.close () # Convert the contents of the file into a queue file_queue = deque ( file_contents ) puzzle_width = int ( file_queue.popleft () ) puzzle_height = int ( file_queue.popleft () ) self.__field = Field ( puzzle_width , puzzle_height ) piece_amount = int ( file_queue.popleft () ) # Clean all self.__puzzle_pieces[:] = [] for i in range ( 0 , piece_amount ): piece = Piece () piece.load ( file_queue ) self.__puzzle_pieces.append ( piece ) self.__puzzle_viewer.clean () self.__puzzle_viewer.setSize ( puzzle_width , puzzle_height ) print ( "File loaded" ) def __runPuzzle ( self ): print ( "PuzzleSolver::runPuzzle: Running puzzle solver" ) self.__puzzle_viewer.clean () field_copy = copy.deepcopy ( self.__field ) print ( "Original field size:" , self.__field.getWidth (), "x", self.__field.getHeight () ) print ( "Copy field size:" , field_copy.getWidth (), "x", field_copy.getHeight () ) if not self.__solve ( field_copy , self.__puzzle_pieces , 0 ): print ( "Solution not found" ) QtGui.QMessageBox ().critical ( self , "Search complete" , "No solution found" ) else: QtGui.QMessageBox ().information ( self , "Search complete" , "Solution found" ) def __solve ( self , field , working_pieces , current_piece ): print ( "Adding piece ID:" , current_piece ) if current_piece == len ( working_pieces ): print ( "Solution found" ) field.print () self.__puzzle_viewer.update ( field ) return True working_pieces[ current_piece ].print () print ( "Into this field:" ) field.print () self.__puzzle_viewer.update ( field ) solved = False print ( "Trying to place..." ) y = 0 while ( y < field.getHeight () ) and not solved: x = 0 while ( x < field.getWidth () ) and not solved: if field.canBeInserted ( working_pieces[ current_piece ] , x , y ): temp_field = copy.deepcopy ( field ) temp_field.insertPiece ( working_pieces[ current_piece ] , x , y ) print ( "Piece added at ", x, ",", y ) print ( "New field:" ) temp_field.print () self.__puzzle_viewer.update ( temp_field ) solved = self.__solve ( temp_field , working_pieces , current_piece + 1 ) if not solved: print ( "Trying another position with piece" , current_piece ) x += 1 y += 1 return solved
def __init__(self, parent=None): super(MainForm, self).__init__(parent) self.id = 0 self.clearResult = True self.queueFiles = [] self.timer: QTimer = None self.setObjectName("mainWindow") self.setStyleSheet(""" #mainWindow{ background-color:#f7f9fc; } QHeaderView{ padding:0; margin:0; } QHeaderView::section { background-color:#f7f9fc; border: 0; color: #6d6f72; } QTableView::item,#QTableViewDelegate{ background-color:#f7f9fc; border:0; min-height: 200px; } QTableView::item:hover { background-color: #dae2f0; } #tableViewOpenBtn{ margin: 0 auto; } """) layout = QVBoxLayout() fields = [ Field("action", "操作", editable=True, delegateClass=ActionDelegate), Field("fileName", "文件名", editable=True), Field("fileSize", "文件大小", formatMethod=fileSizeConvertToFitUnit), Field("createdTime", "创建时间", formatMethod=timestampConvertToString), Field("updatedTime", "修改时间", formatMethod=timestampConvertToString), Field("accessTime", "最近一次访问时间", formatMethod=timestampConvertToString), Field("path", "所属目录") ] model = FileTableModel(fields, ["操作"]) tableView = MyTreeView(model, fields) tableView.setFrameShape(QFrame.NoFrame) tableView.setMaximumSize(800, 400) tableView.setItemDelegateForColumn(1, ActionDelegate(tableView)) header = tableView.horizontalHeader() header.sectionClicked[int].connect(self.sortTable) layout.addWidget(tableView) self.setLayout(layout) Hbox = QHBoxLayout() openChecked = QPushButton("打开选中文件", self) openChecked.clicked.connect(model.openChecked) Hbox.addWidget(openChecked) moveChecked = QPushButton("移动选中文件", self) moveChecked.clicked.connect(model.moveChecked) Hbox.addWidget(moveChecked) deleteButton = QPushButton("删除选中文件", self) deleteButton.clicked.connect(model.deleteChecked) Hbox.addWidget(deleteButton) searchButton = QPushButton("停止搜索", self) searchButton.clicked.connect(self.clickedSearchBtn) layout.addLayout(Hbox) self.tableView = tableView self.model = model self.setMinimumSize(800, 600) self.initialLoad() # timer = QTimer() # timer.timeout.connect(self.generate) # timer.start(1000) # self.timer = timer eventSystem.listen("getPartialResult", self.getPartialResult, self) eventSystem.listen("finishClassify", self.finishSearch, self) eventSystem.listen("stopSearch", self.stopSearch, self) self.tableView = tableView self.model = model
def __init__(self, p, size): super().__init__(p, size,[ Field("action", "操作", hasValue=False, delegateClass=RepeatChildrenDelegate), Field("childrenCount", "重复数") ],closeFields=["accessTime","updatedTime"])