def set_filename (self, filename):
     asPath = splitUri(filename)[-1]
     if os.path.isfile(asPath):
         self.fcbutton.show()
         if filename != self._retrieve_filename():
             self.fcbutton.set_filename(os.path.abspath(asPath))
     else:
         self.fcbutton.set_uri("")
         self.fcbutton.hide()
     self.filename = filename
Beispiel #2
0
 def set_filename(self, filename):
     asPath = splitUri(filename)[-1]
     if os.path.isfile(asPath):
         self.fcbutton.show()
         if filename != self._retrieve_filename():
             self.fcbutton.set_filename(os.path.abspath(asPath))
     else:
         self.fcbutton.set_uri("")
         self.fcbutton.hide()
     self.filename = filename
Beispiel #3
0
def loadFileAndRun(uri):
    parts = splitUri(uri)
    uri = parts[1] if len(parts) == 2 else parts[0]
    loader = enddir[uri[uri.rfind(".") + 1:]]
    timemodel = TimeModel(0, 0)
    gamemodel = GameModel(timemodel)
    white_name = _("White")
    black_name = _("Black")
    p0 = (LOCAL, Human, (WHITE, white_name), white_name)
    p1 = (LOCAL, Human, (BLACK, black_name), black_name)
    game_handler.generalStart(gamemodel, p0, p1, (uri, loader, 0, -1))
Beispiel #4
0
def loadFilesAndRun(uris):
    for uri in uris:
        uri = splitUri(uri)[1]
        loader = ionest.enddir[uri[uri.rfind(".") + 1:]]
        timemodel = TimeModel(0, 0)
        gamemodel = GameModel(timemodel)
        white_name = _("White")
        black_name = _("Black")
        p0 = (LOCAL, Human, (WHITE, white_name), white_name)
        p1 = (LOCAL, Human, (BLACK, black_name), black_name)
        ionest.generalStart(gamemodel, p0, p1, (uri, loader, 0, -1))
Beispiel #5
0
def loadFilesAndRun(uris):
    for uri in uris:
        uri = splitUri(uri)[1]
        loader = game_handler.enddir[uri[uri.rfind(".") + 1:]]
        timemodel = TimeModel(0, 0)
        gamemodel = GameModel(timemodel)
        white_name = _("White")
        black_name = _("Black")
        p0 = (LOCAL, Human, (WHITE, white_name), white_name)
        p1 = (LOCAL, Human, (BLACK, black_name), black_name)
        game_handler.generalStart(gamemodel, p0, p1, (uri, loader, 0, -1))
Beispiel #6
0
def loadFileAndRun(uri):
    parts = splitUri(uri)
    uri = parts[1] if len(parts) == 2 else parts[0]
    loader = enddir[uri[uri.rfind(".") + 1:]]
    timemodel = TimeModel(0, 0)
    gamemodel = GameModel(timemodel)
    white_name = _("White")
    black_name = _("Black")
    p0 = (LOCAL, Human, (WHITE, white_name), white_name)
    p1 = (LOCAL, Human, (BLACK, black_name), black_name)
    perspective = perspective_manager.get_perspective("games")
    create_task(perspective.generalStart(gamemodel, p0, p1, (uri, loader, 0, -1)))
Beispiel #7
0
def loadFileAndRun(uri):
    if uri in [None, '']:
        return False
    parts = splitUri(uri)
    uri = parts[1] if len(parts) == 2 else parts[0]
    loader = enddir[uri[uri.rfind(".") + 1:]]
    timemodel = TimeModel(0, 0)
    gamemodel = GameModel(timemodel)
    white_name = _("White")
    black_name = _("Black")
    p0 = (LOCAL, Human, (WHITE, white_name), white_name)
    p1 = (LOCAL, Human, (BLACK, black_name), black_name)
    perspective = perspective_manager.get_perspective("games")
    create_task(perspective.generalStart(gamemodel, p0, p1, (uri, loader, 0, -1)))
    return True
Beispiel #8
0
    def on_drag_received(self, widget, context, x, y, selection, target_type,
                         timestamp):
        if target_type == TARGET_TYPE_URI_LIST:
            NOTPROC, PARTIAL, FULL = range(3)
            status = NOTPROC
            uris = selection.get_uris()
            for uri in uris:
                fn, fext = os.path.splitext(uri.lower())
                b = False

                # Chess position
                if fext == '.fen':
                    b = newGameDialog.loadFileAndRun(uri)

                # Shortcut
                elif fext in ['.url', '.desktop']:
                    # Preconf
                    if fext == '.url':
                        sectname = 'InternetShortcut'
                        typeok = True
                    elif fext == '.desktop':
                        sectname = 'Desktop Entry'
                        typeok = False
                    else:
                        assert (False)

                    # Read the shortcut
                    filename = splitUri(uri)[1]
                    with open(filename, 'r') as file:
                        content = file.read()
                    lines = content.replace("\r", '').split("\n")

                    # Extract the link
                    section = False
                    link = ''
                    for item in lines:
                        # Header
                        if item.startswith('['):
                            if section:
                                break
                            section = item.startswith('[%s]' % sectname)
                        if not section:
                            continue

                        # Item
                        if item.startswith('URL='):
                            link = item[4:]
                        if item.startswith('Type=Link') and fext == '.desktop':
                            typeok = True

                    # Load the link
                    if typeok and link != '':
                        create_task(get_internet_game(link))
                        b = True

                # Database
                else:
                    perspective = perspective_manager.get_perspective(
                        "database")
                    perspective.open_chessfile(uri)
                    b = True

                # Update the global status
                if b:
                    if status == NOTPROC:
                        status = FULL
                else:
                    if status != NOTPROC:
                        status = PARTIAL

            # Feedback about the load
            msg = ''
            if status == NOTPROC:
                msg = _(
                    'All the links failed to fetch a relevant chess content.')
                msgtype = Gtk.MessageType.ERROR
            elif status == PARTIAL:
                msg = _('Some links were invalid.')
                msgtype = Gtk.MessageType.WARNING
            if msg != '':
                dlg = Gtk.MessageDialog(mainwindow(),
                                        type=msgtype,
                                        buttons=Gtk.ButtonsType.OK,
                                        message_format=msg)
                dlg.run()
                dlg.destroy()