def setup_radio_buttons(self):
		'''add atemporal vs temporal choice part'''
		dct = self.user_input

		temporal_processing_flag = BooleanVar()

		# get context dependent frame (regular)
		regular = Raw2Attributes()
		regular_frame = regular.make_frame(self)
		reg_button = Radiobutton(self, text='raw2attributes', value=False, variable=temporal_processing_flag)
		reg_button.grid(row=11, column=0, sticky=W)

		# get context dependent frame (temporal)
		temporal = Raw2Patterns()
		temporal_frame = temporal.make_frame(self)
		tmprl_button = Radiobutton(self, text='raw2patterns', value=True, variable=temporal_processing_flag)
		tmprl_button.grid(row=11, column=1, sticky=W)

		# configure events, invoke one by default
		reg_button.configure(command=lambda : self.set_frame(regular_frame, temporal_frame))
		tmprl_button.configure(command=lambda : self.set_frame(temporal_frame, regular_frame))
		reg_button.invoke() # default
		
		dct['process_temporal'] = temporal_processing_flag
		dct['a-temporal_specific'] = regular.get_values()
		dct['temporal_specific'] = temporal.get_values()
예제 #2
0
    def body(self, parent):
        self.tkVar = IntVar()
        self.tkVar.set(-1)
        tkRb1 = Radiobutton(parent,
                            text="QT Console",
                            variable=self.tkVar,
                            value=0,
                            command=self.radio_select)
        tkRb1.grid(row=0)
        tkRb2 = Radiobutton(parent,
                            text="Notebook",
                            variable=self.tkVar,
                            value=1,
                            command=self.radio_select)
        tkRb2.grid(row=1)

        self.tkDir = StringVar()
        self.tkDir.set(self.settings.notebook_dir)
        self.tkDirEntry = Entry(parent,
                                textvariable=self.tkDir,
                                state="disabled")
        self.tkDirEntry.grid(row=2, column=0)
        self.tkBrowseButton = Button(parent,
                                     text="Browse",
                                     state="disabled",
                                     command=self.get_directory)
        self.tkBrowseButton.grid(row=2, column=1)
예제 #3
0
    def setup_radio_buttons(self):
        '''add atemporal vs temporal choice part'''
        dct = self.user_input

        temporal_processing_flag = BooleanVar()

        # get context dependent frame (regular)
        regular = Raw2Attributes()
        regular_frame = regular.make_frame(self)
        reg_button = Radiobutton(self,
                                 text='raw2attributes',
                                 value=False,
                                 variable=temporal_processing_flag)
        reg_button.grid(row=12, column=0, sticky=W)

        # get context dependent frame (temporal)
        temporal = Raw2Patterns()
        temporal_frame = temporal.make_frame(self)
        tmprl_button = Radiobutton(self,
                                   text='raw2patterns',
                                   value=True,
                                   variable=temporal_processing_flag)
        tmprl_button.grid(row=12, column=1, sticky=W)

        # configure events, invoke one by default
        reg_button.configure(
            command=lambda: self.set_frame(regular_frame, temporal_frame))
        tmprl_button.configure(
            command=lambda: self.set_frame(temporal_frame, regular_frame))
        reg_button.invoke()  # default

        dct['process_temporal'] = temporal_processing_flag
        dct['a-temporal_specific'] = regular.get_values()
        dct['temporal_specific'] = temporal.get_values()
