Exemple #1
0
    def test_database_save_load(self):
        """Testing database save-load"""

        game_model = pgnfile0.loadToModel(0)

        p0, p1 = pgnfile0.get_player_names(0)
        game_model.players = (TestPlayer(p0), TestPlayer(p1))

        in_game = []
        walk(game_model.boards[0].board, in_game, game_model)
        in_game = " ".join(in_game)

        in_bb_list = [board.board.friends for board in game_model.boards]

        save(None, game_model)

        db = load(None)

        result = self.engine.execute(db.select)
        db.games = result.fetchall()
        print("%s selected" % len(db.games))

        game_model = db.loadToModel(0)

        out_game = []
        walk(game_model.boards[0].board, out_game, game_model)
        out_game = " ".join(out_game)

        out_bb_list = [board.board.friends for board in game_model.boards]

        self.assertEqual(in_game, out_game)
        self.assertEqual(in_bb_list, out_bb_list)
Exemple #2
0
    def load_test_pgn(self):
        for gameno in range(GAME_COUNT):
            game_model = pgnfile1.loadToModel(gameno)
            game_model.players = (TestPlayer("White"), TestPlayer("Black"))
            save(None, game_model)

        return load(None)
Exemple #3
0
    def test_databas(self):
        """Testing database save-load"""

        model = pgnfile.loadToModel(0)

        p0, p1 = pgnfile.get_player_names(0)
        model.players = (TestPlayer(p0), TestPlayer(p1))

        in_game = []
        walk(model.boards[0].board, in_game, model)
        in_game = " ".join(in_game)

        save(None, model)

        db = load(None)

        result = self.conn.execute(db.select)
        db.games = result.fetchall()
        print("%s selected" % len(db.games))

        model = db.loadToModel(0)

        out_game = []
        walk(model.boards[0].board, out_game, model)
        out_game = " ".join(out_game)

        self.assertEqual(in_game, out_game)
Exemple #4
0
    def test_databas(self):
        """Testing database save-load"""

        model = pgnfile.loadToModel(0)

        p0, p1 = pgnfile.get_player_names(0)
        model.players = (TestPlayer(p0), TestPlayer(p1))

        in_game = []
        walk(model.boards[0].board, in_game, model)
        in_game = " ".join(in_game)

        save(None, model)

        db = load(None)

        result = self.conn.execute(db.select)
        db.games = result.fetchall()
        print("%s selected" % len(db.games))

        model = db.loadToModel(0)

        out_game = []
        walk(model.boards[0].board, out_game, model)
        out_game = " ".join(out_game)

        self.assertEqual(in_game, out_game)
Exemple #5
0
    def open_chessfile(self, filename):
        if filename.endswith(".pdb"):
            chessfile = database.load(filename)
        elif filename.endswith(".pgn"):
            chessfile = pgn.load(protoopen(filename))
        elif filename.endswith(".epd"):
            chessfile = epd.load(protoopen(filename))
        elif filename.endswith(".fen"):
            chessfile = fen.load(protoopen(filename))
        else:
            return

        if self.gamelist is None:
            self.init_layout()

        perspective_manager.activate_perspective("database")
        self.emit("chessfile_opened", chessfile)
