class TripVoiDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) pub.subscribe(self.patient_data_updated, "patient.loaded") pub.sendMessage("patient.request", {}) def patient_data_updated(self, msg): self.data = msg.data def select_drop_by_value(self, drop, value): for i, item in enumerate(drop.GetItems()): if item == value: drop.SetSelection(i) def Init(self, voi): self.voi = voi wx.EVT_BUTTON(self, XRCID('btn_ok'), self.save_and_close) wx.EVT_BUTTON(self, XRCID('btn_close'), self.close) self.label_name = XRCCTRL(self, "label_name") self.label_name.SetLabel(voi.get_name()) self.txt_dose = XRCCTRL(self, "txt_dose") self.txt_dose.SetValue("%.2f" % (voi.get_dose())) self.check_target = XRCCTRL(self, "check_target") self.check_target.SetValue(voi.is_target()) self.check_target.Bind(wx.EVT_CHECKBOX, self.on_check_target_changed) self.check_oar = XRCCTRL(self, "check_oar") self.check_oar.SetValue(voi.is_oar()) self.check_oar.Bind(wx.EVT_CHECKBOX, self.on_check_oar_changed) self.txt_max_dose_fraction = XRCCTRL(self, "txt_max_dose_fraction") self.txt_max_dose_fraction.SetValue("%.2f" % (voi.get_max_dose_fraction())) self.txt_max_dose_fraction.Enable(False) self.txt_dose.Enable(False) if voi.is_target(): self.check_oar.Enable(False) self.txt_dose.Enable(True) if voi.is_oar(): self.txt_max_dose_fraction.Enable(True) self.check_target.Enable(False) self.txt_hu_value = XRCCTRL(self, "txt_hu_value") self.txt_hu_offset = XRCCTRL(self, "txt_hu_offset") if not voi.get_hu_value() is None: self.txt_hu_value.SetValue("%d" % voi.get_hu_value()) if not voi.get_hu_offset() is None: self.txt_hu_offset.SetValue("%d" % voi.get_hu_offset()) self.drop_projectile = XRCCTRL(self, "drop_projectile") self.drop_projectile.Append("H") self.drop_projectile.Append("C") self.txt_dose_percent = XRCCTRL(self, "txt_dose_percent") wx.EVT_BUTTON(self, XRCID('btn_set_dosepercent'), self.set_dose_percent) wx.EVT_CHOICE(self, XRCID('drop_projectile'), self.on_projectile_changed) def on_projectile_changed(self, evt): projectile = self.drop_projectile.GetStringSelection() dose_percent = self.voi.get_dose_percent(projectile) if dose_percent is None: self.txt_dose_percent.SetValue("") else: self.txt_dose_percent.SetValue("%d" % dose_percent) def set_dose_percent(self, evt): if not self.drop_projectile.GetStringSelection() == "": self.voi.set_dose_percent(self.drop_projectile.GetStringSelection(), self.txt_dose_percent.GetValue()) def on_check_target_changed(self, evt): if evt.Checked(): self.check_oar.Enable(False) self.txt_dose.Enable(True) else: self.check_oar.Enable(True) self.txt_dose.Enable(False) def on_check_oar_changed(self, evt): if evt.Checked(): self.txt_max_dose_fraction.Enable(True) self.check_target.Enable(False) else: self.check_target.Enable(True) self.txt_max_dose_fraction.Enable(False) def save_and_close(self, evt): voi = self.voi voi.set_dose(self.txt_dose.GetValue()) if voi.is_target() is not self.check_target.IsChecked(): voi.toogle_target() if voi.is_oar() is not self.check_oar.IsChecked(): voi.toogle_oar() voi.set_max_dose_fraction(self.txt_max_dose_fraction.GetValue()) voi.set_hu_offset(self.txt_hu_offset.GetValue()) voi.set_hu_value(self.txt_hu_value.GetValue()) self.Close() def close(self, evt): self.Close()
class FieldDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) def Init(self, field): self.field = field self.btn_ok = XRCCTRL(self, 'btn_ok') wx.EVT_BUTTON(self, XRCID('btn_ok'), self.save_and_close) self.btn_cancel = XRCCTRL(self, 'btn_close') wx.EVT_BUTTON(self, XRCID('btn_close'), self.close) self.label_fieldname = XRCCTRL(self, 'label_fieldname') self.label_fieldname.SetLabel(field.get_name()) self.check_isocenter = XRCCTRL(self, 'check_isocenter') target = field.get_target() if len(target) > 0: self.check_isocenter.SetValue(True) self.check_isocenter.Bind(wx.EVT_CHECKBOX, self.on_check_isocenter_changed) self.txt_targetx = XRCCTRL(self, 'txt_targetx') self.txt_targety = XRCCTRL(self, 'txt_targety') self.txt_targetz = XRCCTRL(self, 'txt_targetz') if len(target) > 0: self.txt_targetx.SetValue("%.2f" % (target[0])) self.txt_targety.SetValue("%.2f" % (target[1])) self.txt_targetz.SetValue("%.2f" % (target[2])) else: self.txt_targetx.Enable(False) self.txt_targety.Enable(False) self.txt_targetz.Enable(False) self.txt_gantry = XRCCTRL(self, 'txt_gantry') self.txt_gantry.SetValue("%.2f" % field.get_gantry()) self.txt_couch = XRCCTRL(self, 'txt_couch') self.txt_couch.SetValue("%.2f" % field.get_couch()) self.txt_fwhm = XRCCTRL(self, 'txt_fwhm') self.txt_fwhm.SetValue("%.2f" % field.get_fwhm()) self.txt_zsteps = XRCCTRL(self, 'txt_zsteps') self.txt_zsteps.SetValue("%.2f" % field.get_zsteps()) self.txt_doseextension = XRCCTRL(self, 'txt_doseext') self.txt_doseextension.SetValue("%.2f" % field.get_doseextension()) self.txt_contourextension = XRCCTRL(self, 'txt_contourext') self.txt_contourextension.SetValue("%.2f" % field.get_contourextension()) self.txt_raster1 = XRCCTRL(self, 'txt_raster1') self.txt_raster2 = XRCCTRL(self, 'txt_raster2') raster = field.get_rasterstep() self.txt_raster1.SetValue("%.2f" % raster[0]) self.txt_raster2.SetValue("%.2f" % raster[1]) self.drop_projectile = XRCCTRL(self, 'drop_projectile') self.drop_projectile.SetSelection( self.drop_projectile.GetItems().index(field.projectile)) def on_check_isocenter_changed(self, evt): if self.check_isocenter.IsChecked(): self.txt_targetx.Enable(True) self.txt_targety.Enable(True) self.txt_targetz.Enable(True) else: self.txt_targetx.Enable(False) self.txt_targety.Enable(False) self.txt_targetz.Enable(False) def save_and_close(self, evt): self.field.set_couch(self.txt_couch.GetValue()) self.field.set_gantry(self.txt_gantry.GetValue()) self.field.set_fwhm(self.txt_fwhm.GetValue()) if self.check_isocenter.IsChecked(): self.field.set_target(self.txt_targetx.GetValue() + "," + self.txt_targety.GetValue() + "," + self.txt_targetz.GetValue()) else: self.field.set_target("") self.field.set_zsteps(self.txt_zsteps.GetValue()) self.field.set_doseextension(self.txt_doseextension.GetValue()) self.field.set_contourextension(self.txt_contourextension.GetValue()) self.field.set_rasterstep(self.txt_raster1.GetValue(), self.txt_raster2.GetValue()) self.field.set_projectile(self.drop_projectile.GetStringSelection()) self.Close() def close(self, evt): self.Close()
class TripExportCubeDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) def Init(self, plan): self.plan = plan self.path = "~/" self.output_path = "" self.checkbox_vois = XRCCTRL(self, "checkbox_vois") wx.EVT_LISTBOX(self, XRCID("checkbox_vois"), self.selected_changed) wx.EVT_BUTTON(self, XRCID("btn_ok"), self.save_and_close) wx.EVT_BUTTON(self, XRCID("btn_cancel"), self.close) wx.EVT_BUTTON(self, XRCID("btn_reset"), self.reset) self.lbl_path = XRCCTRL(self, "lbl_path") self.txt_value = XRCCTRL(self, "txt_value") wx.EVT_TEXT(self, XRCID("txt_value"), self.text_value_changed) pub.subscribe(self.path_changed, "general.export.cube_export_path") pub.sendMessage("settings.value.request", "general.export.cube") pub.subscribe(self.patient_data_updated, "patient.loaded") pub.sendMessage("patient.request", {}) for voi in plan.get_vois(): self.checkbox_vois.Append(voi.get_name()) def patient_data_updated(self, msg): self.data = msg.data def selected_changed(self, evt): selected = self.checkbox_vois.GetStringSelection() self.txt_value.SetValue("") for voi in self.plan.get_vois(): if selected == voi.get_name(): if voi.get_cube_value() is -1: self.txt_value.SetValue("") else: self.txt_value.SetValue("%d" % voi.get_cube_value()) def text_value_changed(self, evt): selected = self.checkbox_vois.GetStringSelection() if len(selected) is 0: return for voi in self.plan.get_vois(): if selected == voi.get_name(): try: voi.set_cube_value(int(self.txt_value.GetValue())) except Exception as e: pass def path_changed(self, msg): if not msg.data is None: self.path = msg.data self.lbl_path.SetLabel(self.path) def reset(self, evt): for voi in self.plan.get_vois(): voi.set_cube_value(-1) self.txt_value.SetValue("") for k, item in enumerate(self.checkbox_vois.GetItems()): self.checkbox_vois.Check(k, False) def browse_for_file(self): dlg = wx.FileDialog(self, message="Save Picture", defaultDir=self.path, style=wx.FD_SAVE) if dlg.ShowModal() == wx.ID_OK: path = dlg.GetPath() a = os.path.splitext(path) if not a[-1] is "dos": path = path + ".dos" self.output_path = path pub.sendMessage("settings.value.updated", {"general.export.cube": os.path.dirname(path)}) return True return False def save_and_close(self, evt): selected = self.checkbox_vois.GetCheckedStrings() vois = [] dos = None for voi in self.plan.get_vois(): if voi.get_name() in selected: if dos is None: dos = voi.get_voi().get_voi_data().get_voi_cube( ) / 1000 * voi.get_cube_value() else: dos.cube[dos.cube == 0] = -1 a = voi.get_voi().get_voi_data().get_voi_cube( ) / 1000 * voi.get_cube_value() dos.cube[dos.cube == -1] = a.cube[dos.cube == -1] if not dos is None: if self.browse_for_file(): dos.write(self.output_path) else: return else: pass self.Close() def close(self, evt): self.Close()
class PlanDialog(wx.Dialog): def __init__(self): pre = wx.PreDialog() self.PostCreate(pre) pub.subscribe(self.patient_data_updated, "patient.loaded") pub.sendMessage("patient.request", {}) def Init(self, plan): self.plan = plan self.btn_ok = XRCCTRL(self, 'btn_ok') wx.EVT_BUTTON(self, XRCID('btn_ok'), self.save_and_close) self.btn_cancel = XRCCTRL(self, 'btn_close') wx.EVT_BUTTON(self, XRCID('btn_close'), self.close) self.init_general() self.init_trip_panel() self.init_opt_panel() self.init_calculation_panel() self.init_files_panel() self.init_advanved_dose() def patient_data_updated(self, msg): self.data = msg.data def init_files_panel(self): self.txt_ddd = XRCCTRL(self, "txt_ddd") self.txt_ddd.SetValue(self.plan.get_ddd_folder()) self.txt_spc = XRCCTRL(self, "txt_spc") self.txt_spc.SetValue(self.plan.get_spc_folder()) self.txt_sis = XRCCTRL(self, "txt_sis") self.txt_sis.SetValue(self.plan.get_sis_file()) wx.EVT_BUTTON(self, XRCID("btn_ddd"), self.on_btn_ddd_clicked) wx.EVT_BUTTON(self, XRCID("btn_spc"), self.on_btn_spc_clicked) wx.EVT_BUTTON(self, XRCID("btn_sis"), self.on_btn_sis_clicked) def init_general(self): self.drop_res_tissue_type = XRCCTRL(self, "drop_res_tissue_type") rbe_list = self.data.get_rbe() for rbe in rbe_list.get_rbe_list(): self.drop_res_tissue_type.Append(rbe.get_name()) self.select_drop_by_value(self.drop_res_tissue_type, self.plan.get_res_tissue_type()) self.drop_target_tissue_type = XRCCTRL(self, "drop_target_tissue_type") for rbe in rbe_list.get_rbe_list(): self.drop_target_tissue_type.Append(rbe.get_name()) self.select_drop_by_value(self.drop_target_tissue_type, self.plan.get_target_tissue_type()) def select_drop_by_value(self, drop, value): for i, item in enumerate(drop.GetItems()): if item == value: drop.SetSelection(i) def init_calculation_panel(self): self.check_phys_dose = XRCCTRL(self, "check_phys_dose") self.check_phys_dose.SetValue(self.plan.get_out_phys_dose()) self.check_bio_dose = XRCCTRL(self, "check_bio_dose") self.check_bio_dose.SetValue(self.plan.get_out_bio_dose()) self.check_dose_mean_let = XRCCTRL(self, "check_mean_let") self.check_dose_mean_let.SetValue(self.plan.get_out_dose_mean_let()) self.check_field = XRCCTRL(self, "check_field") self.check_field.SetValue(self.plan.get_out_field()) def init_opt_panel(self): self.txt_iterations = XRCCTRL(self, "txt_iterations") self.txt_iterations.SetValue("%d" % self.plan.get_iterations()) self.txt_eps = XRCCTRL(self, "txt_eps") self.txt_eps.SetValue("%f" % self.plan.get_eps()) self.txt_geps = XRCCTRL(self, "txt_geps") self.txt_geps.SetValue("%f" % self.plan.get_geps()) self.drop_opt_method = XRCCTRL(self, "drop_opt_method") self.select_drop_by_value(self.drop_opt_method, self.plan.get_opt_method()) self.drop_opt_principle = XRCCTRL(self, "drop_opt_principle") self.select_drop_by_value(self.drop_opt_principle, self.plan.get_opt_princip()) self.drop_dose_alg = XRCCTRL(self, "drop_dose_alg") self.select_drop_by_value(self.drop_dose_alg, self.plan.get_dose_algorithm()) self.drop_bio_alg = XRCCTRL(self, "drop_bio_alg") self.select_drop_by_value(self.drop_bio_alg, self.plan.get_dose_algorithm()) self.drop_opt_alg = XRCCTRL(self, "drop_opt_alg") self.select_drop_by_value(self.drop_opt_alg, self.plan.get_opt_algorithm()) def init_trip_panel(self): self.drop_location = XRCCTRL(self, "drop_location") if self.plan.is_remote(): self.drop_location.SetSelection(1) self.txt_working_dir = XRCCTRL(self, "txt_working_dir") self.txt_working_dir.SetValue(self.plan.get_working_dir()) wx.EVT_BUTTON(self, XRCID('btn_working_dir'), self.on_browse_working_dir) self.txt_username = XRCCTRL(self, "txt_username") self.txt_username.SetValue(self.plan.get_username()) self.txt_password = XRCCTRL(self, "txt_password") self.txt_password.SetValue(self.plan.get_password()) self.txt_server = XRCCTRL(self, "txt_server") self.txt_server.SetValue(self.plan.get_server()) def init_advanved_dose(self): self.drop_projectile = XRCCTRL(self, "drop_projectile") self.drop_projectile.Append("H") self.drop_projectile.Append("C") self.txt_dose_percent = XRCCTRL(self, "txt_dose_percent") wx.EVT_BUTTON(self, XRCID('btn_set_dosepercent'), self.set_dose_percent) wx.EVT_CHOICE(self, XRCID('drop_projectile'), self.on_projectile_changed) def on_projectile_changed(self, evt): projectile = self.drop_projectile.GetStringSelection() dose_percent = self.plan.get_dose_percent(projectile) if dose_percent is None: self.txt_dose_percent.SetValue("") else: self.txt_dose_percent.SetValue("%d" % dose_percent) def set_dose_percent(self, evt): if not self.drop_projectile.GetStringSelection() == "": self.plan.set_dose_percent( self.drop_projectile.GetStringSelection(), self.txt_dose_percent.GetValue()) def on_browse_working_dir(self, evt): dlg = wx.DirDialog( self, defaultPath=self.txt_working_dir.GetValue(), message= "Choose the folder pytripgui should use as working directory") if dlg.ShowModal() == wx.ID_OK: self.txt_working_dir.SetValue(dlg.GetPath()) def on_btn_ddd_clicked(self, evt): dlg = wx.DirDialog(self, defaultPath=self.txt_ddd.GetValue(), message="Choose folder where ddd files are located") if dlg.ShowModal() == wx.ID_OK: self.txt_ddd.SetValue(dlg.GetPath()) def on_btn_sis_clicked(self, evt): dlg = wx.FileDialog(self, defaultFile=self.txt_sis.GetValue(), message="Choose sis file") if dlg.ShowModal() == wx.ID_OK: self.txt_sis.SetValue(dlg.GetPath()) def on_btn_spc_clicked(self, evt): dlg = wx.DirDialog(self, defaultPath=self.txt_spc.GetValue(), message="Choose folder where spc files are located") if dlg.ShowModal() == wx.ID_OK: self.txt_spc.SetValue(dlg.GetPath()) def save_and_close(self, evt): self.plan.set_res_tissue_type( self.drop_res_tissue_type.GetStringSelection()) self.plan.set_target_tissue_type( self.drop_target_tissue_type.GetStringSelection()) if self.drop_location.GetSelection() is 0: self.plan.set_remote_state(False) else: self.plan.set_remote_state(True) self.plan.set_working_dir(self.txt_working_dir.GetValue()) self.plan.set_server(self.txt_server.GetValue()) self.plan.set_username(self.txt_username.GetValue()) self.plan.set_password(self.txt_password.GetValue()) self.plan.set_iterations(self.txt_iterations.GetValue()) self.plan.set_eps(self.txt_eps.GetValue()) self.plan.set_geps(self.txt_geps.GetValue()) self.plan.set_opt_method(self.drop_opt_method.GetStringSelection()) self.plan.set_opt_princip(self.drop_opt_principle.GetStringSelection()) self.plan.set_dose_algorithm(self.drop_dose_alg.GetStringSelection()) self.plan.set_bio_algorithm(self.drop_bio_alg.GetStringSelection()) self.plan.set_opt_algorithm(self.drop_opt_alg.GetStringSelection()) self.plan.set_out_phys_dose(self.check_phys_dose.GetValue()) self.plan.set_out_bio_dose(self.check_bio_dose.GetValue()) self.plan.set_out_dose_mean_let(self.check_dose_mean_let.GetValue()) self.plan.set_out_field(self.check_field.GetValue()) self.plan.set_ddd_folder(self.txt_ddd.GetValue()) self.plan.set_spc_folder(self.txt_ddd.GetValue()) self.plan.set_sis_file(self.txt_sis.GetValue()) self.Close() def close(self, evt): self.Close()