Example #1
0
File: usi.py Project: gbtami/gshogi
    def __init__(self, side):

        self.engine = "gshogi"
        self.path = ""
        self.engine_running = False
        self.newgame = False
        self.running_engine = ""
        self.stop_pending = False
        self.ponder_move = None
        self.side = side
        self.engine_debug = engine_debug.get_ref()
        self.engine_output = engine_output.get_ref()
Example #2
0
    def __init__(self, side):

        self.engine = "gshogi"
        self.path = ""
        self.engine_running = False
        self.newgame = False
        self.running_engine = ""
        self.stop_pending = False
        self.ponder_move = None
        self.side = side
        self.engine_debug = engine_debug.get_ref()
        self.engine_output = engine_output.get_ref()
Example #3
0
    def __init__(self, verbose, verbose_usi, side):

        self.engine = 'gshogi'
        self.path = ''
        self.engine_running = False
        self.newgame = False
        self.running_engine = ''
        self.stop_pending = False
        self.ponder_move = None
        self.verbose = verbose
        self.verbose_usi = verbose_usi
        self.side = side
        self.engine_debug = engine_debug.get_ref()
        self.engine_output = engine_output.get_ref()
Example #4
0
 def __init__(self, verbose, verbose_usi, side):
 
     self.engine = 'gshogi'
     self.path = ''        
     self.engine_running = False
     self.newgame = False
     self.running_engine = ''         
     self.stop_pending = False
     self.ponder_move = None
     self.verbose = verbose 
     self.verbose_usi = verbose_usi
     self.side = side        
     self.engine_debug = engine_debug.get_ref()
     self.engine_output = engine_output.get_ref()        
