示例#1
0
 def setUp(self):
     self.app = wx.App()
     self.frame = magic_gui.MainFrame(PROJECT_WD,
                                      name="best frame ever",
                                      dmodel=DMODEL)
     self.frame.get_wd_data()
     self.pnl = self.frame.GetChildren()[0]
示例#2
0
    def on_btn_upload(self, event):
        outstring = "upload_magic.py"
        print("-I- running python script:\n %s" % (outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.Yield()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
                dir_path=self.WD,
                vocab=self.contribution.vocab,
                contribution=self.contribution)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(
                dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload.\n Your file: {}  was generated in MagIC Project Directory.\nDrag and drop this file in the MagIC database.".format(
                os.path.split(res)[1])
            dlg = wx.MessageDialog(self,
                                   caption="Saved",
                                   message=text,
                                   style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/message window for details".format(
                error_message)
            dlg = wx.MessageDialog(self,
                                   caption="Error",
                                   message=text,
                                   style=wx.OK)

        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()

        if self.data_model_num == 3:
            from programs import magic_gui
            self.Disable()
            self.Hide()
            self.magic_gui_frame = magic_gui.MainFrame(
                self.WD,
                dmodel=self.data_model,
                title="Validations",
                contribution=self.contribution)

            self.magic_gui_frame.validation_mode = ['specimens']
            self.magic_gui_frame.failing_items = all_failing_items
            self.magic_gui_frame.change_dir_button.Disable()
            self.magic_gui_frame.Centre()
            self.magic_gui_frame.Show()
            self.magic_gui_frame.highlight_problems(has_problems)
            #
            # change name of upload button to 'exit validation mode'
            self.magic_gui_frame.bSizer2.GetStaticBox().SetLabel(
                'return to main GUI')
            self.magic_gui_frame.btn_upload.SetLabel("exit validation mode")
            # bind that button to quitting magic gui and re-enabling Pmag GUI
            self.magic_gui_frame.Bind(wx.EVT_BUTTON, self.on_end_validation,
                                      self.magic_gui_frame.btn_upload)
示例#3
0
    def on_btn_upload(self, event):
        """
        Try to run upload_magic.
        Open validation mode if the upload file has problems.
        """
        if not self.check_for_uncombined_files():
            return
        outstring = "upload_magic.py"
        print("-I- running python script:\n %s" % (outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.SafeYield()
        self.contribution.tables['measurements'].add_measurement_names()
        if self.data_model_num == 3:
            res, error_message, has_problems, all_failing_items = ipmag.upload_magic3(
                dir_path=self.WD,
                vocab=self.contribution.vocab,
                contribution=self.contribution)
        if self.data_model_num == 2:
            res, error_message, errors = ipmag.upload_magic(
                dir_path=self.WD, data_model=self.er_magic.data_model)
            del wait

        if res:
            text = "You are ready to upload!\n{} was generated in {}".format(
                os.path.split(res)[1],
                os.path.split(res)[0])
            dlg = pw.ChooseOne(self, "Go to MagIC for uploading",
                               "Not ready yet", text, "Saved")
            del wait
            #dlg = wx.MessageDialog(self, caption="Saved", message=text, style=wx.OK)
        else:
            text = "There were some problems with the creation of your upload file.\nError message: {}\nSee Terminal/message window for details".format(
                error_message)
            dlg = wx.MessageDialog(self,
                                   caption="Error",
                                   message=text,
                                   style=wx.OK)

        dlg.Centre()
        result = dlg.ShowModal()
        if result == wx.ID_OK:
            dlg.Destroy()
        if result == wx.ID_YES:
            pw.on_database_upload(None)

        if self.data_model_num == 3:
            if not res:
                from programs import magic_gui
                self.Disable()
                self.Hide()
                self.magic_gui_frame = magic_gui.MainFrame(
                    self.WD,
                    dmodel=self.data_model,
                    title="Validations",
                    contribution=self.contribution)

                self.magic_gui_frame.validation_mode = ['specimens']
                self.magic_gui_frame.failing_items = all_failing_items
                self.magic_gui_frame.change_dir_button.Disable()
                self.magic_gui_frame.Centre()
                self.magic_gui_frame.Show()
                self.magic_gui_frame.highlight_problems(has_problems)
                #
                # change name of upload button to 'exit validation mode'
                self.magic_gui_frame.bSizer2.GetStaticBox().SetLabel(
                    'return to main GUI')
                self.magic_gui_frame.btn_upload.SetLabel(
                    "exit validation mode")
                # bind that button to quitting magic gui and re-enabling Pmag GUI
                self.magic_gui_frame.Bind(wx.EVT_BUTTON,
                                          self.on_end_validation,
                                          self.magic_gui_frame.btn_upload)
示例#4
0
    def on_btn_upload(self, event):
        """
        Try to run upload_magic.
        Open validation mode if the upload file has problems.
        """
        if not self.check_for_uncombined_files():
            return
        outstring = "upload_magic.py"
        print("-I- running python script:\n %s" % (outstring))
        wait = wx.BusyInfo("Please wait, working...")
        wx.SafeYield()
        success_responses = ['200', 200, '201', 201, True]
        if 'measurements' in self.contribution.tables:
            self.contribution.tables['measurements'].add_measurement_names()
        upload_file, val_response, dummy1, dummy2 = ipmag.upload_magic(
            concat=False, input_dir_path=self.WD, dir_path=self.WD)
        del wait
        if val_response == "no 3.0 files found, upload file not created":
            pw.simple_warning(
                "No 3.0 files were found in your directory, so no upload could be created!"
            )
            return
        status = val_response['status']
        if not status:
            pw.simple_warning(
                "Oops, something went wrong with validating on the server.\n{}\nTry again later or submit a bug report."
                .format(val_response['warnings']))
            return
        validation_errors = val_response['validation']
        if (not validation_errors['warnings']) and (
                not validation_errors['errors']):
            text = "You are ready to upload!\n{} was generated in {}".format(
                os.path.split(upload_file)[1], self.WD)
            dlg = pw.ChooseOne(self, "Go to MagIC for uploading",
                               "Not ready yet", text, "Saved")

            dlg.Centre()
            result = dlg.ShowModal()
            if result == wx.ID_OK:
                dlg.Destroy()
            if result == wx.ID_YES:
                pw.on_database_upload(None)
            return

        # there were problems, so display validation
        text = "There were some problems with the creation of your upload file.\nSee Terminal/message window for details"
        dlg = wx.MessageDialog(self,
                               caption="Error",
                               message=text,
                               style=wx.OK)
        dlg.Centre()
        result = dlg.ShowModal()

        # TODO: get the error-y business formatted into a dict of lists of dicts
        from programs import magic_gui
        self.Disable()
        self.Hide()
        self.magic_gui_frame = magic_gui.MainFrame(
            self.WD,
            dmodel=self.data_model,
            title="Validations",
            contribution=self.contribution,
            errors=validation_errors['errors'])
        self.magic_gui_frame.Centre()
        self.magic_gui_frame.Show()
        self.magic_gui_frame.highlight_problems()
        # bind that button to quitting magic gui and re-enabling Pmag GUI
        self.magic_gui_frame.Bind(wx.EVT_BUTTON, self.on_end_validation,
                                  self.magic_gui_frame.return_btn)
        # do binding so that closing/quitting re-opens the main frame
        self.magic_gui_frame.Bind(wx.EVT_CLOSE, self.on_end_validation)
        # this makes it work with only the validation window open
        self.magic_gui_frame.Bind(
            wx.EVT_MENU,
            lambda event: self.menubar.on_quit(event, self.magic_gui_frame),
            self.magic_gui_frame.menubar.file_quit)
        # this makes it work if an additional grid is open
        self.Bind(
            wx.EVT_MENU,
            lambda event: self.menubar.on_quit(event, self.magic_gui_frame),
            self.magic_gui_frame.menubar.file_quit)