示例#1
0
 def __movestr(self, board):
     move = board.lastMove
     if self.fan:
         movestr = toFAN(board.prev, move)
     else:
         movestr = toSAN(board.prev, move, True)
     nagsymbols = "".join([nag2symbol(nag) for nag in board.nags])
     # To prevent wrap castling we will use hyphen bullet (U+2043)
     return "%s%s%s" % (move_count(board), movestr.replace(
         '-', u'⁃'), nagsymbols)
    def button_press_event(self, widget, event):
        """ Calls setShownBoard() or edit_comment() on mouse click, or pops-up local menu """

        (wx, wy) = event.get_coords()
        (x,
         y) = self.textview.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
                                                    int(wx), int(wy))
        it = self.textview.get_iter_at_location(x, y)

        # https://gramps-project.org/bugs/view.php?id=9335
        if isinstance(it, Gtk.TextIter):
            offset = it.get_offset()
        else:
            offset = it[1].get_offset()

        node = None
        for n in self.nodelist:
            if offset >= n["start"] and offset < n["end"]:
                node = n
                board = node["board"]
                break
        if node is None:
            return True
        # print("-------------------------------------------------------")
        # print("index is:", self.nodelist.index(node))
        # print(node)
        # print("-------------------------------------------------------")
        # left mouse click
        if event.button == 1:
            if "vari" in node:
                if self.need_remove_variation is not None:
                    self.remove_variation(self.need_remove_variation)
                    self.need_remove_variation = None
                return True
            elif "comment" in node:
                self.edit_comment(board=board, index=node["index"])
            else:
                self.boardview.setShownBoard(board.pieceBoard)

        # local menu on right mouse click
        elif event.button == 3:
            self.menu = Gtk.Menu()

            if node is not None:
                position = -1
                for index, child in enumerate(board.children):
                    if isinstance(child, str):
                        position = index
                        break

                if len(self.gamemodel.boards) > 1 and board == self.gamemodel.boards[1].board and \
                        not self.gamemodel.boards[0].board.children:
                    menuitem = Gtk.MenuItem(_("Add start comment"))
                    menuitem.connect('activate', self.edit_comment,
                                     self.gamemodel.boards[0].board, 0)
                    self.menu.append(menuitem)

                if position == -1:
                    menuitem = Gtk.MenuItem(_("Add comment"))
                    menuitem.connect('activate', self.edit_comment, board, 0)
                    self.menu.append(menuitem)
                else:
                    menuitem = Gtk.MenuItem(_("Edit comment"))
                    menuitem.connect('activate', self.edit_comment, board,
                                     position)
                    self.menu.append(menuitem)

                symbol_menu1 = Gtk.Menu()
                for nag, menutext in (("$1", _("Good move")), ("$2",
                                                               _("Bad move")),
                                      ("$3", _("Excellent move")),
                                      ("$4", _("Very bad move")),
                                      ("$5", _("Interesting move")),
                                      ("$6", _("Suspicious move")),
                                      ("$7", _("Forced move"))):
                    menuitem = Gtk.MenuItem("%s %s" %
                                            (nag2symbol(nag), menutext))
                    menuitem.connect('activate', self.symbol_menu1_activate,
                                     board, nag)
                    symbol_menu1.append(menuitem)

                menuitem = Gtk.MenuItem(_("Add move symbol"))
                menuitem.set_submenu(symbol_menu1)
                self.menu.append(menuitem)

                symbol_menu2 = Gtk.Menu()
                for nag, menutext in (("$10",
                                       _("Drawish")), ("$13",
                                                       _("Unclear position")),
                                      ("$14", _("Slight advantage")),
                                      ("$16", _("Moderate advantage")),
                                      ("$18", _("Decisive advantage")),
                                      ("$20", _("Crushing advantage")),
                                      ("$22", _("Zugzwang")),
                                      ("$32", _("Development advantage")),
                                      ("$36",
                                       _("Initiative")), ("$40",
                                                          _("With attack")),
                                      ("$44",
                                       _("Compensation")), ("$132",
                                                            _("Counterplay")),
                                      ("$138", _("Time pressure"))):
                    menuitem = Gtk.MenuItem("%s %s" %
                                            (nag2symbol(nag), menutext))
                    menuitem.connect('activate', self.symbol_menu2_activate,
                                     board, nag)
                    symbol_menu2.append(menuitem)

                menuitem = Gtk.MenuItem(_("Add evaluation symbol"))
                menuitem.set_submenu(symbol_menu2)
                self.menu.append(menuitem)

                self.menu.append(Gtk.SeparatorMenuItem())

                removals_menu = Gtk.Menu()

                menuitem = Gtk.MenuItem(_("Comment"))
                menuitem.connect('activate', self.delete_comment, board,
                                 position)
                removals_menu.append(menuitem)

                menuitem = Gtk.MenuItem(_("Symbols"))
                menuitem.connect('activate', self.remove_symbols, board)
                removals_menu.append(menuitem)

                menuitem = Gtk.MenuItem(_("All the evaluations"))
                menuitem.connect('activate', self.reset_evaluations)
                removals_menu.append(menuitem)

                menuitem = Gtk.MenuItem(_("Remove"))
                menuitem.set_submenu(removals_menu)
                self.menu.append(menuitem)

                self.menu.show_all()
                self.menu.popup(None, None, None, None, event.button,
                                event.time)
        return True