コード例 #1
0
ファイル: enginesDialog.py プロジェクト: btrent/knave
        def add(button):
            self.add = True
            response = engine_chooser_dialog.run()

            if response == gtk.RESPONSE_OK:
                new_engine = engine_chooser_dialog.get_filename()
                if new_engine:
                    try:
                        uci = is_uci(new_engine)
                        if not uci:
                            if not is_cecp(new_engine):
                                # restore the original
                                engine = discoverer.getEngineByName(self.cur_engine)
                                engine_chooser_dialog.set_filename(engine["command"])
                                print "Maybe not a chess engine"
                                return
                        path, binname = os.path.split(new_engine)
                        for e in discoverer.getEngines():
                            if e["name"] == binname:
                                binname = e["name"] + "(1)"
                                break
                        self.widgets["engine_name_entry"].set_text(binname)
                        self.widgets["engine_command_entry"].set_text(new_engine)
                        self.widgets["engine_protocol_combo"].set_active(0 if uci else 1)
                        self.widgets["engine_args_entry"].set_text("")
                        
                        name = self.widgets["engine_name_entry"].get_text().strip()
                        active = self.widgets["engine_protocol_combo"].get_active()
                        protocol = "uci" if active==0 else "xboard"
                        
                        discoverer.addEngine(name, new_engine, protocol)
                        self.cur_engine = name
                        glock_connect_after(discoverer, "engine_discovered", update_store)
                        self.add = False
                        discoverer.start()
                    except:
                        print "There is something wrong with this executable"
                else:
                    # restore the original
                    engine = discoverer.getEngineByName(self.cur_engine)
                    engine_chooser_dialog.set_filename(engine["command"])
            engine_chooser_dialog.hide()
コード例 #2
0
ファイル: enginesDialog.py プロジェクト: btrent/knave
 def protocol_changed(widget):
     if self.cur_engine is not None and not self.add and not self.selection:
         active = self.widgets["engine_protocol_combo"].get_active()
         new_protocol = "uci" if active==0 else "xboard"
         engine = discoverer.getEngineByName(self.cur_engine)
         old_protocol = engine["protocol"]
         if new_protocol != old_protocol:
             engine_command = engine_chooser_dialog.get_filename()
             # is the new protocol supported by the engine?
             if new_protocol == "uci":
                 ok = is_uci(engine_command)
             else:
                 ok = is_cecp(engine_command)
             if ok:
                 # discover engine options for new protocol
                 engine["protocol"] = new_protocol
                 engine["recheck"] = True
                 glock_connect_after(discoverer, "engine_discovered", update_options)
                 discoverer.start()
             else:
                 # restore the original protocol
                 widgets["engine_protocol_combo"].set_active(0 if old_protocol=="uci" else 1)
コード例 #3
0
def prepare():
    print "Discovering uci engines",
    discoverer.connect('discovering_started', cb_started)
    discoverer.connect('engine_discovered', cb_gotone)
    discoverer.connect('all_engines_discovered', start)
    discoverer.start()