예제 #4
0
class vco_model_win(Toplevel):
    def __init__(self, parent):
        Toplevel.__init__(self)

        img = ImageTk.PhotoImage(file=os.path.join(os.path.dirname(__file__),
                                                   'Icons/LMS8001_PLLSim.png'))
        self.tk.call('wm', 'iconphoto', self._w, img)

        self.resizable(0, 0)

        self.parent = parent
        self.pll = self.parent.pll

        self.initUI()
        center_Window(self)
        self.protocol("WM_DELETE_WINDOW", self.on_Quit)

    def initUI(self):
        self.title("LMS8001-PLL-VCO Model Definition")

        self.style = Style()
        self.style.theme_use("default")

        self.columnconfigure(0, pad=1)
        self.columnconfigure(1, pad=1)
        self.columnconfigure(2, pad=1)
        #self.columnconfigure(3, pad=1, weight=1)

        self.rowconfigure(0, pad=10)
        self.rowconfigure(1, pad=1, weight=1)
        self.rowconfigure(2, pad=1, weight=1)
        self.rowconfigure(3, pad=15, weight=1)
        self.rowconfigure(4, pad=1, weight=1)

        self.VCO_EM = BooleanVar()
        self.VCO_EM.set(self.parent.VCO_EM.get())
        self.cbox_vco_em = Checkbutton(self,
                                       text='Use EM (RLCK) VCO Model',
                                       onvalue=1,
                                       offvalue=0,
                                       variable=self.VCO_EM,
                                       command=self.on_VCO_EM)
        self.cbox_vco_em.grid(row=0, column=0, columnspan=3, sticky=W)

        self.radio_fvco = IntVar()
        self.radio_fvco.set(int(self.parent.VCO_MEAS_FREQ.get()))
        self.radio_fvco_meas = Radiobutton(
            self,
            text='Use Measured VCO Frequency Values in Analysis',
            variable=self.radio_fvco,
            value=1)
        self.radio_fvco_meas.grid(row=1,
                                  column=0,
                                  columnspan=2,
                                  padx=15,
                                  sticky=W + N)
        self.radio_fvco_sim = Radiobutton(
            self,
            text='Use Simulated VCO Frequency Values in Analysis',
            variable=self.radio_fvco,
            value=0)
        self.radio_fvco_sim.grid(row=2,
                                 column=0,
                                 columnspan=2,
                                 padx=15,
                                 sticky=W + N)

        buttonFreq = Button(self,
                            text='Plot Freq',
                            command=self.on_FREQ,
                            width=10)
        buttonFreq.grid(row=3, column=0, sticky=W + E)

        buttonKVCO = Button(self,
                            text='Plot KVCO',
                            command=self.on_KVCO,
                            width=10)
        buttonKVCO.grid(row=3, column=1, sticky=W + E)

        buttonFSTEP = Button(self,
                             text='Plot FSTEP',
                             command=self.on_FSTEP,
                             width=17)
        buttonFSTEP.grid(row=3, column=2, sticky=W + E)

        buttonOK = Button(self, text='OK', command=self.on_OK, width=10)
        buttonOK.grid(row=4, column=0, sticky=W + E)

        buttonQuit = Button(self, text='Quit', command=self.on_Quit, width=17)
        buttonQuit.grid(row=4, column=2, sticky=W + E)

        buttonApply = Button(self,
                             text='Apply',
                             command=self.on_Apply,
                             width=10)
        buttonApply.grid(row=4, column=1, sticky=W + E)

        self.on_VCO_EM()

        #self.pack(fill=BOTH, expand=True)

    def get_vals(self):
        if (self.VCO_EM.get()):
            EM_MODEL = True
            if (self.radio_fvco.get()):
                MEAS_FREQ = True
            else:
                MEAS_FREQ = False
        else:
            EM_MODEL = False
            MEAS_FREQ = False
        return (EM_MODEL, MEAS_FREQ)

    def on_FREQ(self):
        (EM_MODEL, MEAS_FREQ) = self.get_vals()
        vco = lms8001_vco(EM_MODEL=EM_MODEL, MEAS_FREQ=MEAS_FREQ)
        fvco = np.array(np.empty([3, 256]))
        for sel in range(1, 4):
            for freq in range(0, 256):
                fvco[sel - 1, freq] = vco.calcF(sel, freq, 0.6)

        figure(15)
        plt1, = plotsig(range(0, 256),
                        fvco[0, :] / 1.0e9,
                        15,
                        xlabel='$Cap. Bank Code$',
                        ylabel='$F_{VCO} [GHz]$',
                        title='VCO Frequency vs. Cap Bank Code',
                        line_color='black',
                        font_name=self.parent.font_name)
        plt2, = plotsig(range(0, 256),
                        fvco[1, :] / 1.0e9,
                        15,
                        xlabel='$Cap. Bank Code$',
                        ylabel='$F_{VCO} [GHz]$',
                        title='VCO Frequency vs. Cap Bank Code',
                        line_color='blue',
                        font_name=self.parent.font_name)
        plt3, = plotsig(range(0, 256),
                        fvco[2, :] / 1.0e9,
                        15,
                        xlabel='$Cap. Bank Code$',
                        ylabel='$F_{VCO} [GHz]$',
                        title='VCO Frequency vs. Cap Bank Code',
                        line_color='red',
                        font_name=self.parent.font_name)
        setlegend(15, [plt1, plt2, plt3],
                  ['VCO_SEL=1', 'VCO_SEL=2', 'VCO_SEL=3'],
                  font_name=self.parent.font_name)
        show_plots()

    def on_KVCO(self):
        (EM_MODEL, MEAS_FREQ) = self.get_vals()
        vco = lms8001_vco(EM_MODEL=EM_MODEL, MEAS_FREQ=MEAS_FREQ)
        fvco = np.array(np.empty([3, 256]))
        NDIV = np.array(np.empty([3, 256]))
        kvco = np.array(np.empty([3, 256]))
        for sel in range(1, 4):
            for freq in range(0, 256):
                fvco[sel - 1, freq] = vco.calcF(sel, freq, 0.6)
                kvco[sel - 1, freq] = vco.calcKVCO(sel, freq, 0.6)
                NDIV[sel - 1, freq] = 1.0 * fvco[sel - 1, freq] / self.pll.Fref

        for sel in range(1, 4):
            kvco_avg = 1.0
            kvco_over_NDIV_avg = 1.0
            for freq in range(0, 256):
                kvco_avg = kvco_avg * (kvco[sel - 1, freq] / 1.0e6)**(1.0 /
                                                                      256)
                kvco_over_NDIV_avg = kvco_over_NDIV_avg * (
                    (kvco[sel - 1, freq] / 1.0e6) /
                    NDIV[sel - 1, freq])**(1.0 / 256.0)

            print 'VCO_SEL=%d, KVCO_AVG=%.3f MHz/V, KVCO_over_NDIV_AVG=%.3f MHz/V' % (
                sel, kvco_avg, kvco_over_NDIV_avg)
        print ''

        figure(16)
        plt1, = plotsig(fvco[0, :] / 1.0e9,
                        kvco[0, :] / 1.0e6,
                        16,
                        xlabel='$F_{VCO} [GHz]$',
                        ylabel='$K_{VCO} [MHz/V]$',
                        title='VCO Sensitivity vs. Frequency',
                        line_color='black',
                        font_name=self.parent.font_name)
        plt2, = plotsig(fvco[1, :] / 1.0e9,
                        kvco[1, :] / 1.0e6,
                        16,
                        xlabel='$F_{VCO} [GHz]$',
                        ylabel='$K_{VCO} [MHz/V]$',
                        title='VCO Sensitivity vs. Frequency',
                        line_color='blue',
                        font_name=self.parent.font_name)
        plt3, = plotsig(fvco[2, :] / 1.0e9,
                        kvco[2, :] / 1.0e6,
                        16,
                        xlabel='$F_{VCO} [GHz]$',
                        ylabel='$K_{VCO} [MHz/V]$',
                        title='VCO Sensitivity vs. Frequency',
                        line_color='red',
                        font_name=self.parent.font_name)
        setlegend(16, [plt1, plt2, plt3],
                  ['VCO_SEL=1', 'VCO_SEL=2', 'VCO_SEL=3'],
                  font_name=self.parent.font_name)
        show_plots()

    def on_FSTEP(self):
        (EM_MODEL, MEAS_FREQ) = self.get_vals()
        vco = lms8001_vco(EM_MODEL=EM_MODEL, MEAS_FREQ=MEAS_FREQ)
        fstep = np.array(np.empty([3, 255]))
        for sel in range(1, 4):
            for freq in range(0, 255):
                fstep[sel - 1,
                      freq] = vco.calcF(sel, freq + 1, 0.6) - vco.calcF(
                          sel, freq, 0.6)

        figure(17)
        plt1, = plotsig(
            range(0, 255),
            fstep[0, :] / 1.0e6,
            17,
            xlabel='$Cap. Bank Code$',
            ylabel='$F_{STEP} [MHz/V]$',
            title='VCO Frequency Step Between Adjacent Tuning Bands',
            line_color='black',
            font_name=self.parent.font_name)
        plt2, = plotsig(
            range(0, 255),
            fstep[1, :] / 1.0e6,
            17,
            xlabel='$Cap. Bank Code$',
            ylabel='$F_{STEP} [MHz/V]$',
            title='VCO Frequency Step Between Adjacent Tuning Bands',
            line_color='blue',
            font_name=self.parent.font_name)
        plt3, = plotsig(
            range(0, 255),
            fstep[2, :] / 1.0e6,
            17,
            xlabel='$Cap. Bank Code$',
            ylabel='$F_{STEP} [MHz/V]$',
            title='VCO Frequency Step Between Adjacent Tuning Bands',
            line_color='red',
            font_name=self.parent.font_name)
        setlegend(17, [plt1, plt2, plt3],
                  ['VCO_SEL=1', 'VCO_SEL=2', 'VCO_SEL=3'],
                  font_name=self.parent.font_name)
        show_plots()

    def on_VCO_EM(self):
        if (self.VCO_EM.get()):
            self.radio_fvco_meas.config(state='enabled')
            self.radio_fvco_sim.config(state='enabled')
        else:
            self.radio_fvco_meas.config(state='disabled')
            self.radio_fvco_sim.config(state='disabled')

    def on_OK(self):
        self.on_Apply()
        self.on_Quit()

    def on_Quit(self):
        self.parent.vco_model_win = None
        self.destroy()

    def on_Apply(self):
        (EM_MODEL, MEAS_FREQ) = self.get_vals()
        self.parent.VCO_EM.set(EM_MODEL)
        self.parent.VCO_MEAS_FREQ.set(MEAS_FREQ)

        self.pll.vco = lms8001_vco(SEL=2,
                                   FREQ=128,
                                   EM_MODEL=EM_MODEL,
                                   MEAS_FREQ=MEAS_FREQ)
