本文整理汇总了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()