Пример #1
0
def updateVideoKeyword(conn, keyword):
    if keyword is not None and len(keyword.get()) > 0:
        filetypes = (('Video files', ('.mp4', '.avi', '.mov', '.mpg', '.m4v',
                                      '.flv', '.mkv', '.webm')), )

        filename = askopenfilename(title='Open a video',
                                   initialdir='/',
                                   filetypes=filetypes)

        if filename or len(filename) > 0:
            if os.path.exists('./videos/' +
                              os.path.basename(filename)) is False:
                keyword = literal_eval(keyword.get())

                strVideoPaths = StringVar()

                if keyword[4] == 'None':
                    strVideoPaths.set('[]')
                else:
                    strVideoPaths.set(keyword[4])

                lstVideoPaths = json.loads(strVideoPaths.get())
                lstVideoPaths.append(os.path.basename(filename))
                strVideoPathsToSave = json.dumps(lstVideoPaths)

                # save to database
                cur = conn.cursor()
                cur.execute(
                    f"""UPDATE dict SET videos='{strVideoPathsToSave}' WHERE word='{keyword[0]}' AND POS='{keyword[1]}' AND definition='{keyword[2]}' """
                )
                conn.commit()
                cur.close()

                # save to UI
                listboxVideo.insert(len(lstVideoPaths),
                                    os.path.basename(filename))

                # save to hard disk
                shutil.copy2(filename, './videos')

                # save to selected item
                keyword = list(keyword)
                keyword[3] = json.dumps(lstVideoPaths)
                currentSelectedKeyword.set(tuple(keyword))

                updateCurrentSelectedKeyword(userInput.get())

                if cur.rowcount < 1:
                    messagebox.error("Trạng thái", "Lưu thất bại")
                else:
                    messagebox.showinfo(title='Đã lưu thành công',
                                        message=filename)

            else:
                messagebox.showinfo(title='Tập tin đã tồn tại',
                                    message='./videos/' +
                                    os.path.basename(filename))
Пример #2
0
def updateKoreaKeyword(conn, keyword, newText):
    if keyword is not None and len(keyword.get()) > 0:
        keyword = literal_eval(keyword.get())
        cur = conn.cursor()
        cur.execute(
            f"""UPDATE dict SET korea='{newText}' WHERE word='{keyword[0]}' AND POS='{keyword[1]}' AND definition='{keyword[2]}' """
        )
        conn.commit()
        cur.close()

        updateCurrentSelectedKeyword(userInput.get())

        if cur.rowcount < 1:
            messagebox.error("Trạng thái", "Lưu thất bại")
        else:
            messagebox.showinfo("Trạng thái", "Đã lưu tiếng Hàn thành công")
Пример #3
0
def deleteAudioKeyword(conn, keyword):
    if keyword is not None and len(keyword.get()) > 0:
        filename = listboxAudio.get(listboxAudio.curselection())

        if os.path.exists('./audios/' + filename):
            # Remove in hard disk
            os.remove('./audios/' + filename)

            # Remove on UI
            idx = listboxAudio.get(0, END).index(filename)
            listboxAudio.delete(idx)

            # Remove on database
            keyword = literal_eval(keyword.get())

            strAudioPaths = StringVar()

            if keyword[3] == 'None':
                strAudioPaths.set('[]')
            else:
                strAudioPaths.set(keyword[3])

            lstAudioPaths = json.loads(strAudioPaths.get())
            lstAudioPaths.remove(filename)

            strAudioPathsToSave = json.dumps(lstAudioPaths)

            cur = conn.cursor()
            cur.execute(
                f"""UPDATE dict SET audios='{strAudioPathsToSave}' WHERE word='{keyword[0]}' AND POS='{keyword[1]}' AND definition='{keyword[2]}' """
            )
            conn.commit()
            cur.close()

            # save to selected item
            keyword = list(keyword)
            keyword[3] = json.dumps(lstAudioPaths)
            currentSelectedKeyword.set(tuple(keyword))

            updateCurrentSelectedKeyword(userInput.get())

            if cur.rowcount < 1:
                messagebox.error("Trạng thái", "Xoá thất bại")
            else:
                messagebox.showinfo(title='Đã xoá thành công',
                                    message='./audios' + filename)
Пример #4
0
    def save(self):
        # Verify everything
        if self.vars.passwd1.get() or self.vars.passwd2.get():
            if self.vars.passwd1.get() != self.vars.passwd2.get():
                messagebox.error("Invalid", "Passwords do not match.")

        # Copy everything
        v = self.vars
        try:
            self.client.user_edit(v.userid.get(),
                                  self.auth[0],
                                  self.auth[1],
                                  issuper=v.issuper.get(),
                                  email=v.email.get(),
                                  passwd=v.passwd1.get(),
                                  firstname=v.firstname.get(),
                                  lastname=v.lastname.get())
            messagebox.showinfo("Saved", "Changes successfully saved!")
            App.app.openFrame("ListUsers")
        except Exception as e:
            self.logger.exception("EditUserPage.save")
            messagebox.showerror("Error", str(e))