예제 #5
0
    def __init__(self, master):

        plat = platform.system()
        if plat == 'Darwin':

            try:
                system(
                    '''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' '''
                )
                print("Trying to force Python window to the front on macOS")
            except:
                system(
                    '''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python2.7" to true' '''
                )
                print(
                    "Trying to force Python 2.7 window to the front on macOS")

        self.master = master
        frame = Frame(master)
        frame.config(background="#dcdcdc")
        frame.config(borderwidth=5, relief=GROOVE)
        frame.place(relx=0.5, rely=0.5, anchor=CENTER)
        master.title('Verify v. 0.2')  #   Main frame title
        master.config(background="#dcdcdc")
        master.geometry('820x750')
        menubar = Menu(master)
        """statmenu = Menu(menubar,tearoff=0)
        statmenu.add_command(label="Fieller", command=self.on_fieller)
        
        statmenu.rantest = Menu(statmenu)
        statmenu.rantest.add_command(label="Continuously variable data", command=self.on_rantest_continuous)
        statmenu.rantest.add_command(label="Binomial data (each result= yes or no)", command=self.on_rantest_binomial)
        statmenu.add_cascade(label="Randomisation test", menu=statmenu.rantest)
        
        statmenu.add_command(label="Help", command=self.on_help, state=DISABLED)
        statmenu.add_command(label="Quit", command=master.quit)
        
        menubar.add_cascade(label="Statistical Tests", menu=statmenu)
        master.config(menu=menubar)
      """
        b3 = Button(frame,
                    text="Load traces",
                    width=20,
                    command=self.callback3,
                    highlightbackground="#dcdcdc")
        b3.grid(row=0, column=0, columnspan=2, padx=10, pady=8, sticky=W)

        self.b4 = Button(frame,
                         text="Verify traces variance",
                         width=20,
                         state=DISABLED,
                         command=self.callback2,
                         highlightbackground="#dcdcdc")
        self.b4.grid(row=1, padx=10, pady=8, column=0, columnspan=2)

        self.b5 = Button(frame,
                         text="Plot Variance vs. current",
                         width=20,
                         state=DISABLED,
                         command=self.callback5,
                         highlightbackground="#dcdcdc")
        self.b5.grid(row=2, padx=10, pady=8, column=0, columnspan=2)

        #need to remove Pack to use separator
        s1 = Separator(frame, orient=VERTICAL)
        s1.grid(column=2, row=0, rowspan=40, pady=10, sticky=N + W + S)

        self.input_filename_label = StringVar()
        self.input_filename_label.set("No data loaded yet")
        self.l1 = Label(frame,
                        textvariable=self.input_filename_label,
                        width=40,
                        bg="#dcdcdc")
        self.l1.grid(row=0, column=2, columnspan=4, pady=5)

        Label(frame, text="Baseline range (pts)",
              bg="#dcdcdc").grid(row=1,
                                 column=2,
                                 columnspan=2,
                                 pady=5,
                                 sticky=E)
        self.br = Entry(frame,
                        justify=CENTER,
                        width=5,
                        highlightbackground="#dcdcdc")
        self.br.grid(row=1, column=4, sticky=W, pady=5)
        self.br.insert(END, '0, 50')

        Label(frame, text="Decimation", bg="#dcdcdc").grid(row=2,
                                                           column=2,
                                                           columnspan=2,
                                                           pady=5,
                                                           sticky=E)
        self.de = Entry(frame,
                        justify=CENTER,
                        width=5,
                        highlightbackground="#dcdcdc")
        self.de.grid(row=2, column=4, sticky=W, pady=5)
        self.de.insert(END, '1')

        Label(frame, text="Unitary current amplitude (pA)",
              bg="#dcdcdc").grid(row=3,
                                 column=2,
                                 columnspan=2,
                                 pady=5,
                                 sticky=E)
        self.ua = Entry(frame,
                        justify=CENTER,
                        width=5,
                        highlightbackground="#dcdcdc")
        self.ua.grid(row=3, column=4, sticky=W, pady=5)
        self.ua.insert(END, '1')
        #default unitary current is 1 pA

        Label(frame, text="Output filename", bg="#dcdcdc").grid(row=4,
                                                                column=2,
                                                                columnspan=2,
                                                                pady=5)

        style = Style()
        style.theme_use('clam')
        style.configure("w.TRadiobutton",
                        padding=2,
                        background="#dcdcdc",
                        foreground="black",
                        width=15)
        style.configure("TRadiobutton",
                        padding=2,
                        background="#dcdcdc",
                        foreground="black",
                        width=8)

        MODES = [("verified.txt", 3), ("Save as...", 2), ("v_[infile]", 1),
                 ("[date:time]_v_[infile]", 0)]

        self.v = IntVar()
        self.v.set(0)  # initialize

        #note this is the ttk radiobutton, the tk one doesn't select at first
        for text, mode in MODES:
            b = Radiobutton(frame,
                            text=text,
                            command=self.callback_fname,
                            variable=self.v,
                            value=mode,
                            state=NORMAL)
            b.grid(row=5, padx=10, column=mode + 2, sticky=E)

        #the last button in the loop (0) is the wide one, so gets the wide style.
        b.configure(style='w.TRadiobutton')

        self.traceHost = Frame(frame)
        self.traceHost.grid(row=15, column=0, columnspan=3)
        self.p = Plot(self.traceHost)

        self.Host2D = Frame(frame)
        self.Host2D.grid(row=15, column=3, columnspan=3)
        self.pcv = Plot(self.Host2D)

        s2 = Separator(frame)
        s2.grid(row=25, columnspan=6, sticky=S + E + W)

        message = Message(frame,
                          text=self.introduction,
                          width=800,
                          font=("Courier", 12),
                          bg="#dcdcdc")
        message.grid(row=26, rowspan=8, columnspan=6, sticky=EW)

        s3 = Separator(frame)
        s3.grid(row=35, columnspan=6, sticky=E + W)

        version_text = "https://github.com/aplested/verify\nPython version:\t" + sys.version.replace(
            "\n", "\t")
        version = Message(frame,
                          width=800,
                          text=version_text,
                          justify=LEFT,
                          background="#dcdcdc",
                          font=("Courier", 12))
        version.grid(row=36, columnspan=5, sticky=EW)

        self.b6 = Button(frame,
                         text="Quit",
                         command=master.quit,
                         width=10,
                         highlightbackground="#dcdcdc")
        self.b6.grid(row=36, padx=10, pady=8, column=5, sticky=W)