Exemple #6
0
    def init_layout(self):
        perspective_widget = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        perspective_manager.set_perspective_widget("database", perspective_widget)

        self.gamelist = GameList(database.load(None))
        self.switcher_panel = SwitcherPanel(self.gamelist)
        self.opening_tree_panel = OpeningTreePanel(self.gamelist)
        self.filter_panel = FilterPanel(self.gamelist)
        self.preview_panel = PreviewPanel(self.gamelist)

        self.progressbar0 = Gtk.ProgressBar(show_text=True)
        self.progressbar = Gtk.ProgressBar(show_text=True)
        self.progress_dialog = Gtk.Dialog("Import", None, 0, (
            Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
        self.progress_dialog.get_content_area().pack_start(self.progressbar0, True, True, 0)
        self.progress_dialog.get_content_area().pack_start(self.progressbar, True, True, 0)
        self.progress_dialog.get_content_area().show_all()

        perspective = perspective_manager.get_perspective("database")

        self.dock = PyDockTop("database", perspective)
        align = Gtk.Alignment()
        align.show()
        align.add(self.dock)
        self.dock.show()
        perspective_widget.pack_start(align, True, True, 0)

        dockLocation = addUserConfigPrefix("pydock-database.xml")

        docks = {
            "gamelist": (Gtk.Label(label="gamelist"), self.gamelist.box),
            "switcher": (dock_panel_tab(_("Database switcher"), "", addDataPrefix("glade/panel_docker.svg")), self.switcher_panel.alignment),
            "openingtree": (dock_panel_tab(_("Opening tree"), "", addDataPrefix("glade/panel_docker.svg")), self.opening_tree_panel.box),
            "filter": (dock_panel_tab(_("Filter"), "", addDataPrefix("glade/panel_docker.svg")), self.filter_panel.box),
            "preview": (dock_panel_tab(_("Preview"), "", addDataPrefix("glade/panel_docker.svg")), self.preview_panel.box),
        }

        if os.path.isfile(dockLocation):
            try:
                self.dock.loadFromXML(dockLocation, docks)
            except Exception as e:
                stringio = StringIO()
                traceback.print_exc(file=stringio)
                error = stringio.getvalue()
                log.error("Dock loading error: %s\n%s" % (e, error))
                msg_dia = Gtk.MessageDialog(None,
                                            type=Gtk.MessageType.ERROR,
                                            buttons=Gtk.ButtonsType.CLOSE)
                msg_dia.set_markup(_(
                    "<b><big>PyChess was unable to load your panel settings</big></b>"))
                msg_dia.format_secondary_text(_(
                    "Your panel settings have been reset. If this problem repeats, \
                    you should report it to the developers"))
                msg_dia.run()
                msg_dia.hide()
                os.remove(dockLocation)
                for title, panel in docks.values():
                    title.unparent()
                    panel.unparent()

        if not os.path.isfile(dockLocation):
            leaf = self.dock.dock(docks["gamelist"][1], CENTER, docks["gamelist"][0], "gamelist")
            leaf.setDockable(False)

            leaf.dock(docks["switcher"][1], NORTH, docks["switcher"][0], "switcher")
            leaf = leaf.dock(docks["filter"][1], EAST, docks["filter"][0], "filter")
            leaf = leaf.dock(docks["openingtree"][1], SOUTH, docks["openingtree"][0], "openingtree")
            leaf.dock(docks["preview"][1], SOUTH, docks["preview"][0], "preview")

        def unrealize(dock):
            dock.saveToXML(dockLocation)
            dock._del()

        self.dock.connect("unrealize", unrealize)

        self.dock.show_all()
        perspective_widget.show_all()

        perspective_manager.set_perspective_toolbuttons("database", [self.import_button, self.close_button])

        self.switcher_panel.connect("chessfile_switched", self.on_chessfile_switched)
Exemple #7
0
    def __init__(self):
        GObject.GObject.__init__(self)

        self.offset = 0
        self.orderby = None
        self.where = None
        self.count = 0
        self.conn = engine.connect()

        self.liststore = Gtk.ListStore(int, str, str, str, str, str, str, str,
                                       str, str, str)
        self.modelsort = Gtk.TreeModelSort(self.liststore)

        self.modelsort.set_sort_column_id(0, Gtk.SortType.ASCENDING)
        self.set_model(self.modelsort)
        self.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        self.set_headers_visible(True)
        self.set_rules_hint(True)
        self.set_search_column(1)

        cols = (_("Id"), _("White"), _("W Elo"), _("Black"), _("B Elo"),
                _("Result"), _("Event"), _("Site"), _("Round"), _("Date"),
                _("ECO"))
        for i, col in enumerate(cols):
            r = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn(col, r, text=i)
            column.set_resizable(True)
            column.set_reorderable(True)
            column.set_sort_column_id(i)
            column.connect("clicked", self.column_clicked, i)
            self.append_column(column)

        self.connect("row-activated", self.row_activated)

        self.set_cursor(0)
        self.columns_autosize()
        self.gameno = 0
        self.uri = pychess_pdb

        self.chessfile = load(open(self.uri))
        self.build_query()

        w = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        w.set_title(_("PyChess Game Database"))
        w.set_size_request(1000, 400)

        hbox = Gtk.HBox()

        self.playerlist = Gtk.ListStore(str)

        self.match = set()
        completion = Gtk.EntryCompletion()
        completion.set_model(self.playerlist)
        completion.set_text_column(0)

        for player in self.chessfile.players:
            self.playerlist.append(player)

        entry = Gtk.Entry()
        entry.set_completion(completion)
        entry.connect('activate', self.activate_entry)

        hbox.pack_start(entry, False, False, 0)

        toolbar = Gtk.Toolbar()
        hbox.pack_start(toolbar, True, True, 0)

        firstButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_PREVIOUS)
        toolbar.insert(firstButton, -1)

        prevButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_REWIND)
        toolbar.insert(prevButton, -1)

        nextButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_FORWARD)
        toolbar.insert(nextButton, -1)

        lastButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_NEXT)
        toolbar.insert(lastButton, -1)

        firstButton.connect("clicked", self.on_first_clicked)
        prevButton.connect("clicked", self.on_prev_clicked)
        nextButton.connect("clicked", self.on_next_clicked)
        lastButton.connect("clicked", self.on_last_clicked)

        vbox = Gtk.VBox()
        vbox.pack_start(hbox, False, False, 0)

        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        sw.add(self)
        vbox.pack_start(sw, True, True, 0)
        w.add(vbox)
        w.show_all()
