Пример #1
0
    def upload(self):
        self.ui.upload.setText("Uploading...")

        user_input = {
            'file_list': self.file_list,
            'description': self.ui.description.toPlainText(),
            'file_type': self.get_file_type()
        }

        problem = self.validate(user_input)
        if problem:
            warn("""Please ensure all fields are filled correctly""")
        else:
            print("Uploading", user_input)
            r = post("add_file_list",
                     user=self.email,
                     token=self.token,
                     json=user_input)
            if r is not Exception:
                #self.disable_form()
                info("""The file list was uploaded successfully""")
                #self.uploaded = True
                self.ready_form()
            else:
                self.ui.upload.setText("Upload")
Пример #2
0
 def check_connection(self, quietly=False):
     """ Check connection by sending token to server and requesting list
      of permitted rounds. Then update the form. A warning or info message
      will be shown unless quietly=True. """
     print("check_connection: Checking the connection")
     self.ui.check_connection.setText(self.tr("Checking connection..."))
     error_handler = self.connection_error
     if quietly:
         error_handler = self.connection_error_quiet
     r = get("get_rounds",
             getattr(settings, 'email', None),
             getattr(settings, 'token', None),
             error_handler=error_handler)
     if r is not Exception:
         print("check_connection: connected ok. returned:", r)
         self.connected = True
         self.signed_in = True
         settings.rounds = r['rounds']
         if not quietly:
             if settings.rounds:
                 info(self.tr("You are connected to the server."))
             else:
                 warn(
                     self.
                     tr("You are connected to the server, but do not currently have access to a comparison round."
                        ))
     else:
         print("check_connection: there was a connection problem")
         # (A warning message will be generated by the error handler)
     self.update_form()
Пример #3
0
 def play_video(self, location):
     try:
         os.startfile(os.path.join(settings.file_folder, location))
     except WindowsError as e:
         #TODO: if file is not found then warn it may have been moved
         warn(
             self.
             tr("There was an error starting the video. Please try again."))
         print e
Пример #4
0
 def choose_round(self, permitted):
     """ Cannot continue with the currently selected round. Display a warning
     and go to the settings panel. """
     warn(
         self.
         tr("The selected round is no longer available. Please choose a different one"
            ))
     settings.rounds = permitted
     self.cancel_timer()
     self.open_settings()
Пример #5
0
 def open_file(self, location):
     full_path = os.path.normpath(
         os.path.join(settings.file_folder, location))
     print("Trying to play video at ", full_path)
     try:
         os.startfile(full_path)
     except WindowsError as e:
         #TODO: if file is not found then warn it may have been moved
         warn(
             self.tr(
                 "There was an error opening the file. Please try again."))
         print(e)
Пример #6
0
 def accept(self):
     global settings
     print("accept")
     settings.file_folder = self.ui.file_folder.text()
     settings.output_folder = self.ui.output_folder.text()
     settings.round = self.get_round_id()
     if settings.rounds == []:
         warn(
             self.
             tr("The comparisons application cannot start because you do not \
         have access to any rounds."))
     elif settings.complete():
         print("accept: settings complete, so close")
         settings.save()
         judge_panel.start_judging()
         QDialog.accept(self)
     else:
         warn(self.tr("""Please ensure all settings are configured"""))
Пример #7
0
 def do_next_thing(self, action, detail):
     if action == 'choose round':
         self.choose_round(detail)
     elif action == 'comparison':
         self.set_choice(detail)
         self.ui.submit.setEnabled(True)
         self.ui.play_left.setEnabled(True)
         self.ui.play_right.setEnabled(True)
     elif action == 'end':
         info(self.tr("There are no more comparisons to do in this round."))
         self.ui.submit.setEnabled(False)
         self.ui.play_left.setEnabled(False)
         self.ui.play_right.setEnabled(False)
     else:
         warn(
             self.
             tr("The server returned an action that this application was not able to complete. Action: {}; detail: {}"
                .format(action, detail)))
Пример #8
0
    def submit(self):
        print("Submitted choice")
        submission_time = (datetime.now() -
                           settings.comparison_shown).total_seconds()
        print("Time since comparison was shown is ", submission_time)
        if settings.min_time is not None and submission_time < settings.min_time:
            warn((self.tr(
                "Only {} seconds have passed. You cannot submit your choice until "
                "{} seconds have passed.")).format(int(submission_time),
                                                   settings.min_time))
            return
        if self.ui.radio_left.isChecked():
            choice = "left"
        elif self.ui.radio_right.isChecked():
            choice = "right"
        else:
            warn(self.tr("You have not selected an option"))
            return
            #choice = None
        self.cancel_timer()
        print("Choice is ", choice)
        self.statusBar().showMessage(self.tr("Submitting choice to server"))
        r = post("complete_comparison",
                 settings.email,
                 settings.token,
                 json={
                     "choice": choice,
                     "comparison": self.comparison_id,
                     "round": settings.round
                 })
        self.statusBar().showMessage(self.tr("Submitted choice to server"))
        while True:
            try:
                self.write_output(choice)
                break
            except IOError:
                warn(
                    self.
                    tr("It was not possible to save the comparison data. Please \
                     select a new location for the output folder."))
                #self.settings_panel.show()
                settings.output_folder = self.settings_panel.select_output_folder(
                )
                settings.save()
                self.output = ComparisonsCsv(settings.output_folder)

        if r is not Exception:
            print("submit: response is", r)
            self.do_next_thing(r['action'], r['detail'])
Пример #9
0
 def show_time_warning(self):
     warn(self.say("warning").format(settings.warn_time))
     self.cancel_timer()
Пример #10
0
 def show_time_warning(self):
     warn(
         self.tr("""{} seconds have passed. Please select a video now.""").
         format(settings.warn_time))
     self.cancel_timer()