예제 #6
0
        class A_DWI:
            def __init__(self, container, frame, label='', text='', row=0, column=0):
                self.container = container
                self.is_b0 = BooleanVar(container.parent)
                self.is_dw = BooleanVar(container.parent)
                self.column = column
                self.direction = StringVar(container.parent)

                self.label_from = Label(frame, text='from')
                self.text_from = Entry(frame)
                self.text_from.insert(0, text)
                self.button_file_from = Button(frame, text='...', command=lambda:filenameDialog_text(self.text_from))
                self.button_rm = Button(frame, text='remove', command=self.click_remove)
                self.radio_ap = Radiobutton(frame, text='AP', variable=self.direction, value='AP', command=self.set_direction)
                self.radio_pa = Radiobutton(frame, text='PA', variable=self.direction, value='PA', command=self.set_direction)

                self.label_to = Label(frame, text='to')
                self.text_to = Entry(frame)
                #self.text_to.insert(0, text)
                self.button_file_to = Button(frame, text='Gen', command=self.set_filename_to)
                self.check_b0 = Checkbutton(frame, text='B0',   variable=self.is_b0)
                self.check_dw = Checkbutton(frame, text='DWI',  variable=self.is_dw)

                self.button_up = Button(frame, text='up', width=3, command=self.click_up)
                self.button_dn = Button(frame, text='down', width=3, command=self.click_dn)

                self.row = -1
                self.change_row(row)
                if text != '':
                    self.set_appa()
                    self.set_filename_to()

            def prefix(self):
                return self.container.parent.prefix()

            def set_direction(self):
                pass

            def get_dwi_filenames(self):
                '''
                :return: [('from', 'to'), ('from', 'to')]
                '''
                filename_from = self.text_from.get()
                filename_to = self.text_to.get()
                if self.is_dw.get():
                    rtn = [ [filename_from, filename_to] ]
                    filename_b_from = filename_wo_ext(filename_from)
                    filename_b_to = filename_wo_ext(filename_to)
                    rtn.append( [filename_b_from+'.bval', filename_b_to+'.bval'] )
                    rtn.append( [filename_b_from+'.bvec', filename_b_to+'.bvec'] )
                    return rtn
                return []

            def get_b0_filename(self):
                '''
                :return: [('from', 'to')]
                '''
                filename_from = self.text_from.get()
                filename_to = self.text_to.get()
                ext = extname(filename_to)
                if self.is_b0.get():
                    if self.is_dw.get():
                        filename_to = '%s_B0%s' % (filename_wo_ext(filename_to), ext)
                    return [ [filename_from, filename_to] ]
                return []

            def set_appa(self):
                filename_from = self.text_from.get()
                basename_from = os.path.basename(filename_from)
                basename_b_from = filename_wo_ext(basename_from)
                if 'pa' in basename_b_from.lower():
                    self.direction.set('PA')
                elif 'ap' in basename_b_from.lower():
                    self.direction.set('AP')
                else:
                    pass

            def set_filename_to(self, middle=None):
                filename_from = self.text_from.get()
                basename_from = os.path.basename(filename_from)
                number = os.path.dirname(filename_from).split('/')[-1].split('_')[0]
                if number == '':
                    number = str(self.row)
                else:
                    try:
                        int(number)
                    except:
                        number = str(self.row)


                ext = extname(basename_from)
                intermediate = self.direction.get()
                if intermediate == '':
                    intermediate = 'DWI'

                if self.is_b0.get() and not self.is_dw.get():
                    intermediate += '_B0'

                self.text_to.delete(0, len(self.text_to.get()))
                self.text_to.insert(0, '%s%s_%s%s' % (self.prefix(), number, intermediate, ext))

            def change_row(self, row):
                if self.row == row:
                    return
                self.row = row
                i = 2*row
                j = self.column
                j += 0; self.button_up.grid(row=i, column=j)
                j += 1; self.label_from.grid(row=i, column=j)
                j += 1; self.text_from.grid(row=i, column=j, sticky=EW)
                j += 1; self.button_file_from.grid(row=i, column=j)
                j += 1; self.button_rm.grid(row=i, column=j)
                j += 1; self.radio_ap.grid(row=i, column=j)
                j += 1; self.radio_pa.grid(row=i, column=j)
                i += 1
                j = 0
                j += 0; self.button_dn.grid(row=i, column=j)
                j += 1; self.label_to.grid(row=i, column=j)
                j += 1; self.text_to.grid(row=i, column=j, sticky=EW)
                j += 1; self.button_file_to.grid(row=i, column=j)
                j += 1
                j += 1; self.check_b0.grid(row=i, column=j)
                j += 1; self.check_dw.grid(row=i, column=j)

            def click_remove(self):
                self.container.remove(self.row)

                self.button_up.destroy()
                self.label_from.destroy()
                self.text_from.destroy()
                self.button_file_from.destroy()
                self.button_rm.destroy()
                self.radio_ap.destroy()
                self.radio_pa.destroy()
                self.button_dn.destroy()
                self.label_to.destroy()
                self.text_to.destroy()
                self.button_file_to.destroy()
                self.check_b0.destroy()
                self.check_dw.destroy()

            def click_up(self):
                self.container.up(self.row)
            def click_dn(self):
                self.container.dn(self.row)
