def __init__(self, *args, **kwargs): Tk.__init__(self, *args, **kwargs) self.geometry("550x550+450+150") # the container is where we'll stack a bunch of frames # on top of each other, then the one we want visible # will be raised above the others container = Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) self.protocol('WM_DELETE_WINDOW', self.leaveCallback) # root is your root window self.frames = {} for F in (StartPage, AboutPage, CreateServer, FindServer, ChooseType, GameWindow): page_name = F.__name__ frame = F(container, self) self.frames[page_name] = frame # put all of the pages in the same location; # the one on the top of the stacking order # will be the one that is visible. frame.grid(row=0, column=0, sticky="nsew") self.show_frame("StartPage")
def initUI(self): self.parent.title('Prepare DWI') frm_output = Frame(self) frm_button = Frame(self) frm_list = VerticalScrolledFrame(self) self.frm_list_sub = frm_list.interior self.lst_dwi = self.List_DWI(self, self.frm_list_sub) i = 0 frm_output.grid(row=i, column=0, columnspan=6, sticky=EW) frm_output.grid_columnconfigure(1, weight=1) ii = 0; Label(frm_output, text='Subject').grid(row=ii, column=0) self.txt_subject = Entry(frm_output); self.txt_subject.grid(row=ii, column=1, sticky=EW) self.txt_subject.insert(0, self.subject_name) ii += 1; Label(frm_output, text='Output Directory').grid(row=ii, column=0) self.txt_output = Entry(frm_output); self.txt_output.grid(row=ii, column=1, sticky=EW) self.txt_output.insert(0, self.output_dir) btn_output = Button(frm_output, text='...', command=lambda:dirnameDialog_text(self.txt_output)); btn_output.grid(row=ii, column=2) ii += 1; Label(frm_output, text='Merged B0').grid(row=ii, column=0) self.txt_output_b0 = Entry(frm_output); self.txt_output_b0.grid(row=ii, column=1, sticky=EW) btn_output_b0 = Button(frm_output, text='Gen', command=lambda:self.lst_dwi.fn_b0(self.txt_output_b0)); btn_output_b0.grid(row=ii, column=2) ii += 1; Label(frm_output, text='Merged DWI').grid(row=ii, column=0) self.txt_output_dw = Entry(frm_output); self.txt_output_dw.grid(row=ii, column=1, sticky=EW) btn_output_dw = Button(frm_output, text='Gen', command=lambda:self.lst_dwi.fn_dw(self.txt_output_dw)); btn_output_dw.grid(row=ii, column=2) i += ii i += 1 frm_button.grid(row=i, column=0, columnspan=6, sticky=EW) ii = 0 btn_add = Button(frm_button, text='ADD Nifti1 file', command=self.add_dwi_list); btn_add.grid(row=ii, column=0) btn_run = Button(frm_button, text='Run', command=self.run); btn_run.grid(row=ii, column=1) i += ii i += 1 i_frm_list = i self.frm_list_sub.grid_columnconfigure(2, weight=1) frm_list.grid(row=i, column=0, columnspan=6, sticky=NSEW) self.grid_rowconfigure(i_frm_list, weight=1, minsize=20) #self.lst_dwi.add_one('test1') #self.lst_dwi.add_one('test2') self.grid_columnconfigure(0, weight=1) ni = i + 1 #for i in range(i_frm_list, ni): # self.grid_rowconfigure(i, weight=1, minsize=20) self.pack(fill=BOTH, expand=True)
def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) # the container is where we'll stack a bunch of frames # on top of each other, then the one we want visible # will be raised above the others container = Frame(self) container.pack(side="top", fill="both", expand=True) container.grid_rowconfigure(0, weight=1) container.grid_columnconfigure(0, weight=1) menubar = tk.Menu(container) self.config(menu=menubar) fileMenu = tk.Menu(menubar, tearoff=False) fileMenu.add_command(label="Test Connect", command=self.TestConnection) fileMenu.add_command(label="Exit", command=self.onExit) menubar.add_cascade(label="Connect", menu=fileMenu) aboutMenu = tk.Menu(menubar, tearoff=False) aboutMenu.add_command(label="About", command=self.About) menubar.add_cascade(label="Help", menu=aboutMenu) self.frames = {} self.titles = {} for F in (StartPage, Test_ZebraScanner, Test_Wifi, Test_GPS3G, Test_Cepas): page_name = F.__name__ title_name = F._title frame = F(parent=container, controller=self) self.frames[page_name] = frame self.titles[page_name] = title_name # put all of the pages in the same location; # the one on the top of the stacking order # will be the one that is visible. frame.grid(row=0, column=0, sticky="nsew") frame = self.show_frame("StartPage") frame._disable_test()
Button(mainframe, text="Add", command=add_requirement).grid(column=2, row=9, sticky=(N,W)) #text area #txt_frm = Frame(mainframe, width=200, height=100) #larger txt_frm = Frame(mainframe, width=500, height=100) #smaller txt_frm.pack(fill="both", expand=True) #for a smaller frame txt_frm.pack_propagate(0) txt_frm.grid(column=0, columnspan= 2, row=9, sticky=(W,E)) # ensure a consistent GUI size txt_frm.grid_propagate(False) # implement stretchability txt_frm.grid_rowconfigure(0, weight=1) txt_frm.grid_columnconfigure(0, weight=1) # create a Text widget t = Text(txt_frm, borderwidth=3, relief="sunken") t.config(font=("consolas", 12), undo=True, wrap='word') t.grid(row=0, column=0, sticky="nsew", padx=2, pady=2) # create a Scrollbar and associate it with txt scrollb = Scrollbar(txt_frm, command=t.yview) scrollb.grid(row=0, column=1, sticky='nsew') t['yscrollcommand'] = scrollb.set t.pack() #########The frame below is the one where completeness values are stored
class CreateMask(Frame): def __init__(self, parent, filename=None, dirname=None, mask4d=False, obj_return_value=None): Frame.__init__(self, parent) self.parent = parent self.obj_return_value = obj_return_value if dirname is None: self.dirname = '' else: self.dirname = dirname if filename is None or not os.path.isfile(filename): if dirname is not None: filename = tkFileDialog.askopenfilename(initialdir=dirname) else: filename = tkFileDialog.askopenfilename() if not os.path.isfile(filename): parent.destroy() return self.readImage(filename) _, _, filename_mask = create_mask.set_filenames(filename) self.filename_mask = filename_mask + '.nii.gz' if mask4d: if len(self.shape) > 3: self.mask_base = np.zeros(self.shape, dtype=np.int8) self.mask = self.mask_base[:, :, :, 0] self.mask4d = True else: self.mask = np.zeros(self.shape[:3], dtype=np.int8) self.mask4d = False self.volume = 0 self.initUI() self.modifyUI() self.drawSlice() def initUI(self): self.frame_bottom = Frame(self) self.frame_main = Frame(self) def modifyUI(self): frame_bottom = self.frame_bottom frame_main = self.frame_main self.sliceView = [ ImshowMplCanvas(frame_main) for k in range(self.shape[2]) ] self.sliceSpin = [ MySpinBox(frame_main, k) for k in range(self.shape[2]) ] #Layout self.parent.title('CreateMask') max_spin = 0 if self.mask4d: max_spin = self.shape[3] - 1 self.spin_volume = Spinbox(frame_bottom, from_=0, to=max_spin, increment=1, command=self.change_volume, width=8) self.reset_box(self.spin_volume, 0) buttonMask = Button(frame_bottom, text='B0 from Bval...', command=self.createBaseImage) buttonMaskCreate = Button(frame_bottom, text='Create', command=self.createMaskAll) buttonSave = Button(frame_bottom, text='Save', command=self.saveMask) self.drawmask = BooleanVar() buttonDrawMask = Checkbutton(frame_bottom, text='Draw Mask', variable=self.drawmask, command=self.drawSlice) num_col = 3 num_row = 6 for col in range(self.shape[2] / num_row): for k in range(num_row): ind = col * num_row + k if ind >= self.shape[2]: break self.sliceView[ind].get_tk_widget().grid(row=k, column=col * num_col, sticky=NSEW) self.sliceSpin[ind].grid(row=k, column=col * num_col + 1) self.frame_main.grid_columnconfigure(col * num_col, weight=1) for k in range(num_row): self.frame_main.grid_rowconfigure(k, weight=1) self.spin_volume.grid(row=0, column=0) buttonMask.grid(row=0, column=1) buttonMaskCreate.grid(row=0, column=2) buttonSave.grid(row=0, column=3) buttonDrawMask.grid(row=0, column=5) frame_bottom.pack(side=BOTTOM) frame_main.pack(fill=BOTH, expand=TRUE) self.pack(fill=BOTH, expand=True) def change_volume(self): if not self.mask4d: return self.volume = int(self.spin_volume.get()) self.data = self.data_base[:, :, :, self.volume] self.mask = self.mask_base[:, :, :, self.volume] self.drawSlice() def saveMask(self): print 'save mask to %s' % self.filename_mask if self.mask4d: img_out = nib.Nifti1Image(self.mask_base, self.img.get_affine(), self.img.get_header()) else: img_out = nib.Nifti1Image(self.mask, self.img.get_affine(), self.img.get_header()) nib.save(img_out, os.path.join(self.dirname, self.filename_mask)) if self.obj_return_value is not None: self.obj_return_value.delete(0, len(self.obj_return_value.get())) self.obj_return_value.insert(0, os.path.basename(self.filename_mask)) def readImage(self, filename): self.filename = filename self.img = nib.load(filename) self.shape = self.img.shape self.data_base = self.img.get_data() if len(self.data_base.shape) > 3: for f in range(self.data_base.shape[3]): for z in range(self.data_base.shape[2]): self.data_base[:, :, z, f] = ndimage.gaussian_filter( self.data_base[:, :, z, f], sigma=0.5) self.data = self.data_base[:, :, :, 0] else: for z in range(self.data_base.shape[2]): self.data_base[:, :, z] = ndimage.gaussian_filter( self.data_base[:, :, z], sigma=0.5) self.data = self.data_base def createBaseImage(self): bvalFilename = tkFileDialog.askopenfilename() if bvalFilename: b0frames = parameter.get_b0_from_bval(bvalFilename) print self.filename, b0frames filename, filename_fltd, filename_mask = create_mask.set_filenames( self.filename) create_mask.make_base_image(filename, filename_fltd + '.nii.gz', b0frames) self.filename_mask = filename_mask + '.nii.gz' self.readImage(filename_fltd + '.nii.gz') self.drawSlice() def setSpinBoxConnect(self): for k in range(self.shape[2]): #self.sliceSpin[k].valueChanged.connect(lambda: self.createMaskSlice(k)) #self.sliceSpin[k].configure(command=lambda:self.createMaskSlice(k, self.sliceSpin[k])) self.sliceSpin[k].configure(command=functools.partial( self.createMaskSlice, k, self.sliceSpin[k])) def drawSlice(self): for k in range(self.shape[2]): self.sliceView[k].drawData(self.data[:, :, k], self.mask[:, :, k], self.drawmask.get()) def reset_box(self, box, text): box.delete(0, len(box.get())) box.insert(0, text) def createMaskSlice(self, k, value=None): self.mask[:, :, k] = 0 if value is None: value_i = int(self.sliceSpin[k].get()) else: value_i = int(value.get()) #create_mask.mask_from_threshold(self.com_x[k], self.com_y[k], self.sliceSpin[k].value(), self.data, self.mask, k) create_mask.mask_from_threshold(self.com_x[k], self.com_y[k], value_i, self.data, self.mask, k) self.sliceView[k].drawData(self.data[:, :, k], self.mask[:, :, k], self.drawmask.get()) def createMaskAll(self): self.drawmask.set(True) hdr = self.img.get_header() zooms = hdr.get_zooms() shape = self.shape self.com_x, self.com_y, roi_x, roi_y = create_mask.calculate_com( self.data, zooms) for k in range(shape[2]): dat_subflt = self.data[roi_x[k][0]:roi_x[k][1], roi_y[k][0]:roi_y[k][1], k].flatten() #threshold = np.mean(dat_subflt) threshold = np.mean(dat_subflt) + np.std(dat_subflt) self.reset_box(self.sliceSpin[k], int(threshold)) self.createMaskSlice(k) #create_mask.mask_from_threshold(self.com_x[k], self.com_y[k], threshold, self.data, self.mask, k) #self.drawSlice() self.setSpinBoxConnect()
def initUI(self): self.parent.title(self.title) self.nosearch = BooleanVar(self) self.noresample = BooleanVar(self) i = 0 #frame_top = Frame(self) #frame_top.grid(row=i, column=0, columnspan=6, sticky=EW) #Label(frame_top, text='topframe').grid(row=0, column=0, sticky=EW) #Label(frame_top, text='topframe').grid(row=0, column=1, sticky=EW) #Label(frame_top, text='topframe').grid(row=1, column=0, sticky=EW) #Label(frame_top, text='topframe').grid(row=1, column=1, sticky=EW) #Entry(frame_top, text='topframe').grid(row=0, column=0, sticky=EW) #Entry(frame_top, text='topframe').grid(row=0, column=1, sticky=EW) #Entry(frame_top, text='topframe').grid(row=1, column=0, sticky=EW) #Entry(frame_top, text='topframe').grid(row=1, column=1, sticky=EW) #frame_top.grid_columnconfigure(0, weight=1) #frame_top.grid_columnconfigure(1, weight=1) dddWidth = 4 labelWidth = 10 i += 1 Label(self, text='Working dir', width=labelWidth).grid(row=i, column=0) self.txt_working = Entry(self) self.txt_working.grid(row=i, column=1, sticky=EW) btn_working = Button( self, text='...', width=dddWidth, command=lambda: self.dirnameDialog_text(self.txt_working)) btn_working.grid(row=i, column=2, sticky=W) i += 1 Label(self, text='Parameters', width=labelWidth).grid(row=i, column=0) self.txt_param = Entry(self) self.txt_param.grid(row=i, column=1, sticky=EW) btn_param_read = Button(self, text='Read', command=self.read_param) btn_param_read.grid(row=i, column=2) btn_param_save = Button(self, text='Save', command=self.save_param) btn_param_save.grid(row=i, column=3) i += 1 frm_prepa = Frame(self) ii = 0 Label(frm_prepa, text='Subject', width=labelWidth).grid(row=ii, column=0) self.txt_subject = Entry(frm_prepa) self.txt_subject.grid(row=ii, column=1, sticky=EW) btn_prepa = Button(frm_prepa, text='Prepare DWIs', command=self.run_prepare) btn_prepa.grid(row=ii, column=3) #btn_update = Button(frm_prepa, text='Update filenames', command=self.update_parameter); btn_update.grid(row=ii, column=4) btn_update = Button(frm_prepa, text='Update filenames', command=self.update_text_from_param) btn_update.grid(row=ii, column=4) ii += 1 Label(frm_prepa, text='bval', width=labelWidth).grid(row=ii, column=0) self.txt_bval = Entry(frm_prepa) self.txt_bval.grid(row=ii, column=1, sticky=EW) btn_bval = Button( frm_prepa, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_bval)) btn_bval.grid(row=ii, column=2, sticky=W) Label(frm_prepa, text='b0 threshold').grid(row=ii, column=3, sticky=E) self.txt_b0_threshold = Entry(frm_prepa, width=10) self.txt_b0_threshold.grid(row=ii, column=4) ii += 1 Label(frm_prepa, text='bvec', width=labelWidth).grid(row=ii, column=0) self.txt_bvec = Entry(frm_prepa) self.txt_bvec.grid(row=ii, column=1, sticky=EW) btn_bvec = Button( frm_prepa, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_bvec)) btn_bvec.grid(row=ii, column=2, sticky=W) Label(frm_prepa, text='high b threshold').grid(row=ii, column=3, sticky=E) self.txt_high_b_threshold = Entry(frm_prepa, width=10) self.txt_high_b_threshold.grid(row=ii, column=4) frm_prepa.grid_columnconfigure(1, weight=1) frm_prepa.grid(row=i, rowspan=ii + 1, column=0, columnspan=6, sticky=NSEW) ii += 1 i += ii # TOPUP/EDDY or Rigid registration i += 1 Label(self, text=' TOPUP/EDDY or Rigid registration').grid(row=i, column=0, columnspan=2, sticky=W) i += 1 frm_eddy = Frame(self) width = 10 ii = 0 jj = 0 Label(frm_eddy, text='TOPUP', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) jj += 1 self.txt_topup_app = Entry(frm_eddy, width=width) self.txt_topup_app.grid(row=ii, column=jj) jj += 1 Label(frm_eddy, text='Configure', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) jj += 1 self.txt_topup_config = Entry(frm_eddy) self.txt_topup_config.grid(row=ii, column=jj, sticky=EW) jj += 1 btn_topup_config = Button( frm_eddy, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_topup_config)) btn_topup_config.grid(row=ii, column=jj, sticky=W) jj += 1 Label(frm_eddy, text='EDDY', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) jj += 1 self.txt_eddy_app = Entry(frm_eddy, width=width) self.txt_eddy_app.grid(row=ii, column=jj) frm_eddy.grid(row=i, rowspan=ii + 1, column=0, columnspan=6, sticky=NSEW) frm_eddy.grid_columnconfigure(3, weight=1) i += ii i += 1 Label(self, text='B0', width=labelWidth).grid(row=i, column=0) self.txt_b0 = Entry(self) self.txt_b0.grid(row=i, column=1, sticky=EW) btn_b0 = Button(self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_b0)) btn_b0.grid(row=i, column=2, sticky=W) btn_topup = Button(self, text='TOPUP', command=self.run_topup) btn_topup.grid(row=i, column=4, rowspan=2, sticky=NS) btn_rigid = Button(self, text='Rigid\nReg', command=self.run_eddy) btn_rigid.grid(row=i, column=5, rowspan=4, sticky=NS) i += 1 Label(self, text='B0 mask', width=labelWidth).grid(row=i, column=0) self.txt_b0mask = Entry(self) self.txt_b0mask.grid(row=i, column=1, sticky=EW) btn_b0mask = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_b0mask)) btn_b0mask.grid(row=i, column=2, sticky=W) btn_b0mask_make = Button( self, text='Make', command=lambda: self.make_mask( self.txt_b0.get(), mask4d=True, rtn=self.txt_b0mask)) btn_b0mask_make.grid(row=i, column=3) i += 1 Label(self, text='DWI', width=labelWidth).grid(row=i, column=0) self.txt_dwi = Entry(self) self.txt_dwi.grid(row=i, column=1, sticky=EW) btn_dwi_eddy = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dwi)) btn_dwi_eddy.grid(row=i, column=2, sticky=W) btn_eddy = Button(self, text='EDDY', command=self.run_eddy) btn_eddy.grid(row=i, column=4, rowspan=2, sticky=NS) i += 1 Label(self, text='DWI mask', width=labelWidth).grid(row=i, column=0) self.txt_dwi_mask = Entry(self) self.txt_dwi_mask.grid(row=i, column=1, sticky=EW) btn_dwi_mask = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dwi_mask)) btn_dwi_mask.grid(row=i, column=2, sticky=W) btn_dwi_mask_make = Button( self, text='Make', command=lambda: self.make_mask(self.txt_dwi.get(), rtn=self.txt_dwi_mask)) btn_dwi_mask_make.grid(row=i, column=3) i += 1 Label(self, text='Output', width=labelWidth).grid(row=i, column=0) self.txt_output_eddy = Entry(self) self.txt_output_eddy.grid(row=i, column=1, sticky=EW) btn_output_eddy = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_output_eddy)) btn_output_eddy.grid(row=i, column=2, sticky=W) btn_output_eddy_auto = Button(self, text='Auto', command=self.gen_eddy_outputname) btn_output_eddy_auto.grid(row=i, column=3) # 2D registration i += 1 Label(self, text=' 2D registration (X-Y translation)').grid(row=i, column=0, columnspan=2, sticky=W) i += 1 frm_param = Frame(self) width = 12 width_half = 6 ii = 0 jj = 0 Label(frm_param, text='Multi band', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) #jj += 1; self.txt_multiband = Entry(frm_param, width=width_half); self.txt_multiband.grid(row=ii, column=jj) jj += 1 self.spin_multiband = Spinbox(frm_param, from_=0, to=1000, increment=1, width=width_half) self.spin_multiband.grid(row=ii, column=jj) jj += 1 Label(frm_param, text='#iteration', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) #jj += 1; self.txt_nitr = Entry(frm_param, width=width_half); self.txt_nitr.grid(row=ii, column=jj) jj += 1 self.spin_nitr = Spinbox(frm_param, from_=0, to=1000, increment=1, width=width_half) self.spin_nitr.grid(row=ii, column=jj) jj += 1 Label(frm_param, text='', width=width, justify=RIGHT, anchor=E).grid(row=ii, column=jj, sticky=E) jj += 1 self.chk_nosearch = Checkbutton(frm_param, text='nosearch', variable=self.nosearch, width=width) self.chk_nosearch.grid(row=ii, column=jj) jj += 1 self.chk_noresample = Checkbutton(frm_param, text='noresample', variable=self.noresample, width=width) self.chk_noresample.grid(row=ii, column=jj) ii += 1 jj = 0 Label(frm_param, text='Schedule').grid(row=ii, column=jj, sticky=E) jj += 1 self.txt_reg_config = Entry(frm_param) self.txt_reg_config.grid(row=ii, column=jj, sticky=EW, columnspan=4) jj += 4 btn_reg_config = Button( frm_param, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_reg_config)) btn_reg_config.grid(row=ii, column=jj, sticky=W) frm_param.grid_columnconfigure(4, weight=1) frm_param.grid(row=i, rowspan=ii + 1, column=0, columnspan=6, sticky=NSEW) i += ii i += 1 Label(self, text='DWI', width=labelWidth).grid(row=i, column=0) self.txt_dwi_eddy = Entry(self) self.txt_dwi_eddy.grid(row=i, column=1, sticky=EW) btn_dwi_eddy = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dwi_eddy)) btn_dwi_eddy.grid(row=i, column=2, sticky=W) btn_dwi_eddy_copy = Button( self, text='Copy', command=lambda: self.reset_entry(self.txt_dwi_eddy, self.txt_output_eddy.get())) btn_dwi_eddy_copy.grid(row=i, column=3) btn_dwi_eddy = Button(self, text='Save\nParam', command=self.save_reg_param) btn_dwi_eddy.grid(row=i, column=4, rowspan=2, sticky=NSEW) btn_dwi_eddy = Button(self, text='XY-Reg', command=self.run_xy_reg) btn_dwi_eddy.grid(row=i, column=5, rowspan=2, sticky=NSEW) i += 1 Label(self, text='Mask', width=labelWidth).grid(row=i, column=0) self.txt_reg_mask = Entry(self) self.txt_reg_mask.grid(row=i, column=1, sticky=EW) btn_reg_mask = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_reg_mask)) btn_reg_mask.grid(row=i, column=2, sticky=W) btn_reg_mask_make = Button( self, text='Make', command=lambda: self.make_mask(self.txt_dwi_eddy.get(), rtn=self.txt_reg_mask)) btn_reg_mask_make.grid(row=i, column=3) i += 1 Label(self, text='Slices', width=labelWidth).grid(row=i, column=0) self.txt_reg_slices = Entry(self) self.txt_reg_slices.grid(row=i, column=1, sticky=EW) i += 1 Label(self, text='Outlier', width=labelWidth).grid(row=i, column=0) self.txt_reg_outlier = Entry(self) self.txt_reg_outlier.grid(row=i, column=1, sticky=EW) btn_reg_outlier = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_reg_outlier)) btn_reg_outlier.grid(row=i, column=2, sticky=W) btn_reg_outlier_calculate = Button(self, text='Calculate', command=self.run_xy_reg_outlier) btn_reg_outlier_calculate.grid(row=i, column=3) btn_reg_apply = Button(self, text='Applywarp', command=self.run_applywarp) btn_reg_apply.grid(row=i, column=4, columnspan=2, sticky=EW) i += 1 Label(self, text='Output', width=labelWidth).grid(row=i, column=0) self.txt_output_reg = Entry(self) self.txt_output_reg.grid(row=i, column=1, sticky=EW) btn_output_reg = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_output_reg)) btn_output_reg.grid(row=i, column=2, sticky=W) btn_output_reg_auto = Button(self, text='Auto', command=self.gen_reg_outputname) btn_output_reg_auto.grid(row=i, column=3) # DTI i += 1 Label(self, text=' DTI map with outlier rejection').grid(row=i, column=0, columnspan=2, sticky=W) i += 1 Label(self, text='DWI_reg', width=labelWidth).grid(row=i, column=0) self.txt_dwi_dti = Entry(self) self.txt_dwi_dti.grid(row=i, column=1, sticky=EW) btn_dwi_dti = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dwi_dti)) btn_dwi_dti.grid(row=i, column=2, sticky=W) btn_dwi_dti_copy = Button( self, text='Copy', command=lambda: self.reset_entry(self.txt_dwi_dti, self.txt_output_reg.get())) btn_dwi_dti_copy.grid(row=i, column=3) btn_dti_maps = Button(self, text='Generate DTI maps', command=self.run_generate_dti_maps) btn_dti_maps.grid(row=i, column=4, columnspan=2, sticky=EW) i += 1 Label(self, text='DTI', width=labelWidth).grid(row=i, column=0) self.txt_dti = Entry(self) self.txt_dti.grid(row=i, column=1, sticky=EW) btn_dti = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dti)) btn_dti.grid(row=i, column=2, sticky=W) btn_dti_auto = Button(self, text='Auto', command=self.gen_dti_name) btn_dti_auto.grid(row=i, column=3) btn_dti_outlier_calc = Button(self, text='Calculate Outlier', command=self.run_dti_outlier) btn_dti_outlier_calc.grid(row=i, column=4, columnspan=2, rowspan=2, sticky=NSEW) i += 1 Label(self, text='Mask', width=labelWidth).grid(row=i, column=0) self.txt_md_mask = Entry(self) self.txt_md_mask.grid(row=i, column=1, sticky=EW) btn_md_mask = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_md_mask)) btn_md_mask.grid(row=i, column=2, sticky=W) btn_md_mask_make = Button(self, text='Make', command=self.run_md_mask) btn_md_mask_make.grid(row=i, column=3) i += 1 Label(self, text='Outlier', width=labelWidth).grid(row=i, column=0) self.txt_dti_outlier = Entry(self) self.txt_dti_outlier.grid(row=i, column=1, sticky=EW) btn_dti_outlier = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dti_outlier)) btn_dti_outlier.grid(row=i, column=2, sticky=W) btn_dti_maps_itr = Button( self, text='Generate DTI maps', command=lambda: self.run_generate_dti_maps(outlier=True)) btn_dti_maps_itr.grid(row=i, column=4, columnspan=2, sticky=EW) #i += 1 #Label(self, text='DWI' , width=labelWidth).grid(row=i, column=0) #self.txt_dwi_dti_itr = Entry(self); self.txt_dwi_dti_itr.grid(row=i, column=1, sticky=EW) #btn_dwi_dti_itr = Button(self, text='...', width=dddWidth, command=lambda:self.filenameDialog_text(self.txt_dwi_dti_itr)) #btn_dwi_dti_itr.grid(row=i, column=2, sticky=W) #i += 1; Label(self, text='Output' , width=labelWidth).grid(row=i, column=0) #self.txt_output_dti = Entry(self); self.txt_output_dti.grid(row=i, column=1, sticky=EW) #btn_output_dti = Button(self, text='...', width=dddWidth, command=lambda:self.filenameDialog_text(self.txt_output_dti)) #btn_output_dti.grid(row=i, column=2, sticky=W) #btn_output_dti_auto = Button(self, text='Auto', command=self.gen_dti_outputname); btn_output_dti_auto.grid(row=i, column=3) # DTI Values i += 1 Label(self, text=' DTI values').grid(row=i, column=0, columnspan=2, sticky=W) i += 1 Label(self, text='DTI', width=labelWidth).grid(row=i, column=0) self.txt_dti_value = Entry(self) self.txt_dti_value.grid(row=i, column=1, sticky=EW) btn_dti_value = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dti_value)) btn_dti_value.grid(row=i, column=2, sticky=W) btn_dwi_dti_value_copy = Button( self, text='Copy', command=lambda: self.reset_entry(self.txt_dti_value, self.txt_dti.get())) btn_dwi_dti_value_copy.grid(row=i, column=3) btn_dti_value_get = Button(self, text='Get DTI\nValues', command=self.run_get_dti_values) btn_dti_value_get.grid(row=i, column=4, rowspan=2, columnspan=2, sticky=NSEW) i += 1 Label(self, text='ROI', width=labelWidth).grid(row=i, column=0) self.txt_dti_roi = Entry(self) self.txt_dti_roi.grid(row=i, column=1, sticky=EW) btn_dti_roi = Button( self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text(self.txt_dti_roi)) btn_dti_roi.grid(row=i, column=2, sticky=W) btn_dti_roi = Button(self, text='Make') btn_dti_roi.grid(row=i, column=3) i += 1 Label(self, text='Output', width=labelWidth).grid(row=i, column=0) self.txt_output_dti_value = Entry(self) self.txt_output_dti_value.grid(row=i, column=1, sticky=EW) btn_output_dti_value = Button(self, text='...', width=dddWidth, command=lambda: self.filenameDialog_text( self.txt_output_dti_value)) btn_output_dti_value.grid(row=i, column=2, sticky=W) btn_output_dti_value_auto = Button( self, text='Auto', command=self.gen_dti_value_outputname) btn_output_dti_value_auto.grid(row=i, column=3) self.grid_columnconfigure(1, weight=1) ni = i + 1 for i in range(ni): self.grid_rowconfigure(i, weight=1, minsize=20) self.pack(fill=BOTH, expand=True)
class VueEditeur(Frame): """ class VueEditeur ======================== Cette classe hérite d'un Frame. Elle représente la vue « Editeur » telle que présentée dans le document de spécification. Le Frame inclut les boutons et autres Widgets nécessaires pour la vue. :example: >>> test = VueEditeur() """ # Constructeur. def __init__(self, parent=None, attachOrdinateurGUI=None): """ Constructeur de la classe VueEditeur. Le constructeur initialise le Frame de la classe avec le Widget parent donné en argument. Il initialise ensuite les Widgets nécessaires de la vue (comme décrit dans le document de spécification). Les fonctions du module « 02-FonctionEditeur » et du module « 03-Compileur » seront liés aux évènements associés (par exemple les boutons de la vue). :param parent: Parent Widget de la classe. :type parent: Widget (Tk) :param attachOrdinateurGUI: Interface ordinateur. :type attachOrdinateurGUI: Widget (Tk) :example: >>> test1 = VueEditeur() >>> test2 = VueEditeur(Tk()) .. warning:: Cette classe a besoin d'avoir accès aux modules « 02-FonctionEditeur » et « 03-Compileur ». """ self.guiOrdinateur = attachOrdinateurGUI # Initialise le Frame de l'instance. Frame.__init__(self, parent) # Création des widgets nécessaires. # --Frame(Text + Button). self.globalFrame = Frame(self) # ----Text. self.frameCin = Frame(self.globalFrame) self.labelCin = ttk.Label(self.frameCin, text="Code", anchor=SW) self.innerFrameCin = Frame(self.frameCin, relief=SUNKEN) self.txtConsoleInput = modCST.CodeScrolledText(self.innerFrameCin) self.txtConsoleInput.configure(width=0, relief=FLAT) self.labelCin.pack(fill=X, padx=3, ipady=5) self.innerFrameCin.pack(fill=BOTH, padx=3, pady=5, expand=True) self.txtConsoleInput.pack(fill=BOTH, padx=3, pady=3, expand=True) self.frameCin.grid(column=0, row=0, sticky="NSWE") # ----Button. self.frameBut = Frame(self.globalFrame) if self.guiOrdinateur is not None: self.butTransfer = ttk.Button( self.frameBut, text="Compiler et Transfèrer dans Ordinateur") self.butCompile = ttk.Button(self.frameBut, text="Compiler et Sauvegarder") self.butSave = ttk.Button(self.frameBut, text="Sauvegarder Code") self.butLoad = ttk.Button(self.frameBut, text="Ouvrir Code") if self.guiOrdinateur is not None: self.butTransfer.pack(fill=X, padx=20, pady=35, ipady=15) self.butCompile.pack(fill=X, padx=20, ipady=15) else: self.butCompile.pack(fill=X, padx=20, pady=35, ipady=15) self.butSave.pack(fill=X, padx=20, pady=3, ipady=10) self.butLoad.pack(fill=X, padx=20, pady=3, ipady=10) self.frameBut.grid(column=1, row=0, sticky="NWE") # ----Grid Configure self.globalFrame.grid_rowconfigure(0, weight=1) self.globalFrame.grid_columnconfigure(0, minsize=400, weight=4) self.globalFrame.grid_columnconfigure(1, minsize=100, weight=1) # --StatusBar. self.statusBar = modStatusBar.StatusBar(self) # Pack self.globalFrame.pack(fill=BOTH, expand=True) self.statusBar.pack(fill=X) # Liaison des évènements. if self.guiOrdinateur is not None: self.butTransfer.configure(command=self.__callbackCompileTransfer) self.butCompile.configure(command=self.__callbackCompile) self.butSave.configure(command=self.__callbackSave) self.butLoad.configure(command=self.__callbackLoad) # Fin de __init__. return def __callbackCompileTransfer(self): """ Callback pour le bouton «Compiler et Transfert». Cette fonction appelle la fonction appropriée du module 03-Compiler. Si la compilation est un échec, cette fonction avertie l'utilisateur via une boite système l'erreur (l'information est aussi inscrite sur la barre de statut). Si la compilation est un succès on transfère le code dans l'interface «Ordinateur». ..note: Cette fonction est interne à la classe. """ # On compile le code inscrit dans le widget Text. result = modCompiler.compile(self.txtConsoleInput.get("1.0", END)) # Si la compilation est un succès. if result[0]: self.statusBar.setText("La compilation est un succès.") # On Transfère le code. self.guiOrdinateur.transfert(result[1]) self.statusBar.setText( "La compilation est un succès. Transfert effectué.") # Si la compilation est un échec. else: # On informe l'utilisateur. self.statusBar.setText(result[1]) messageBox.showerror(title="Erreur de compilation", message=result[1]) # Fin callbackCompile. return def __callbackCompile(self): """ Callback pour le bouton «Compiler». Cette fonction appelle la fonction appropriée du module 03-Compiler. Si la compilation est un échec, cette fonction avertie l'utilisateur via une boite système l'erreur (l'information est aussi inscrite sur la barre de statut). Si la compilation est un succès, on ouvre une boite système pour faire choisir l'emplacement où sauvegarder le fichier compilé. Nous appelons ensuite la fonction pour sauvegarder ce fichier. ..note: Cette fonction est interne à la classe. """ # On compile le code inscrit dans le widget Text. result = modCompiler.compile(self.txtConsoleInput.get("1.0", END)) # Si la compilation est un succès. if result[0]: self.statusBar.setText("La compilation est un succès.") # On demande le chemin du fichier à sauvegarder. info = fileDialog.asksaveasfilename( defaultextension=".exeb", filetypes=[("Executable byte code", ".exeb")], title="Sauvegarder l'exécutable sous...") # --Si l'utilisateur annule. if info is "": return # On sauvegarde ce fichier. modFunctEditor.saveByteCode(info, result[1]) self.statusBar.setText( "La compilation est un succès. L'exécutable a été sauvegardé.") # Si la compilation est un échec. else: # On informe l'utilisateur. self.statusBar.setText(result[1]) messageBox.showerror(title="Erreur de compilation", message=result[1]) # Fin callbackCompile. return def __callbackSave(self): """ Fonction «callback» pour le bouton «Sauvegarder». Cette fonction appelle la fonction appropriée du module 02-FonctionEditeur. On ouvre une boite système pour faire choisir l'emplacement où sauvegarder le fichier du code non-compilé. Nous appelons ensuite la fonction pour sauvegarder ce fichier. ..note: Cette fonction est interne à la classe. """ # On demande le chemin du fichier à sauvegarder. info = fileDialog.asksaveasfilename( defaultextension=".asm", filetypes=[("Assembler", ".asm"), ("Texte", ".txt")], title="Sauvegarder le code sous...") # --Si l'utilisateur annule. if info is "": return # On sauvegarde ce fichier. modFunctEditor.saveTextCode(info, self.txtConsoleInput.get("1.0", END)[0:-1]) self.statusBar.setText("Code sauvegarder.") # Fin callbackSave. return def __callbackLoad(self): """ Fonction «callback» pour le bouton «Charger». Cette fonction appelle la fonction appropriée du module 02-FonctionEditeur. On ouvre une boite système pour faire choisir l'emplacement du fichier code à charger. Nous appelons ensuite la fonction pour charger ce fichier. ..note: Cette fonction est interne à la classe. """ # On demande le chemin du fichier à charger. info = fileDialog.askopenfilename(defaultextension=".asm", filetypes=[("Assembler", ".asm"), ("Texte", ".txt")], title="Ouvrir le code...") # --Si l'utilisateur annule. if info is "": return # On charge ce fichier. code = modFunctEditor.loadTextCode(info) self.txtConsoleInput.delete("1.0", END) self.txtConsoleInput.insert(END, code) self.statusBar.setText("Code charger.") # Fin callbackLoad. return