Exemple #8
0
    def __init__(self):
        GObject.GObject.__init__(self)

        self.offset = 0
        self.orderby = None
        self.where = None
        self.count = 0
        self.conn = engine.connect()

        self.liststore = Gtk.ListStore(int, str, str, str, str, str, str, str,
                                       str, str, str)
        self.modelsort = Gtk.TreeModelSort(self.liststore)

        self.modelsort.set_sort_column_id(0, Gtk.SortType.ASCENDING)
        self.set_model(self.modelsort)
        self.get_selection().set_mode(Gtk.SelectionMode.BROWSE)
        self.set_headers_visible(True)
        self.set_rules_hint(True)
        self.set_search_column(1)

        cols = (_("Id"), _("White"), _("W Elo"), _("Black"), _("B Elo"),
                _("Result"), _("Event"), _("Site"), _("Round"), _("Date"),
                _("ECO"))
        for i, col in enumerate(cols):
            r = Gtk.CellRendererText()
            column = Gtk.TreeViewColumn(col, r, text=i)
            column.set_resizable(True)
            column.set_reorderable(True)
            column.set_sort_column_id(i)
            column.connect("clicked", self.column_clicked, i)
            self.append_column(column)

        self.connect("row-activated", self.row_activated)

        self.set_cursor(0)
        self.columns_autosize()
        self.gameno = 0
        self.uri = pychess_pdb

        self.chessfile = load(open(self.uri))
        self.build_query()

        w = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        w.set_title(_("PyChess Game Database"))
        w.set_size_request(1000, 400)

        hbox = Gtk.HBox()

        self.playerlist = Gtk.ListStore(str)

        self.match = set()
        completion = Gtk.EntryCompletion()
        completion.set_model(self.playerlist)
        completion.set_text_column(0)

        for player in self.chessfile.players:
            self.playerlist.append(player)

        entry = Gtk.Entry()
        entry.set_completion(completion)
        entry.connect('activate', self.activate_entry)

        hbox.pack_start(entry, False, False, 0)

        toolbar = Gtk.Toolbar()
        hbox.pack_start(toolbar, True, True, 0)

        firstButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_PREVIOUS)
        toolbar.insert(firstButton, -1)

        prevButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_REWIND)
        toolbar.insert(prevButton, -1)

        nextButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_FORWARD)
        toolbar.insert(nextButton, -1)

        lastButton = Gtk.ToolButton(Gtk.STOCK_MEDIA_NEXT)
        toolbar.insert(lastButton, -1)

        firstButton.connect("clicked", self.on_first_clicked)
        prevButton.connect("clicked", self.on_prev_clicked)
        nextButton.connect("clicked", self.on_next_clicked)
        lastButton.connect("clicked", self.on_last_clicked)

        vbox = Gtk.VBox()
        vbox.pack_start(hbox, False, False, 0)

        sw = Gtk.ScrolledWindow()
        sw.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
        sw.add(self)
        vbox.pack_start(sw, True, True, 0)
        w.add(vbox)
        w.show_all()