Example #5
0
File: gui.py Project: gbtami/gshogi
    def build_gui(self):

        self.gobactive = False
        self.engine_debug = engine_debug.get_ref()
        self.engine_output = engine_output.get_ref()
        self.move_list = move_list.get_ref()
        self.gamelist = gamelist.get_ref()
        self.set_board_colours = set_board_colours.get_ref()
        self.drag_and_drop = drag_and_drop.get_ref()
        self.enable_dnd = True
        self.load_save = load_save.get_ref()
        self.show_coords = True
        self.highlight_moves = True

        # Create Main Window
        glade_dir = gv.gshogi.get_glade_dir()
        self.glade_file = os.path.join(glade_dir, "main_window.glade")
        self.glade_file_preferences = os.path.join(
            glade_dir, "preferences.glade")
        self.builder = Gtk.Builder()
        self.builder.add_from_file(self.glade_file)
        self.builder.connect_signals(self)

        self.window = self.builder.get_object("main_window")
        screen = self.window.get_screen()
        self.screen_width = screen.get_width()
        self.screen_height = screen.get_height()
        self.set_window_size()

        # self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        self.window.set_title(NAME + " " + VERSION)

        # 1 eventbox per board square
        self.eb = [[Gtk.EventBox() for x in range(9)] for x in range(9)]

        # 1 eventbox per komadai board square
        self.keb = [[Gtk.EventBox() for x in range(7)] for x in range(2)]

        # Set a handler for delete_event that immediately exits GTK.
        self.window.connect("delete_event", gv.gshogi.delete_event)

        main_vbox = self.builder.get_object("main_vbox")
        main_vbox.show()

        # menu
        # Create a UIManager instance
        uimanager = Gtk.UIManager()

        # Add the accelerator group to the toplevel window
        accelgroup = uimanager.get_accel_group()
        self.window.add_accel_group(accelgroup)

        # main action group
        actiongroup = Gtk.ActionGroup("UIManagerAG")
        self.actiongroup = actiongroup

        # action group for toggleactions
        ta_action_group = Gtk.ActionGroup("AGPromoteMode")
        ta_action_group.add_toggle_actions([(
            "promotemode", None, "_Ask Before Promoting", None, None,
            self.promote_mode)])

        self.ta_action_group = ta_action_group

        # Create actions
        actiongroup.add_actions([
            # NewGame and the handicap names are used in gshogi.py NewGame
            # routine. don't change them.
            ("NewGame", Gtk.STOCK_NEW, "_New Game", None, "New Game",
             gv.gshogi.new_game_cb),
            ("LanceHandicap", None, "_Lance", None,
             "Lance Handicap", gv.gshogi.new_game_cb),
            ("BishopHandicap", None, "_Bishop", None,
             "Bishop Handicap", gv.gshogi.new_game_cb),
            ("RookHandicap", None, "_Rook", None,
             "Rook Handicap", gv.gshogi.new_game_cb),
            ("RookandLanceHandicap", None, "_Rook and Lance", None,
             "Rook and Lance Handicap", gv.gshogi.new_game_cb),
            ("TwoPieceHandicap", None, "_2 Pieces", None,
             "Two Piece Handicap", gv.gshogi.new_game_cb),
            ("FourPieceHandicap", None, "_4 Pieces", None,
             "Four Piece Handicap", gv.gshogi.new_game_cb),
            ("SixPieceHandicap", None, "_6 Pieces", None,
             "Six Piece Handicap", gv.gshogi.new_game_cb),
            ("EightPieceHandicap", None, "_8 Pieces", None,
             "Eight Piece Handicap", gv.gshogi.new_game_cb),
            ("TenPieceHandicap", None, "_10 Pieces", None,
             "Ten Piece Handicap", gv.gshogi.new_game_cb),
            ("NewHandicapGame", None, "_New Handicap Game"),
            #
            ("Quit", Gtk.STOCK_QUIT, "_Quit", None,
             "Quit the Program", gv.gshogi.quit_game),
            ("LoadGame", Gtk.STOCK_OPEN, "_Load Game", None,
             "Load Game", self.load_save.load_game),
            ("SaveGame", Gtk.STOCK_SAVE, "_Save Game", None,
             "Save Game", self.load_save.save_game),
            ("File", None, "_File"),
            ("Edit", None, "_Edit"),
            ("Undo", Gtk.STOCK_UNDO, "_Undo Move", "<Control>U",
             "Undo Move", gv.gshogi.undo_single_move),
            ("Redo", Gtk.STOCK_REDO, "_Redo Move", "<Control>R",
             "Redo Move", gv.gshogi.redo_single_move),
            ("MoveNow", None, "_Move Now", "<Control>M",
             "Move Now", gv.gshogi.move_now),
            ("SetBoardColours", None, "_Set Board Colours", None,
             "Set Board Colours", self.set_board_colours.show_dialog),
            ("SetPieces", None, "_Set Pieces", None,
             "Set Pieces", self.set_board_colours.show_pieces_dialog),
            ("TimeControl", None, "_Time Control", None,
             "Time Control", gv.tc.time_control),
            # ConfigureEngine1 - this name is used in engine_manager.
            # don't change it.
            ("ConfigureEngine1", None, "_Configure Engine 1", None,
             "Configure Engine 1", gv.engine_manager.configure_engine),
            ("ConfigureEngine2", None, "_Configure Engine 2", None,
             "Configure Engine 2", gv.engine_manager.configure_engine),
            ("Players", None, "_Players", None,
             "Players", gv.gshogi.set_players),
            ("Engines", None, "_Engines", None,
             "Engines", gv.engine_manager.engines),
            ("CommonEngineSettings", None, "_Common Engine Settings", None,
             "Common Engine Settings", gv.engine_manager.common_settings),
            ("MoveList", None, "_Move List", None,
             "Move List", self.move_list.show_movelist_window),
            ("GameList", None, "_Game List", None,
             "Game List", self.gamelist.show_gamelist_window_cb),
            ("EngineOutput", None, "_Engine Output", None,
             "Engine Output", self.engine_output.show_engine_output_window),
            ("EngineDebug", None, "_Engine Debug", None,
             "Engine Debug", self.engine_debug.show_debug_window),
            ("Options", None, "_Options"),
            ("View", None, "_View"),
            ("About", Gtk.STOCK_ABOUT, "_About", None,
             "Show About Box", self.about_box),
            ("Help", None, "_Help"),
            ("CopyPosition", None, "_Copy Position", None,
             "Copy Position", utils.copy_SFEN_to_clipboard),
            ("PastePosition", None, "_Paste Position", None,
             "Paste Position", utils.paste_clipboard_to_SFEN),
            ("CopyGame", None, "_Copy Game", None,
             "Copy Game", utils.copy_game_to_clipboard),
            ("PasteGame", None, "_Paste Game", None,
             "Paste Game", utils.paste_game_from_clipboard),
            ("EditPosition", None, "_Edit Position", None,
             "Edit Position", self.enable_edit_mode),
            ("Preferences", None, "_Preferences", None,
             "Preferences", self.preferences),
            ]
        )

        # Add the actiongroups to the uimanager
        uimanager.insert_action_group(actiongroup, 0)
        uimanager.insert_action_group(ta_action_group, 1)

        ui = """<ui>
        <menubar name="MenuBar">
            <menu action="File">
                <menuitem action="NewGame"/>
                <menu action="NewHandicapGame">
                    <menuitem action="LanceHandicap"/>
                    <menuitem action="BishopHandicap"/>
                    <menuitem action="RookHandicap"/>
                    <menuitem action="RookandLanceHandicap"/>
                    <menuitem action="TwoPieceHandicap"/>
                    <menuitem action="FourPieceHandicap"/>
                    <menuitem action="SixPieceHandicap"/>
                    <menuitem action="EightPieceHandicap"/>
                    <menuitem action="TenPieceHandicap"/>
                </menu>
                <separator/>
                <menuitem action="LoadGame"/>
                <menuitem action="SaveGame"/>
                <separator/>
                <menuitem action="Quit"/>
            </menu>
            <menu action="Edit">
                <menuitem action="CopyPosition"/>
                <menuitem action="PastePosition"/>
                <separator/>
                <menuitem action="CopyGame"/>
                <menuitem action="PasteGame"/>
                <separator/>
                <menuitem action="EditPosition"/>
                <separator/>
                <menuitem action="Preferences"/>
            </menu>
            <menu action="Options">
                <menuitem action="Undo"/>
                <menuitem action="Redo"/>
                <menuitem action="MoveNow"/>
                <separator/>
                <menuitem action="promotemode"/>
                <menuitem action="SetBoardColours"/>
                <menuitem action="SetPieces"/>
                <separator/>
                <menuitem action="TimeControl"/>
                <menuitem action="ConfigureEngine1"/>
                <menuitem action="ConfigureEngine2"/>
                <menuitem action="Players"/>
                <menuitem action="Engines"/>
                <menuitem action="CommonEngineSettings"/>
            </menu>
            <menu action="View">
                <menuitem action="MoveList"/>
                <menuitem action="GameList"/>
                <menuitem action="EngineOutput"/>
                <menuitem action="EngineDebug"/>
            </menu>
            <menu action="Help">
                <menuitem action="About"/>
            </menu>
        </menubar>
        </ui>"""

        # Add a UI description
        uimanager.add_ui_from_string(ui)

        # Use an event box and set its background colour.
        # This was needed on Ubuntu 12.04 to set the toolbar bg colour.
        # Otherwise ubuntu uses the window bg colour which is not
        # correct.
        # don't need this on Fedora though.
        eb_1 = self.builder.get_object("eb_1")
        # eb_1 = Gtk.EventBox()
        vbox2 = Gtk.VBox(False, 0)
        # main_vbox.pack_start(vbox2, False)
        # main_vbox.pack_start(eb_1, False)
        eb_1.add(vbox2)
        eb_1.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB"))

        # Create a MenuBar
        menubar = uimanager.get_widget("/MenuBar")
        vbox2.pack_start(menubar, False, True, 0)

        # create a toolbar
        toolbar = Gtk.Toolbar()
        vbox2.pack_start(toolbar, False, True, 0)

        # populate toolbar
        toolitem = Gtk.ToolItem()

        # 2 rows, 4 columns, not homogeneous
        tb = Gtk.Table(2, 5, False)

        # Gtk.ShadowType.NONE, SHADOW_IN, SHADOW_OUT, SHADOW_ETCHED_IN,
        # SHADOW_ETCHED_OUT

        self.side_to_move = [
            Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN),
            Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN)]
        self.side_to_move[BLACK].set_alignment(0.5, 0.4)
        self.side_to_move[WHITE].set_alignment(0.5, 0.4)

        tb.attach(self.side_to_move[WHITE], 0, 1, 0, 1)
        tb.attach(self.side_to_move[BLACK], 0, 1, 1, 2)

        lw = Gtk.Label(label="White: ")
        lb = Gtk.Label(label="Black: ")
        lw.set_alignment(0, 0.5)
        lb.set_alignment(0, 0.5)
        tb.attach(lw, 1, 2, 0, 1)
        tb.attach(lb, 1, 2, 1, 2)

        self.engines_lblw = Gtk.Label(label="gshogi")
        self.engines_lblw.set_use_markup(True)
        self.engines_lblw.set_alignment(0, 0.5)

        self.engines_lblb = Gtk.Label(label="human")
        self.engines_lblb.set_use_markup(True)
        self.engines_lblb.set_alignment(0, 0.5)

        tb.attach(self.engines_lblw, 2, 3, 0, 1)
        tb.attach(self.engines_lblb, 2, 3, 1, 2)

        # time control
        self.tc_lbl = [
            Gtk.Label(label="00:45:00 00/10"),
            Gtk.Label(label="00:45:00 00/10")]
        self.tc_lbl[BLACK].set_alignment(0, 0.5)
        self.tc_lbl[WHITE].set_alignment(0, 0.5)

        tb.attach(self.tc_lbl[WHITE], 3, 4, 0, 1)
        tb.attach(self.tc_lbl[BLACK], 3, 4, 1, 2)

        toolitem.add(tb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # stop/go buttons
        hb = Gtk.HBox(False, 0)
        self.gobutton = Gtk.ToolButton(Gtk.STOCK_YES)
        self.gobutton.connect("clicked", gv.gshogi.go_clicked)
        self.stopbutton = Gtk.ToolButton(Gtk.STOCK_NO)
        self.stopbutton.connect("clicked", gv.gshogi.stop_clicked)
        self.gobutton.set_tooltip_text("go")
        self.stopbutton.set_tooltip_text("stop")
        hb.pack_start(self.stopbutton, False, True, 0)
        hb.pack_start(self.gobutton, False, True, 0)

        toolitem = Gtk.ToolItem()
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # game review buttons
        hb = Gtk.HBox(False, 0)
        self.go_first = Gtk.ToolButton(Gtk.STOCK_GOTO_FIRST)
        self.go_first.connect("clicked", gv.gshogi.undo_all)

        self.go_back = Gtk.ToolButton(Gtk.STOCK_GO_BACK)
        self.go_back.connect("clicked", gv.gshogi.undo_single_move)

        self.go_forward = Gtk.ToolButton(Gtk.STOCK_GO_FORWARD)
        self.go_forward.connect("clicked", gv.gshogi.redo_single_move)

        self.go_last = Gtk.ToolButton(Gtk.STOCK_GOTO_LAST)
        self.go_last.connect("clicked", gv.gshogi.redo_all)

        hb.pack_start(self.go_first, False, True, 0)
        hb.pack_start(self.go_back, False, True, 0)
        hb.pack_start(self.go_forward, False, True, 0)
        hb.pack_start(self.go_last, False, True, 0)

        toolitem = Gtk.ToolItem()
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        main_grid = self.builder.get_object("grid1")
        main_grid.set_row_homogeneous(True)
        main_grid.set_column_homogeneous(True)
        # main_hbox = Gtk.HBox(False, 0)

        # Create komadai grids for captured pieces
        self.setup_komadai(WHITE, main_grid)
        self.setup_komadai(BLACK, main_grid)

        # Create a 9x9 table for the main board
        self.boardgrid = Gtk.Grid.new()
        self.boardgrid.set_row_homogeneous(True)
        self.boardgrid.set_column_homogeneous(True)
        self.boardgrid.set_border_width(1)

        #
        # init board squares (add event box, set up drag and drop,
        # button clicks)
        # x, y = 0, 0 is the top left square of the board
        #
        for x in range(9):
            for y in range(9):
                self.init_board_square(x, y)

        eb2 = Gtk.EventBox()

        eb2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black"))
        eb2.add(self.boardgrid)
        eb = Gtk.EventBox()
        eb.add(eb2)
        eb.show()

        aspect_frame = Gtk.AspectFrame(label=None, xalign=0.5, yalign=0.5,
                                       ratio=1.0, obey_child=False)
        aspect_frame.add(eb)

        eb2.set_border_width(20)
        self.grid_eb = eb2

        main_grid.attach(aspect_frame, 6, 0, 20, 20)
        aspect_frame.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black"))

        eb.connect_after("draw", self.draw_coords)
        self.border_eb = eb

        # status bar
        self.status_bar = self.builder.get_object("status_bar")

        # set status bar bg color
        # Use an event box and set its background colour.
        # This was needed on Fedora 19 to set the statusbar bg colour.
        # Otherwise it uses the window bg colour which is not
        # correct. This was not needed on F17.
        eb_2 = self.builder.get_object("eb_2")
        eb_2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB"))
        # self.status_bar = Gtk.Statusbar()
        # main_vbox.pack_start(self.status_bar, False, False, 0)
        self.context_id = self.status_bar.get_context_id("gshogi statusbar")

        self.actiongroup.get_action("MoveNow").set_sensitive(False)

        self.window.show_all()
        self.side_to_move[WHITE].hide()
        self.gobutton.set_sensitive(False)
        self.stopbutton.set_sensitive(False)

        # mask = Gdk.WindowHints.BASE_SIZE|
        #            Gdk.WindowHints.MIN_SIZE|
        #            Gdk.WindowHints.MAX_SIZE|
        #            Gdk.WindowHints.RESIZE_INC|Gdk.WindowHints.ASPECT
        #mask = Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE
        mask = Gdk.WindowHints.MIN_SIZE
        geometry = Gdk.Geometry()
        # geometry.base_width = -1
        # geometry.base_height = -1
        # geometry.max_width = -1
        # geometry.max_height = -1
        geometry.min_width = 378
        geometry.min_height = 378
        # geometry.width_inc = -1
        # geometry.height_inc = -1
        # geometry.min_aspect = -1.0
        # geometry.max_aspect = -1.0
        #self.window.set_geometry_hints(self.window, geometry, mask)
        # self.window.set_geometry_hints(
        #   self.window, min_width=378, min_height=378, max_width=-1,
        #   max_height=-1, base_width=-1, base_height=-1, width_inc=-1,
        #   height_inc=-1, min_aspect=-1.0, max_aspect=-1.0)

        self.build_edit_popup()
Example #6
0
    def build_gui(self):

        self.gobactive = False
        self.engine_debug = engine_debug.get_ref()
        self.engine_output = engine_output.get_ref()
        self.move_list = move_list.get_ref()
        self.gamelist = gamelist.get_ref()
        self.set_board_colours = set_board_colours.get_ref()
        self.drag_and_drop = drag_and_drop.get_ref()
        self.enable_dnd = True
        self.load_save = load_save.get_ref()
        self.show_coords = True
        self.highlight_moves = True

        # Create Main Window
        glade_dir = gv.gshogi.get_glade_dir()
        self.glade_file = os.path.join(glade_dir, "main_window.glade")
        self.glade_file_preferences = os.path.join(glade_dir,
                                                   "preferences.glade")
        self.builder = Gtk.Builder()
        self.builder.add_from_file(self.glade_file)
        self.builder.connect_signals(self)

        self.window = self.builder.get_object("main_window")
        screen = self.window.get_screen()
        self.screen_width = screen.get_width()
        self.screen_height = screen.get_height()
        self.set_window_size()

        # self.window = Gtk.Window(Gtk.WindowType.TOPLEVEL)
        self.window.set_title(NAME + " " + VERSION)

        # 1 eventbox per board square
        self.eb = [[Gtk.EventBox() for x in range(9)] for x in range(9)]

        # 1 eventbox per komadai board square
        self.keb = [[Gtk.EventBox() for x in range(7)] for x in range(2)]

        # Set a handler for delete_event that immediately exits GTK.
        self.window.connect("delete_event", gv.gshogi.delete_event)

        main_vbox = self.builder.get_object("main_vbox")
        main_vbox.show()

        # menu
        # Create a UIManager instance
        uimanager = Gtk.UIManager()

        # Add the accelerator group to the toplevel window
        accelgroup = uimanager.get_accel_group()
        self.window.add_accel_group(accelgroup)

        # main action group
        actiongroup = Gtk.ActionGroup("UIManagerAG")
        self.actiongroup = actiongroup

        # action group for toggleactions
        ta_action_group = Gtk.ActionGroup("AGPromoteMode")
        ta_action_group.add_toggle_actions([
            ("promotemode", None, "_Ask Before Promoting", None, None,
             self.promote_mode)
        ])

        self.ta_action_group = ta_action_group

        # Create actions
        actiongroup.add_actions([
            # NewGame and the handicap names are used in gshogi.py NewGame
            # routine. don't change them.
            ("NewGame", Gtk.STOCK_NEW, "_New Game", None, "New Game",
             gv.gshogi.new_game_cb),
            ("LanceHandicap", None, "_Lance", None, "Lance Handicap",
             gv.gshogi.new_game_cb),
            ("BishopHandicap", None, "_Bishop", None, "Bishop Handicap",
             gv.gshogi.new_game_cb),
            ("RookHandicap", None, "_Rook", None, "Rook Handicap",
             gv.gshogi.new_game_cb),
            ("RookandLanceHandicap", None, "_Rook and Lance", None,
             "Rook and Lance Handicap", gv.gshogi.new_game_cb),
            ("TwoPieceHandicap", None, "_2 Pieces", None, "Two Piece Handicap",
             gv.gshogi.new_game_cb),
            ("FourPieceHandicap", None, "_4 Pieces", None,
             "Four Piece Handicap", gv.gshogi.new_game_cb),
            ("SixPieceHandicap", None, "_6 Pieces", None, "Six Piece Handicap",
             gv.gshogi.new_game_cb),
            ("EightPieceHandicap", None, "_8 Pieces", None,
             "Eight Piece Handicap", gv.gshogi.new_game_cb),
            ("TenPieceHandicap", None, "_10 Pieces", None,
             "Ten Piece Handicap", gv.gshogi.new_game_cb),
            ("NewHandicapGame", None, "_New Handicap Game"),
            #
            ("Quit", Gtk.STOCK_QUIT, "_Quit", None, "Quit the Program",
             gv.gshogi.quit_game),
            ("LoadGame", Gtk.STOCK_OPEN, "_Load Game", None, "Load Game",
             self.load_save.load_game),
            ("SaveGame", Gtk.STOCK_SAVE, "_Save Game", None, "Save Game",
             self.load_save.save_game),
            ("File", None, "_File"),
            ("Edit", None, "_Edit"),
            ("Undo", Gtk.STOCK_UNDO, "_Undo Move", "<Control>U", "Undo Move",
             gv.gshogi.undo_single_move),
            ("Redo", Gtk.STOCK_REDO, "_Redo Move", "<Control>R", "Redo Move",
             gv.gshogi.redo_single_move),
            ("MoveNow", None, "_Move Now", "<Control>M", "Move Now",
             gv.gshogi.move_now),
            ("SetBoardColours", None, "_Set Board Colours", None,
             "Set Board Colours", self.set_board_colours.show_dialog),
            ("SetPieces", None, "_Set Pieces", None, "Set Pieces",
             self.set_board_colours.show_pieces_dialog),
            ("TimeControl", None, "_Time Control", None, "Time Control",
             gv.tc.time_control),
            # ConfigureEngine1 - this name is used in engine_manager.
            # don't change it.
            ("ConfigureEngine1", None, "_Configure Engine 1", None,
             "Configure Engine 1", gv.engine_manager.configure_engine),
            ("ConfigureEngine2", None, "_Configure Engine 2", None,
             "Configure Engine 2", gv.engine_manager.configure_engine),
            ("Players", None, "_Players", None, "Players",
             gv.gshogi.set_players),
            ("Engines", None, "_Engines", None, "Engines",
             gv.engine_manager.engines),
            ("CommonEngineSettings", None, "_Common Engine Settings", None,
             "Common Engine Settings", gv.engine_manager.common_settings),
            ("MoveList", None, "_Move List", None, "Move List",
             self.move_list.show_movelist_window),
            ("GameList", None, "_Game List", None, "Game List",
             self.gamelist.show_gamelist_window_cb),
            ("EngineOutput", None, "_Engine Output", None, "Engine Output",
             self.engine_output.show_engine_output_window),
            ("EngineDebug", None, "_Engine Debug", None, "Engine Debug",
             self.engine_debug.show_debug_window),
            ("Options", None, "_Options"),
            ("View", None, "_View"),
            ("About", Gtk.STOCK_ABOUT, "_About", None, "Show About Box",
             self.about_box),
            ("Help", None, "_Help"),
            ("CopyPosition", None, "_Copy Position", None, "Copy Position",
             utils.copy_SFEN_to_clipboard),
            ("PastePosition", None, "_Paste Position", None, "Paste Position",
             utils.paste_clipboard_to_SFEN),
            ("CopyGame", None, "_Copy Game", None, "Copy Game",
             utils.copy_game_to_clipboard),
            ("PasteGame", None, "_Paste Game", None, "Paste Game",
             utils.paste_game_from_clipboard),
            ("EditPosition", None, "_Edit Position", None, "Edit Position",
             self.enable_edit_mode),
            ("Preferences", None, "_Preferences", None, "Preferences",
             self.preferences),
        ])

        # Add the actiongroups to the uimanager
        uimanager.insert_action_group(actiongroup, 0)
        uimanager.insert_action_group(ta_action_group, 1)

        ui = """<ui>
        <menubar name="MenuBar">
            <menu action="File">
                <menuitem action="NewGame"/>
                <menu action="NewHandicapGame">
                    <menuitem action="LanceHandicap"/>
                    <menuitem action="BishopHandicap"/>
                    <menuitem action="RookHandicap"/>
                    <menuitem action="RookandLanceHandicap"/>
                    <menuitem action="TwoPieceHandicap"/>
                    <menuitem action="FourPieceHandicap"/>
                    <menuitem action="SixPieceHandicap"/>
                    <menuitem action="EightPieceHandicap"/>
                    <menuitem action="TenPieceHandicap"/>
                </menu>
                <separator/>
                <menuitem action="LoadGame"/>
                <menuitem action="SaveGame"/>
                <separator/>
                <menuitem action="Quit"/>
            </menu>
            <menu action="Edit">
                <menuitem action="CopyPosition"/>
                <menuitem action="PastePosition"/>
                <separator/>
                <menuitem action="CopyGame"/>
                <menuitem action="PasteGame"/>
                <separator/>
                <menuitem action="EditPosition"/>
                <separator/>
                <menuitem action="Preferences"/>
            </menu>
            <menu action="Options">
                <menuitem action="Undo"/>
                <menuitem action="Redo"/>
                <menuitem action="MoveNow"/>
                <separator/>
                <menuitem action="promotemode"/>
                <menuitem action="SetBoardColours"/>
                <menuitem action="SetPieces"/>
                <separator/>
                <menuitem action="TimeControl"/>
                <menuitem action="ConfigureEngine1"/>
                <menuitem action="ConfigureEngine2"/>
                <menuitem action="Players"/>
                <menuitem action="Engines"/>
                <menuitem action="CommonEngineSettings"/>
            </menu>
            <menu action="View">
                <menuitem action="MoveList"/>
                <menuitem action="GameList"/>
                <menuitem action="EngineOutput"/>
                <menuitem action="EngineDebug"/>
            </menu>
            <menu action="Help">
                <menuitem action="About"/>
            </menu>
        </menubar>
        </ui>"""

        # Add a UI description
        uimanager.add_ui_from_string(ui)

        # Use an event box and set its background colour.
        # This was needed on Ubuntu 12.04 to set the toolbar bg colour.
        # Otherwise ubuntu uses the window bg colour which is not
        # correct.
        # don't need this on Fedora though.
        eb_1 = self.builder.get_object("eb_1")
        # eb_1 = Gtk.EventBox()
        vbox2 = Gtk.VBox(False, 0)
        # main_vbox.pack_start(vbox2, False)
        # main_vbox.pack_start(eb_1, False)
        eb_1.add(vbox2)
        eb_1.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB"))

        # Create a MenuBar
        menubar = uimanager.get_widget("/MenuBar")
        vbox2.pack_start(menubar, False, True, 0)

        # create a toolbar
        toolbar = Gtk.Toolbar()
        vbox2.pack_start(toolbar, False, True, 0)

        # populate toolbar
        toolitem = Gtk.ToolItem()

        # 2 rows, 4 columns, not homogeneous
        tb = Gtk.Table(2, 5, False)

        # Gtk.ShadowType.NONE, SHADOW_IN, SHADOW_OUT, SHADOW_ETCHED_IN,
        # SHADOW_ETCHED_OUT

        self.side_to_move = [
            Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN),
            Gtk.Arrow(Gtk.ArrowType.RIGHT, Gtk.ShadowType.ETCHED_IN)
        ]
        self.side_to_move[BLACK].set_alignment(0.5, 0.4)
        self.side_to_move[WHITE].set_alignment(0.5, 0.4)

        tb.attach(self.side_to_move[WHITE], 0, 1, 0, 1)
        tb.attach(self.side_to_move[BLACK], 0, 1, 1, 2)

        lw = Gtk.Label(label="White: ")
        lb = Gtk.Label(label="Black: ")
        lw.set_alignment(0, 0.5)
        lb.set_alignment(0, 0.5)
        tb.attach(lw, 1, 2, 0, 1)
        tb.attach(lb, 1, 2, 1, 2)

        self.engines_lblw = Gtk.Label(label="gshogi")
        self.engines_lblw.set_use_markup(True)
        self.engines_lblw.set_alignment(0, 0.5)

        self.engines_lblb = Gtk.Label(label="human")
        self.engines_lblb.set_use_markup(True)
        self.engines_lblb.set_alignment(0, 0.5)

        tb.attach(self.engines_lblw, 2, 3, 0, 1)
        tb.attach(self.engines_lblb, 2, 3, 1, 2)

        # time control
        self.tc_lbl = [
            Gtk.Label(label="00:45:00 00/10"),
            Gtk.Label(label="00:45:00 00/10")
        ]
        self.tc_lbl[BLACK].set_alignment(0, 0.5)
        self.tc_lbl[WHITE].set_alignment(0, 0.5)

        tb.attach(self.tc_lbl[WHITE], 3, 4, 0, 1)
        tb.attach(self.tc_lbl[BLACK], 3, 4, 1, 2)

        toolitem.add(tb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # stop/go buttons
        hb = Gtk.HBox(False, 0)
        self.gobutton = Gtk.ToolButton(Gtk.STOCK_YES)
        self.gobutton.connect("clicked", gv.gshogi.go_clicked)
        self.stopbutton = Gtk.ToolButton(Gtk.STOCK_NO)
        self.stopbutton.connect("clicked", gv.gshogi.stop_clicked)
        self.gobutton.set_tooltip_text("go")
        self.stopbutton.set_tooltip_text("stop")
        hb.pack_start(self.stopbutton, False, True, 0)
        hb.pack_start(self.gobutton, False, True, 0)

        toolitem = Gtk.ToolItem()
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # game review buttons
        hb = Gtk.HBox(False, 0)
        self.go_first = Gtk.ToolButton(Gtk.STOCK_GOTO_FIRST)
        self.go_first.connect("clicked", gv.gshogi.undo_all)

        self.go_back = Gtk.ToolButton(Gtk.STOCK_GO_BACK)
        self.go_back.connect("clicked", gv.gshogi.undo_single_move)

        self.go_forward = Gtk.ToolButton(Gtk.STOCK_GO_FORWARD)
        self.go_forward.connect("clicked", gv.gshogi.redo_single_move)

        self.go_last = Gtk.ToolButton(Gtk.STOCK_GOTO_LAST)
        self.go_last.connect("clicked", gv.gshogi.redo_all)

        hb.pack_start(self.go_first, False, True, 0)
        hb.pack_start(self.go_back, False, True, 0)
        hb.pack_start(self.go_forward, False, True, 0)
        hb.pack_start(self.go_last, False, True, 0)

        toolitem = Gtk.ToolItem()
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        # add a vertical separator
        hb = Gtk.HBox(False, 0)
        toolitem = Gtk.ToolItem()
        vsep = Gtk.VSeparator()
        hb.pack_start(vsep, True, True, 10)
        toolitem.add(hb)
        toolbar.insert(toolitem, -1)

        main_grid = self.builder.get_object("grid1")
        main_grid.set_row_homogeneous(True)
        main_grid.set_column_homogeneous(True)
        # main_hbox = Gtk.HBox(False, 0)

        # Create komadai grids for captured pieces
        self.setup_komadai(WHITE, main_grid)
        self.setup_komadai(BLACK, main_grid)

        # Create a 9x9 table for the main board
        self.boardgrid = Gtk.Grid.new()
        self.boardgrid.set_row_homogeneous(True)
        self.boardgrid.set_column_homogeneous(True)
        self.boardgrid.set_border_width(1)

        #
        # init board squares (add event box, set up drag and drop,
        # button clicks)
        # x, y = 0, 0 is the top left square of the board
        #
        for x in range(9):
            for y in range(9):
                self.init_board_square(x, y)

        eb2 = Gtk.EventBox()

        eb2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black"))
        eb2.add(self.boardgrid)
        eb = Gtk.EventBox()
        eb.add(eb2)
        eb.show()

        aspect_frame = Gtk.AspectFrame(label=None,
                                       xalign=0.5,
                                       yalign=0.5,
                                       ratio=1.0,
                                       obey_child=False)
        aspect_frame.add(eb)

        eb2.set_border_width(20)
        self.grid_eb = eb2

        main_grid.attach(aspect_frame, 6, 0, 20, 20)
        aspect_frame.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("black"))

        eb.connect_after("draw", self.draw_coords)
        self.border_eb = eb

        # status bar
        self.status_bar = self.builder.get_object("status_bar")

        # set status bar bg color
        # Use an event box and set its background colour.
        # This was needed on Fedora 19 to set the statusbar bg colour.
        # Otherwise it uses the window bg colour which is not
        # correct. This was not needed on F17.
        eb_2 = self.builder.get_object("eb_2")
        eb_2.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse("#EDECEB"))
        # self.status_bar = Gtk.Statusbar()
        # main_vbox.pack_start(self.status_bar, False, False, 0)
        self.context_id = self.status_bar.get_context_id("gshogi statusbar")

        self.actiongroup.get_action("MoveNow").set_sensitive(False)

        self.window.show_all()
        self.side_to_move[WHITE].hide()
        self.gobutton.set_sensitive(False)
        self.stopbutton.set_sensitive(False)

        # mask = Gdk.WindowHints.BASE_SIZE|
        #            Gdk.WindowHints.MIN_SIZE|
        #            Gdk.WindowHints.MAX_SIZE|
        #            Gdk.WindowHints.RESIZE_INC|Gdk.WindowHints.ASPECT
        #mask = Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE
        mask = Gdk.WindowHints.MIN_SIZE
        geometry = Gdk.Geometry()
        # geometry.base_width = -1
        # geometry.base_height = -1
        # geometry.max_width = -1
        # geometry.max_height = -1
        geometry.min_width = 378
        geometry.min_height = 378
        # geometry.width_inc = -1
        # geometry.height_inc = -1
        # geometry.min_aspect = -1.0
        # geometry.max_aspect = -1.0
        #self.window.set_geometry_hints(self.window, geometry, mask)
        # self.window.set_geometry_hints(
        #   self.window, min_width=378, min_height=378, max_width=-1,
        #   max_height=-1, base_width=-1, base_height=-1, width_inc=-1,
        #   height_inc=-1, min_aspect=-1.0, max_aspect=-1.0)

        self.build_edit_popup()