コード例 #4
0
ファイル: Main.py プロジェクト: btrent/knave
    def initGlade(self):
        #=======================================================================
        # Init glade and the 'GladeHandlers'
        #=======================================================================
        gtk.about_dialog_set_url_hook(self.website)
        widgets = uistuff.GladeWidgets("PyChess.glade")
        widgets.getGlade().connect_signals(GladeHandlers.__dict__)
        tasker = TaskerManager()
        tasker.packTaskers (NewGameTasker(), InternetGameTasker())
        widgets["Background"].add(tasker)
        
        #------------------------------------------------------ Redirect widgets
        gamewidget.setWidgets(widgets)
        
        def on_sensitive_changed (widget, prop):
            name = widget.get_property('name')
            sensitive = widget.get_property('sensitive')
            #print "'%s' changed to '%s'" % (name, sensitive)
        widgets['pause1'].connect("notify::sensitive", on_sensitive_changed)
        widgets['resume1'].connect("notify::sensitive", on_sensitive_changed)
        #-------------------------- Main.py still needs a minimum of information
        ionest.handler.connect("gmwidg_created",
                               GladeHandlers.__dict__["on_gmwidg_created"])
        
        #---------------------- The only menuitems that need special initing
        for widget in ("hint_mode", "spy_mode"):
            widgets[widget].set_sensitive(False)

        uistuff.keep(widgets["hint_mode"], "hint_mode")
        uistuff.keep(widgets["spy_mode"], "spy_mode")
        uistuff.keep(widgets["show_sidepanels"], "show_sidepanels")
        uistuff.keep(widgets["auto_call_flag"], "autoCallFlag")
        
        #=======================================================================
        # Show main window and init d'n'd
        #=======================================================================
        widgets["window1"].set_title('%s - PyChess' % _('Welcome'))
        widgets["window1"].connect("key-press-event",
                                   GladeHandlers.__dict__["on_window_key_press"])
        uistuff.keepWindowSize("main", widgets["window1"], (575,479), POSITION_GOLDEN)
        widgets["window1"].show()
        widgets["Background"].show_all()
        
        flags = DEST_DEFAULT_MOTION | DEST_DEFAULT_HIGHLIGHT | DEST_DEFAULT_DROP
        # To get drag in the whole window, we add it to the menu and the
        # background. If it can be gotten to work, the drag_dest_set_proxy
        # method is very interesting.
        widgets["menubar1"].drag_dest_set(flags, dnd_list, gtk.gdk.ACTION_COPY)
        widgets["Background"].drag_dest_set(flags, dnd_list, gtk.gdk.ACTION_COPY)
        # TODO: http://code.google.com/p/pychess/issues/detail?id=737
        # The following two should really be set in the glade file
        #widgets["menubar1"].set_events(widgets["menubar1"].get_events() | gtk.gdk.DRAG_STATUS)
        #widgets["Background"].set_events(widgets["Background"].get_events() | gtk.gdk.DRAG_STATUS)
        
        #=======================================================================
        # Init 'minor' dialogs
        #=======================================================================
        
        #------------------------------------------------------------ Log dialog
        LogDialog.add_destroy_notify(lambda: widgets["log_viewer1"].set_active(0))
        
        #---------------------------------------------------------- About dialog
        aboutdialog = widgets["aboutdialog1"]
        clb = aboutdialog.get_child().get_children()[1].get_children()[2]
        aboutdialog.set_name(NAME)
        #aboutdialog.set_position(gtk.WIN_POS_CENTER)
        #aboutdialog.set_website_label(_("PyChess Homepage"))
        link = aboutdialog.get_website()
        aboutdialog.set_copyright("Copyright © 2006-2013")
        aboutdialog.set_version(VERSION_NAME+" "+VERSION)
        if os.path.isdir(prefix.addDataPrefix(".hg")):
            cmd = ["hg", "tip", "--cwd", prefix.getDataPrefix(), "--template", "{node|short} {date|isodate}"]
            process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
            out = process.stdout.readline().split()
            if len(out)>=2:
                comments = aboutdialog.get_comments()
                self.hg_rev = out[0]
                self.hg_date = out[1]
                aboutdialog.set_comments("rev. %s\n%s\n%s" % (self.hg_rev, self.hg_date, comments))
        
        with open(prefix.addDataPrefix("ARTISTS")) as f:
            aboutdialog.set_artists(f.read().splitlines())
        with open(prefix.addDataPrefix("AUTHORS")) as f:
            aboutdialog.set_authors(f.read().splitlines())
        with open(prefix.addDataPrefix("DOCUMENTERS")) as f:
            aboutdialog.set_documenters(f.read().splitlines())
        with open(prefix.addDataPrefix("TRANSLATORS")) as f:
            aboutdialog.set_translator_credits(f.read())

        def callback(button, *args):
            aboutdialog.hide()
            return True
        clb.connect("activate", callback)
        clb.connect("clicked", callback)
        aboutdialog.connect("delete-event", callback)

        #---------------------------------------------------- RecentChooser
        def recent_item_activated (self):
            uri = self.get_current_uri()
            try:
                urllib.urlopen(uri).close()
                newGameDialog.LoadFileExtension.run(self.get_current_uri())
            except (IOError, OSError):
                #shomething wrong whit the uri
                recentManager.remove_item(uri)
                
        self.menu_recent = gtk.RecentChooserMenu(recentManager)
        self.menu_recent.set_show_tips(True)
        self.menu_recent.set_sort_type(gtk.RECENT_SORT_MRU)
        self.menu_recent.set_limit(10)
        self.menu_recent.set_name("menu_recent")
        
        self.file_filter = gtk.RecentFilter()
        self.file_filter.add_mime_type("application/x-chess-pgn")
        self.menu_recent.set_filter(self.file_filter)

        self.menu_recent.connect("item-activated", recent_item_activated)
        widgets["load_recent_game1"].set_submenu(self.menu_recent)
        
        #----------------------------------------------------- Discoverer dialog
        def discovering_started (discoverer, binnames):
            gobject.idle_add(DiscovererDialog.show, discoverer, widgets["window1"])
        discoverer.connect("discovering_started", discovering_started)
        DiscovererDialog.init(discoverer)
        discoverer.start()
        
        #------------------------------------------------- Tip of the day dialog
        if conf.get("show_tip_at_startup", False):
            tipOfTheDay.TipOfTheDay.show()
