예제 #1
0
    def _init (cls):
        def callback (widget, allocation):
            cls.widgets["enterGameNotationFrame"].set_size_request(
                    223, allocation.height-4)
        cls.widgets["enterGameNotationSidePanel"].connect_after("size-allocate", callback)

        flags = []
        if isInstalled():
            path = gettext.find("pychess")
        else:
            path = gettext.find("pychess", localedir=addDataPrefix("lang"))
        if path:
            loc = locale.getdefaultlocale()[0][-2:].lower()
            flags.append(addDataPrefix("flags/%s.png" % loc))

        flags.append(addDataPrefix("flags/us.png"))

        cls.ib = ImageButton(flags)
        cls.widgets["imageButtonDock"].add(cls.ib)
        cls.ib.show()

        cls.sourcebuffer = GtkSource.Buffer()
        sourceview = GtkSource.View.new_with_buffer(cls.sourcebuffer)
        sourceview.set_tooltip_text(
            _("Type or paste PGN game or FEN positions here"))
        cls.widgets["scrolledwindow6"].add(sourceview)
        sourceview.show()

        # Pgn format does not allow tabulator
        sourceview.set_insert_spaces_instead_of_tabs(True)
        sourceview.set_wrap_mode(Gtk.WrapMode.WORD)

        man = GtkSource.LanguageManager()
        # Init new version
        if hasattr(man.props, 'search_path'):
            try:
                path = os.path.join(getDataPrefix(),"gtksourceview-1.0/language-specs")
                man.props.search_path = man.props.search_path + [path]
                if 'pgn' in man.get_language_ids():
                    lang = man.get_language('pgn')
                    cls.sourcebuffer.set_language(lang)
                else:
                    log.warning("Unable to load pgn syntax-highlighting.")
                cls.sourcebuffer.set_highlight_syntax(True)
            except NotImplementedError:
                # Python 2.7.3 in Ubuntu 12.04
                log.warning("Unable to load pgn syntax-highlighting.")
        # Init old version
        else:
            os.environ["XDG_DATA_DIRS"] = getDataPrefix()+":/usr/share/"
            man = LanguageManager()
            for lang in man.get_available_languages():
                if lang.get_name() == "PGN":
                    cls.sourcebuffer.set_language(lang)
                    break
            else:
                log.warning("Unable to load pgn syntax-highlighting.")
            cls.sourcebuffer.set_highlight(True)
예제 #2
0
    def _init(cls):
        def callback(widget, allocation):
            cls.widgets["enterGameNotationFrame"].set_size_request(
                223, allocation.height - 4)

        cls.widgets["enterGameNotationSidePanel"].connect_after(
            "size-allocate", callback)

        flags = []
        if isInstalled():
            path = gettext.find("pychess")
        else:
            path = gettext.find("pychess", localedir=addDataPrefix("lang"))
        if path:
            loc = locale.getdefaultlocale()[0][-2:].lower()
            flags.append(addDataPrefix("flags/%s.png" % loc))

        flags.append(addDataPrefix("flags/us.png"))

        cls.ib = ImageButton(flags)
        cls.widgets["imageButtonDock"].add(cls.ib)
        cls.ib.show()

        cls.sourcebuffer = GtkSource.Buffer()
        sourceview = GtkSource.View.new_with_buffer(cls.sourcebuffer)
        sourceview.set_tooltip_text(
            _("Type or paste PGN game or FEN positions here"))
        cls.widgets["scrolledwindow6"].add(sourceview)
        sourceview.show()

        # Pgn format does not allow tabulator
        sourceview.set_insert_spaces_instead_of_tabs(True)
        sourceview.set_wrap_mode(Gtk.WrapMode.WORD)

        man = GtkSource.LanguageManager()
        # Init new version
        if hasattr(man.props, 'search_path'):
            path = os.path.join(getDataPrefix(),
                                "gtksourceview-1.0/language-specs")
            man.props.search_path = man.props.search_path + [path]
            if 'pgn' in man.get_language_ids():
                lang = man.get_language('pgn')
                cls.sourcebuffer.set_language(lang)
            else:
                log.warning("Unable to load pgn syntax-highlighting.")
            cls.sourcebuffer.set_highlight_syntax(True)
        # Init old version
        else:
            os.environ["XDG_DATA_DIRS"] = getDataPrefix() + ":/usr/share/"
            man = LanguageManager()
            for lang in man.get_available_languages():
                if lang.get_name() == "PGN":
                    cls.sourcebuffer.set_language(lang)
                    break
            else:
                log.warning("Unable to load pgn syntax-highlighting.")
            cls.sourcebuffer.set_highlight(True)
예제 #3
0
import sqlite3
import struct

from pychess.compat import memoryview
from pychess.System.prefix import addDataPrefix, isInstalled

db_path = os.path.join(addDataPrefix("eco.db"))
if os.path.exists(db_path):
    conn = sqlite3.connect(db_path, check_same_thread = False)
    atexit.register(conn.close)
    ECO_OK = True
else:
    print("Warning: eco.db not find, run pgn2ecodb.sh")
    ECO_OK = False

if isInstalled():
    mofile = gettext.find('pychess')
else:
    mofile = gettext.find('pychess', localedir=addDataPrefix("lang"))

if mofile is None:
    lang = "en"
else:
    lang = mofile.split(os.sep)[-3]

# big-endian, unsigned long long (uint64)
hash_struct = struct.Struct('>Q')

def get_eco(hash):
    if not ECO_OK:
        return None
예제 #4
0
# DA = https://da.wikipedia.org/wiki/Skak%C3%A5bninger
# DE = https://de.wikipedia.org/wiki/ECO-Code
# ES = https://es.wikipedia.org/wiki/Anexo:Aperturas_de_ajedrez
# HU = https://hu.wikipedia.org/wiki/Sakkmegnyit%C3%A1sok_list%C3%A1ja
# FR = https://fr.wikipedia.org/wiki/Liste_des_ouvertures_d'%C3%A9checs_suivant_le_code_ECO

db_path = os.path.join(addDataPrefix("eco.db"))
if os.path.exists(db_path):
    conn = sqlite3.connect(db_path, check_same_thread=False)
    atexit.register(conn.close)
    ECO_OK = True
else:
    print("Warning: eco.db not found, please run pgn2ecodb.sh")
    ECO_OK = False

if isInstalled():
    mofile = gettext.find('pychess')
else:
    mofile = gettext.find('pychess', localedir=addDataPrefix("lang"))

if mofile is None:
    lang = ECO_MAIN_LANG
else:
    lang = mofile.split(os.sep)[-3]


def get_eco(hash, exactPosition=True):
    if not ECO_OK:
        return None
    cur = conn.cursor()
    select = "select eco, opening, variation, endline from openings where hash=? and hkey=? and lang=? and endline like ?"