Exemple #1
0
    def on_remote_game_activate(self, widget):
        # Ask the user for an URL
        widgets = gamewidget.getWidgets()
        url_dialog = widgets["url_path_dialog"]
        widgets["url_edit"].set_text('')
        widgets["url_edit"].grab_focus()
        answer = url_dialog.run()
        url_dialog.hide()
        if answer != Gtk.ResponseType.OK.real:
            return

        # Download the game
        url = widgets["url_edit"].get_text().strip()
        if len(url) == 0:
            return
        remdata = get_internet_game_as_pgn(url)
        if remdata is None:
            dlg = Gtk.MessageDialog(
                mainwindow(),
                type=Gtk.MessageType.ERROR,
                buttons=Gtk.ButtonsType.OK,
                message_format=
                _("The provided link does not lead to a meaningful chess content."
                  ))
            dlg.run()
            dlg.destroy()
            return

        # Load the game
        newGameDialog.loadPgnAndRun(remdata)
Exemple #2
0
 def on_remote_game_activate(self, widget):
     url = getUserTextDialog(mainwindow(), _('Load a remote game'), _('Paste the link to download:'))
     if url is not None:
         remdata = get_internet_game_as_pgn(url.strip())
         if remdata is None:
             dlg = Gtk.MessageDialog(mainwindow(),
                                     type=Gtk.MessageType.ERROR,
                                     buttons=Gtk.ButtonsType.OK,
                                     message_format=_("The provided link does not lead to a meaningful chess content."))
             dlg.run()
             dlg.destroy()
         else:
             newGameDialog.loadPgnAndRun(remdata)
Exemple #3
0
    def executeTest(self, cp, links):
        # Check
        if cp is None or links is None or len(links) == 0:
            return
        print("\n%s" % cp.get_description())
        if not cp.is_enabled():
            print('- Skipping disabled chess provider')

        # Pick one link only to not overload the remote server
        url, expected = random.choice(links)
        print('- Target link : %s' % url)
        print('- Expecting data : %s' % expected)

        # Download link
        data = get_internet_game_as_pgn(url)
        ok = data is not None
        print('- Fetched data : %s' % ok)
        self.assertEqual(ok, expected)
Exemple #4
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 != '':
                        pgn = get_internet_game_as_pgn(link)
                        b = newGameDialog.loadPgnAndRun(pgn)

                # 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()