コード例 #5
0
def prepare():
    print "Discovering uci engines",
    discoverer.connect('discovering_started', cb_started)
    discoverer.connect('engine_discovered', cb_gotone)
    discoverer.connect('all_engines_discovered', start)
    discoverer.start()
コード例 #6
0
            print "Black blunder", dif
            print "Should have done:", ", ".join(listToSan(game.getBoardAtPly(game.ply),oldmoves))
            print
    
    movename = toSAN(game.getBoardAtPly(game.ply-1),game.getMoveAtPly(game.ply-1))
    print "Considering", game.ply//2+1, movename, " ",
    game.undoMoves(1)

def onAnalyze(analyzer, pv, score):
    global values
    sys.stdout.write('.')
    sys.stdout.flush()
    if score != None:
        values[game.ply] = (pv, score*(-1)**game.ply)

###############################################################################
# Slightly validate arguments 

if len(sys.argv) != 2 or sys.argv[1] == "--help":
    print "Usage: python blunders.py FILENAME   Analyze the specified pgn file"
    print "       python blunders.py --help     Display this help and exit"
    print "Note: You'll probably need to run the scripts with your PYTHONPATH set"
    print " like 'PYTHONPATH=../lib/ python blunders...'"
    sys.exit()

###############################################################################
# Push onto the mainloop and start it
discoverer.connect('all_engines_discovered', start)
discoverer.start()
mainloop.run()
コード例 #7
0
    def initGlade(self):
        #=======================================================================
        # Init glade and the 'GladeHandlers'
        #=======================================================================
        gtk.glade.set_custom_handler(self.widgetHandler)
        gtk.about_dialog_set_url_hook(self.website)
        widgets = uistuff.GladeWidgets("PyChess.glade")
        widgets.getGlade().signal_autoconnect(GladeHandlers.__dict__)
        
        #------------------------------------------------------ Redirect widgets
        gamewidget.setWidgets(widgets)
        
        #-------------------------- Main.py still needs a minimum of information
        ionest.handler.connect("gmwidg_created",
                               GladeHandlers.__dict__["on_gmwidg_created"])
        
        #---------------------- The only menuitems that need special initing
        uistuff.keep(widgets["hint_mode"], "hint_mode")
        uistuff.keep(widgets["spy_mode"], "spy_mode")
        uistuff.keep(widgets["show_sidepanels"], "show_sidepanels")
        
        #=======================================================================
        # Show main window and init d'n'd
        #=======================================================================
        widgets["window1"].set_title('%s - PyChess' % _('Welcome'))
        widgets["window1"].connect("key-press-event",
                                   GladeHandlers.__dict__["on_window_key_press"])
        uistuff.keepWindowSize("main", widgets["window1"], (575,479), POSITION_GOLDEN)
        widgets["window1"].show()
        widgets["Background"].show_all()
        
        flags = DEST_DEFAULT_MOTION | DEST_DEFAULT_HIGHLIGHT | DEST_DEFAULT_DROP
        widgets["menubar1"].drag_dest_set(flags, dnd_list, gtk.gdk.ACTION_COPY)
        widgets["Background"].drag_dest_set(flags, dnd_list, gtk.gdk.ACTION_COPY)
        
        #=======================================================================
        # Init 'minor' dialogs
        #=======================================================================
        
        #------------------------------------------------------------ Log dialog
        LogDialog.add_destroy_notify(lambda: widgets["log_viewer1"].set_active(0))
        
        #---------------------------------------------------------- About dialog
        clb = widgets["aboutdialog1"].get_child().get_children()[1].get_children()[2]
        widgets["aboutdialog1"].set_name(NAME)
        #widgets["aboutdialog1"].set_position(gtk.WIN_POS_CENTER)
        #widgets["aboutdialog1"].set_website_label(_("PyChess Homepage"))
        link = widgets["aboutdialog1"].get_website()
        if os.path.isfile(prefix.addDataPrefix(".svn/entries")):
            f = open(prefix.addDataPrefix(".svn/entries"))
            line4 = [f.next() for i in xrange(4)][-1].strip()
            widgets["aboutdialog1"].set_version(VERSION_NAME+" r"+line4)
        else:
            widgets["aboutdialog1"].set_version(VERSION_NAME+" "+VERSION)
        
        with open(prefix.addDataPrefix("ARTISTS")) as f:
            widgets["aboutdialog1"].set_artists(f.read().splitlines())
        with open(prefix.addDataPrefix("AUTHORS")) as f:
            widgets["aboutdialog1"].set_authors(f.read().splitlines())
        with open(prefix.addDataPrefix("DOCUMENTERS")) as f:
            widgets["aboutdialog1"].set_documenters(f.read().splitlines())
        with open(prefix.addDataPrefix("TRANSLATORS")) as f:
            widgets["aboutdialog1"].set_translator_credits(f.read())

        def callback(button, *args):
            widgets["aboutdialog1"].hide()
            return True
        clb.connect("activate", callback)
        clb.connect("clicked", callback)
        widgets["aboutdialog1"].connect("delete-event", callback)
        
        #----------------------------------------------------- Discoverer dialog
        def discovering_started (discoverer, binnames):
            gobject.idle_add(DiscovererDialog.show, discoverer, widgets["window1"])
        discoverer.connect("discovering_started", discovering_started)
        DiscovererDialog.init(discoverer)
        discoverer.start()
        
        #------------------------------------------------- Tip of the day dialog
        if conf.get("show_tip_at_startup", False):
            tipOfTheDay.TipOfTheDay.show()
コード例 #8
0
    movename = toSAN(game.getBoardAtPly(game.ply - 1),
                     game.getMoveAtPly(game.ply - 1))
    print "Considering", game.ply // 2 + 1, movename, " ",
    game.undoMoves(1)


def onAnalyze(analyzer, pv, score):
    global values
    sys.stdout.write('.')
    sys.stdout.flush()
    if score != None:
        values[game.ply] = (pv, score * (-1)**game.ply)


###############################################################################
# Slightly validate arguments

if len(sys.argv) != 2 or sys.argv[1] == "--help":
    print "Usage: python blunders.py FILENAME   Analyze the specified pgn file"
    print "       python blunders.py --help     Display this help and exit"
    print "Note: You'll probably need to run the scripts with your PYTHONPATH set"
    print " like 'PYTHONPATH=../lib/ python blunders...'"
    sys.exit()

###############################################################################
# Push onto the mainloop and start it
discoverer.connect('all_engines_discovered', start)
discoverer.start()
mainloop.run()