Пример #5
0
    def draw_fn_composition(self):
        """
            Draw window with function components and total
        """

        self.logger.info('Drawing fit composition for run %s', self.data.id)

        # get top objects
        fit_files = self.bfit.fit_files
        bfit = self.bfit

        # get fit object
        bdfit = self.data

        # get base function
        fn_name = fit_files.fit_function_title.get()

        # get number of components and parameter names
        ncomp = fit_files.n_component.get()
        pnames_single = fit_files.fitter.gen_param_names(fn_name, 1)
        pnames_combined = fit_files.fitter.gen_param_names(fn_name, ncomp)

        if '2' in bdfit.mode:
            fn_single = fit_files.fitter.get_fn(
                fn_name=fn_name,
                ncomp=1,
                pulse_len=bdfit.pulse_s,
                lifetime=bd.life[bfit.probe_species.get()])
            fn_combined = fit_files.fitter.get_fn(
                fn_name=fn_name,
                ncomp=ncomp,
                pulse_len=bdfit.pulse_s,
                lifetime=bd.life[bfit.probe_species.get()])
        else:
            fn_single = fit_files.fitter.get_fn(fn_name=fn_name, ncomp=1)
            fn_combined = fit_files.fitter.get_fn(fn_name=fn_name, ncomp=ncomp)

        # draw in redraw mode
        draw_mode = bfit.draw_style.get()
        bfit.draw_style.set('redraw')

        # draw the data
        bdfit.draw(bfit.get_asym_mode(fit_files), figstyle='fit', color='k')

        # get the fit results
        results = {
            par: bdfit.fitpar.loc[par, 'res']
            for par in pnames_combined
        }

        # draw if ncomp is 1
        if ncomp == 1:
            bfit.draw_style.set('stack')
            bdfit.draw_fit('fit',
                           unique=False,
                           asym_mode=bfit.get_asym_mode(self.bfit.fit_files),
                           label=fn_name)
            self.bfit.draw_style.set(draw_mode)
            return

        # draw baseline
        if 'baseline' in pnames_single:
            bfit.plt.axhline('fit',
                             bdfit.id + '_base',
                             results['baseline'],
                             ls='--',
                             zorder=6)

        # get x pts
        t, a, da = bdfit.asym(bfit.get_asym_mode(fit_files))
        fitx = np.linspace(min(t), max(t), fit_files.n_fitx_pts)

        # get x axis scaling
        if bdfit.mode in bfit.units:
            unit = bfit.units[bdfit.mode]
        else:
            fitxx = fitx

        # draw relative to peak 0
        if self.bfit.draw_rel_peak0.get():

            # get reference
            par = data.fitpar

            if 'peak_0' in par.index: index = 'peak_0'
            elif 'mean_0' in par.index: index = 'mean_0'
            elif 'peak' in par.index: index = 'peak'
            elif 'mean' in par.index: index = 'mean'
            else:
                msg = "No 'peak' or 'mean' fit parameter found. Fit with" +\
                     " an appropriate function."
                self.logger.exception(msg)
                messagebox.error(msg)
                raise RuntimeError(msg)

            ref = par.loc[index, 'res']

            # do the shift
            fitxx = fitx - ref
            fitxx *= unit[0]
            xlabel = 'Frequency Shift (%s)' % unit[1]
            self.logger.info('Drawing as freq shift from peak_0')

        # ppm shift
        elif self.bfit.draw_ppm.get():

            # check div zero
            try:
                fitxx = 1e6 * (
                    fitx - self.bfit.ppm_reference) / self.bfit.ppm_reference
            except ZeroDivisionError as err:
                self.logger.exception(str(msg))
                messagebox.error(str(msg))
                raise err

            self.logger.info('Drawing as PPM shift with reference %s Hz',
                             self.bfit.ppm_reference)
            xlabel = 'Frequency Shift (PPM)'

        else:
            fitxx = fitx * unit[0]

        # draw the combined
        params = [results[name] for name in pnames_combined]

        bfit.plt.plot('fit',
                      bdfit.id + '_comb',
                      fitxx,
                      fn_combined(fitx, *params),
                      unique=False,
                      label='Combined',
                      zorder=5)

        # draw each component
        for i in range(ncomp):

            # get parameters
            params = [results[single+'_%d'%i] \
                        for single in pnames_single if single != 'baseline']

            if 'baseline' in pnames_single:
                params.append(results['baseline'])

            # draw
            bfit.plt.plot('fit',
                          bdfit.id + '_%d' % i,
                          fitxx,
                          fn_single(fitx, *params),
                          unique=False,
                          ls='--',
                          label='%s %d' % (fn_name, i),
                          zorder=6)

        # plot legend
        bfit.plt.legend('fit')

        # reset to old draw mode
        bfit.draw_style.set(draw_mode)
Пример #6
0
 def is_project_names(self):
     project_names = self.database_interface.get_project_names()
     if not project_names:
         messagebox.error("Error", "The project list is empty")
         return False
     return True