예제 #1
0
파일: ims.py 프로젝트: jeffreydominic/DOSMA
    def __display_data_loader(self):
        hb = tk.Frame(self)

        filedialog = FileDialogReader(self.manager[self.__LOAD_PATH_KEY])
        b = tk.Button(hb,
                      text=self.__LOAD_PATH_KEY,
                      command=lambda fd=filedialog: self.manager[
                          self.__LOAD_PATH_KEY].set(fd.get_save_dirpath()))
        b.pack(side='left', anchor='nw', pady=10)

        l = tk.Label(hb, textvariable=self.manager[self.__LOAD_PATH_KEY])
        l.pack(side='left', anchor='nw', pady=10)

        hb.pack(side='top', anchor='nw')
예제 #2
0
파일: ims.py 프로젝트: jeffreydominic/DOSMA
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        self.file_dialog_reader = FileDialogReader()

        self.manager = dict()
        self.gui_manager = dict()
        self.balloon = Pmw.Balloon()

        self.__init_manager()

        self.__base_gui()
        self.preferences = PreferencesManager()
        self.scan_reader = ScanReader(self)

        button1 = ttk.Button(self,
                             text="Home",
                             command=lambda: controller.show_frame(StartPage))
        button1.pack(anchor='se', side='right')

        button1 = ttk.Button(self, text="Run", command=lambda: self.execute())
        button1.pack(anchor='sw', side='left')

        self.InitUI()
예제 #3
0
def format_filepath_gui(root, label, type_var, **kwargs):
    hbox = tk.Frame(root)
    hbox.pack(side="top", anchor="nw")

    _label = tk.Label(hbox, text="%s: " % label)
    _label.pack(side="left", anchor="nw", padx=5)

    t = tk.Label(hbox, textvariable=type_var)
    t.pack(side="left", anchor="nw", padx=5)

    fd = FileDialogReader(type_var)
    fd_prompt = "Load %s" % label.lower()

    f_action = fd.get_filepath
    if "dir" in label.lower():
        f_action = fd.get_dirpath

    b = ttk.Button(root, text=fd_prompt, command=lambda: f_action(title=fd_prompt))

    b.pack(anchor="nw", pady=1)

    return hbox
