本文整理匯總了Python中model.database.Database.init_from_pgn方法的典型用法代碼示例。如果您正苦於以下問題:Python Database.init_from_pgn方法的具體用法?Python Database.init_from_pgn怎麽用?Python Database.init_from_pgn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.database.Database
的用法示例。
在下文中一共展示了Database.init_from_pgn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: open_database
# 需要導入模塊: from model.database import Database [as 別名]
# 或者: from model.database.Database import init_from_pgn [as 別名]
def open_database(self):
dialog = QFileDialog()
if self.model.gamestate.last_open_dir != None:
dialog.setDirectory(self.model.gamestate.last_open_dir)
filename = dialog.getOpenFileName(
self.mainAppWindow.chessboard_view,
self.mainAppWindow.trUtf8("Open PGN"),
None,
"PGN (*.pgn)",
QFileDialog.DontUseNativeDialog,
)
if filename:
db = Database(filename)
db.init_from_pgn(self.mainAppWindow, self.mainAppWindow.trUtf8("Scanning PGN File..."))
self.model.database = db
self.model.user_settings.active_database = db.filename
selectedGame = 0
if db.no_of_games() > 1:
dlg = DialogBrowsePgn(db)
if dlg.exec_() == QDialog.Accepted:
items = dlg.table.selectedItems()
selectedGame = int(items[0].text()) - 1
else:
selectedGame = None
if not selectedGame == None and db.no_of_games() > 0:
loaded_game = db.load_game(selectedGame)
self.model.gamestate.current = loaded_game
self.mainAppWindow.chessboard_view.update()
self.mainAppWindow.chessboard_view.emit(SIGNAL("statechanged()"))
self.mainAppWindow.save.setEnabled(False)
self.mainAppWindow.setLabels()
self.mainAppWindow.moves_edit_view.setFocus()
self.model.gamestate.last_open_dir = QFileInfo(filename).dir().absolutePath()
self.model.gamestate.init_game_tree(self.mainAppWindow)
self.mainAppWindow.moves_edit_view.setFocus()