예제 #7
0
class ConvertSPC:
    def __init__(self, master):
        self.master = master
        master.title("Convert SPC files")

        mf = Frame(master, padding="10")
        mf.grid(column=0, row=0, sticky=(N, W, E, S))
        mf.columnconfigure(0, weight=1)
        mf.rowconfigure(0, weight=1)
        self.message = "Enter folder containing *.SPC files"
        self.label_text = StringVar()
        self.folder = StringVar()
        self.output_fmt = StringVar()

        self.label_text.set(self.message)

        self.label = Label(mf, textvariable=self.label_text)
        self.folder_label = Label(mf, text="Folder")
        self.output_fmt_label = Label(mf, text="Output Format")

        self.fmt_txt = Radiobutton(mf, text="TXT", variable=self.output_fmt, value='txt')
        self.fmt_csv = Radiobutton(mf, text="CSV", variable=self.output_fmt, value='csv')
        self.folder_entry = Entry(mf, textvariable=self.folder)

        self.sel_foler = Button(mf, text="Browse", command=self.ask_dir)
        self.convert_btn = Button(mf, text="Convert", command=self.convert)

        # map on grid
        self.label.grid(row=0, column=0, columnspan=4, sticky=W + E)
        self.folder_label.grid(row=1, column=0, sticky=E)
        self.output_fmt_label.grid(row=2, column=0, sticky=E)
        self.folder_entry.grid(row=1, column=1, columnspan=2, sticky=W + E)
        self.fmt_txt.grid(row=2, column=1, sticky=W)
        self.fmt_csv.grid(row=2, column=2, sticky=W)
        self.sel_foler.grid(row=1, column=3, sticky=W)
        self.convert_btn.grid(row=3, column=1, columnspan=2, sticky=W + E)

        for child in mf.winfo_children():
            child.grid_configure(padx=5, pady=5)

    def convert(self):
        self.fol_val = str(self.folder.get())
        self.fmt_val = str(self.output_fmt.get())
        print("About to convert {} with {} ext".format(self.fol_val, self.fmt_val))

        if self.fmt_val == 'txt':
            exten = '.txt'
            delim = '\t'
        else:
            # defaults
            exten = '.csv'
            delim = ','

        flist = []

        # only directory here
        ffn = os.path.abspath(self.fol_val)
        for f in os.listdir(ffn):
            flist.append(os.path.join(ffn, f))

        # process files
        for fpath in flist:
            if fpath.lower().endswith('spc'):

                foutp = fpath[:-4] + exten
                try:
                    print(fpath, end=' ')
                    f = spc.File(fpath)
                    f.write_file(foutp, delimiter=delim)
                    print('Converted')
                except:
                    print('Error processing %s' % fpath)
            else:
                print('%s not spc file, skipping' % fpath)

    def ask_dir(self):
        self.folder.set(tkFileDialog.askdirectory())