예제 #4
0
파일: ims.py 프로젝트: jeffreydominic/DOSMA
class DosmaFrame(tk.Frame):
    __SCAN_KEY = 'Scan'
    __TISSUES_KEY = 'Tissues'

    __DICOM_PATH_KEY = 'Read dicoms'
    __LOAD_PATH_KEY = 'Load data'

    __SAVE_PATH_KEY = 'Save path'

    __DATA_KEY = 'data'  # Track option menu for dicom/load path
    __DATA_PATH_KEY = 'datapath'  # Track filepath associated with option menu

    __IGNORE_EXTENSION_KEY = 'Ignore extension'

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)

        self.file_dialog_reader = FileDialogReader()

        self.manager = dict()
        self.gui_manager = dict()
        self.balloon = Pmw.Balloon()

        self.__init_manager()

        self.__base_gui()
        self.preferences = PreferencesManager()
        self.scan_reader = ScanReader(self)

        button1 = ttk.Button(self,
                             text="Home",
                             command=lambda: controller.show_frame(StartPage))
        button1.pack(anchor='se', side='right')

        button1 = ttk.Button(self, text="Run", command=lambda: self.execute())
        button1.pack(anchor='sw', side='left')

        self.InitUI()

    def execute(self):
        try:
            save_path = self.manager[self.__SAVE_PATH_KEY].get()
            if not save_path:
                raise ValueError('Save path not defined')

            action_str = self.scan_reader.get_cmd_line_str().strip()

            if not action_str:
                raise ValueError('No action selected')

            preferences_str = self.preferences.get_cmd_line_str().strip()

            source = 'd'
            if self.manager[self.__DATA_KEY].get() == self.__LOAD_PATH_KEY:
                source = 'l'

            tissue_str = ''
            for c, t in enumerate(self.manager[self.__TISSUES_KEY]):
                if t.get():
                    tissue_str += '--%s ' % knee.SUPPORTED_TISSUES[c].STR_ID
            tissue_str = tissue_str.strip()

            if not tissue_str:
                raise ValueError('No tissues selected')

            ignore_ext = self.manager[self.__IGNORE_EXTENSION_KEY].get()

            str_f = '--%s %s --s %s %s %s %s %s %s' % (
                source, self.manager[self.__DATA_PATH_KEY].get(), save_path,
                preferences_str, '--ignore_ext' if ignore_ext else '',
                self.manager[self.__SCAN_KEY].get(), tissue_str, action_str)

            logging.info('CMD LINE INPUT: %s' % str_f)

            parse_args(str_f.split())
        except Exception as e:
            tk.messagebox.showerror(str(type(e)), e.__str__())

    def __init_manager(self):
        self.manager[self.__SCAN_KEY] = tk.StringVar()
        self.manager[self.__TISSUES_KEY] = [
            tk.BooleanVar() for i in range(len(knee.SUPPORTED_TISSUES))
        ]
        self.manager[self.__DATA_KEY] = tk.StringVar()
        self.manager[self.__DATA_PATH_KEY] = tk.StringVar()

        self.manager[self.__SCAN_KEY].trace_add('write', self.__on_scan_change)
        self.manager[self.__SAVE_PATH_KEY] = tk.StringVar()
        self.manager[self.__IGNORE_EXTENSION_KEY] = tk.BooleanVar()

    def __on_scan_change(self, *args):
        scan_id = self.manager[self.__SCAN_KEY].get()
        scan = None
        for x in SUPPORTED_SCAN_TYPES:
            if x.NAME == scan_id:
                scan = x

        self.scan_reader.load_scan(scan)

        assert scan is not None, "No scan selected"

    def __update_svar(self, *args):
        svar = self.manager[self.__DATA_PATH_KEY]
        selected_option = self.manager[self.__DATA_KEY].get()
        if selected_option == self.__DICOM_PATH_KEY:
            fp = self.file_dialog_reader.get_volume_filepath(
                selected_option, im_type=fio_utils.ImageDataFormat.dicom)
        elif selected_option == self.__LOAD_PATH_KEY:
            fp = self.file_dialog_reader.get_dirpath(selected_option)
        else:
            raise ValueError('%s key not found' % self.__DATA_KEY)

        if not fp:
            svar.set('')
            return

        svar.set(fp)

        if selected_option == self.__LOAD_PATH_KEY:
            self.manager[self.__SAVE_PATH_KEY].set(fp)

    def __display_data_loader(self):
        s_var = self.manager[self.__DATA_PATH_KEY]

        hb = tk.Frame(self)

        l = tk.Label(hb, text='Data source: ')
        l.pack(side='left', anchor='nw', pady=10)

        options = [self.__DICOM_PATH_KEY, self.__LOAD_PATH_KEY]
        menu = tk.OptionMenu(hb,
                             self.manager[self.__DATA_KEY],
                             *options,
                             command=self.__update_svar)
        menu.pack(side='left', anchor='nw', pady=10)

        l = tk.Label(hb, textvariable=s_var)
        l.pack(side='left', anchor='nw', pady=10)

        hb.pack(side='top', anchor='nw')
        self.balloon.bind(hb, "Read dicoms or load data")

        hb = tk.Frame(self)

        # filedialog = FileDialogReader(self.manager[self.__SAVE_PATH_KEY])
        b = tk.Button(hb,
                      text=self.__SAVE_PATH_KEY,
                      command=lambda fd=self.file_dialog_reader: self.manager[
                          self.__SAVE_PATH_KEY].set(fd.get_save_dirpath()))
        b.pack(side='left', anchor='nw', pady=10)

        l = tk.Label(hb, textvariable=self.manager[self.__SAVE_PATH_KEY])
        l.pack(side='left', anchor='nw', pady=10)

        hb.pack(side='top', anchor='nw')

        hb = tk.Frame(self)

        b = tk.Checkbutton(hb,
                           text=self.__IGNORE_EXTENSION_KEY,
                           variable=self.manager[self.__IGNORE_EXTENSION_KEY])
        b.pack(side='left', anchor='nw', pady=10)
        self.balloon.bind(b, "Ignore '.dcm' extension when loading dicoms")

        hb.pack(side='top', anchor='nw')

    def __display_tissues(self):
        hb = tk.Frame(self)
        l = tk.Label(hb, text='Tissues:')
        l.pack(side='left', anchor='w')
        hb.pack(side='top', anchor='nw')
        frames = [tk.Frame(hb)] * (len(knee.SUPPORTED_TISSUES) // 3 + 1)
        for ind, tissue in enumerate(knee.SUPPORTED_TISSUES):
            f = frames[ind // 3]
            b = tk.Checkbutton(f,
                               text=tissue.FULL_NAME,
                               variable=self.manager[self.__TISSUES_KEY][ind])
            b.pack(side='top', anchor='nw', pady=5)

        for f in frames:
            f.pack(side='left', anchor='nw')

        self.balloon.bind(l, 'Tissues to analyze')

    def __base_gui(self):
        self.__display_data_loader()
        self.__display_tissues()

        hb = tk.Frame(self)
        scan_label = tk.Label(hb, text='Scan:')
        scan_label.pack(side='left', anchor='nw', pady=10)
        options = [x.NAME for x in SUPPORTED_SCAN_TYPES]
        scan_dropdown = tk.OptionMenu(hb, self.manager[self.__SCAN_KEY],
                                      *options)
        scan_dropdown.pack(side='left', anchor='nw', pady=10)
        hb.pack(side='top', anchor='nw')

    def InitUI(self):
        self.text_box = tk.Text(self, wrap='word', height=11, width=50)
        self.text_box.pack(anchor='s', side='bottom')