def make_filter_combos(self): self.cam_combo = make_cb(["sky", "sbc"]) self.exp_combo = make_cb(exp_times) self.date_combo = make_cb(date_keys) self.zframe_combo = make_cb(["No z-frames", "only z-frames", "all"]) self.filters = DropDownCheckEntryBox(FILTER_CACHE) save_group = self.make_save_group() self.filter_box = make_box(gtk.HBox, [self.cam_combo, self.exp_combo, self.date_combo, self.zframe_combo, self.filters.box, save_group])
class GuiQuery: def __init__(self): self.win = gtk.Window() self.win.connect("destroy", lambda x: gtk.main_quit()) self.win.set_default_size(800,600) self.win.set_title("Gattini Data Explorer") plot_button = make_button("Plot", self._plot) self.make_cmap_combo() self.make_filter_combos() self.make_xyc_combos(per_image_fields + per_star_fields) self.image_spin = make_integer_spinner(1, count("image")) self.star_spin = make_integer_spinner(1, count("star")) vsep = [gtk.VSeparator() for i in range(4)] [v.set_property("width-request", 1) for v in vsep] toolbar1 = make_box(gtk.HBox, [plot_button, vsep[0], self.xyc_box, vsep[1], self.image_spin, self.star_spin, vsep[3], self.cmap_combo]) toolbar2 = make_box(gtk.HBox, [self.filter_box, vsep[2]]) self.nb = gtk.Notebook() self.nb.set_tab_pos(gtk.POS_TOP) self.nb.connect("switch-page", self.change_page) self.tabs = [] for tab, name in [(PlottingTab, "plot"), (ImageTab, "image"), (StarTab, "star"), (HistTab, "hist")]: tab = tab(self) self.tabs.append(tab) self.nb.append_page(tab.box, tab.label) setattr(self, name, tab) box = gtk.VBox() box.pack_start(toolbar1, False, False, 0) box.pack_start(toolbar2, False, False, 0) box.pack_start(self.nb) self.win.add(box) self.win.show_all() def change_page(self, notebook, page, page_num): self.get_active_tab().on_unfocus() self.tabs[page_num].on_focus() def get_active_tab(self): return self.tabs[self.nb.get_current_page()] def _plot(self, button): """ Call the plot method of the selected tab. """ self.get_active_tab().plot() self.filters.update() def make_cmap_combo(self): self.cmap_combo = make_cmap_combo() def make_filter_combos(self): self.cam_combo = make_cb(["sky", "sbc"]) self.exp_combo = make_cb(exp_times) self.date_combo = make_cb(date_keys) self.zframe_combo = make_cb(["No z-frames", "only z-frames", "all"]) self.filters = DropDownCheckEntryBox(FILTER_CACHE) save_group = self.make_save_group() self.filter_box = make_box(gtk.HBox, [self.cam_combo, self.exp_combo, self.date_combo, self.zframe_combo, self.filters.box, save_group]) def get_filters(self): cam = get_combo_item(self.cam_combo) dates = date_vals[date_keys.index(get_combo_item(self.date_combo))] exp = get_combo_item(self.exp_combo) zframes = get_combo_item(self.zframe_combo) if exp == "None": exp = None else: exp = float(exp) filters, condition = self.filters.get_items_and_entry() print filters return cam, exp, dates, zframes, condition, filters def make_xyc_combos(self, fields): self.x_val_combo = make_cb(fields) self.y_val_combo = make_cb(fields) self.c_val_combo = make_cb(fields) self.xyc_box = make_box(gtk.HBox, [self.x_val_combo, self.y_val_combo, self.c_val_combo]) def get_tab(self): return self.get_active_tab().label.get_text() def save(self, button): print "self =", self self._plot(None) tab = self.get_tab() x, y, c = self.get_xyc() image = self.image_spin.get_value_as_int() star = self.star_spin.get_value_as_int() cmap = get_combo_item(self.cmap_combo) cam, exp, dates, zframes, _, filters = self.get_filters() hist = self.get_active_tab().get_hist_params() print "Saving hist", hist save_name = self.save_load_list.child.get_text() s = ":".join(map(str, [save_name, tab, x, y, c, image, star, cmap, cam, exp, dates, zframes, hist, filters])) + "\n" entries = open(".savefile", "r").readlines() f = open(".savefile", "w") f.write(s) for ent in entries: sn = ent.split(":")[0] if sn != save_name: f.write(ent) f.close() self.get_active_tab().f.savefig("/home/timl/thesis/images/%s.eps" % save_name) def load(self, button): load_name = self.save_load_list.child.get_text() print "loading", load_name f = open(".savefile", "r") for line in f.readlines(): save_name, tab, x, y, c, image, star, cmap, cam, exp, dates, zframes, hist, filters = line.split(":") if save_name == load_name: print "loading", save_name, tab, x, y, c, image, star, cmap, exp, dates, zframes, hist, filters break self.nb.set_current_page(self.tabs.index(tab)) set_combo_item(self.x_val_combo, x) set_combo_item(self.y_val_combo, y) set_combo_item(self.c_val_combo, c) self.image_spin.set_value(int(image)) self.star_spin.set_value(int(star)) set_combo_item(self.cmap_combo ,cmap) set_combo_item(self.cam_combo, cam) set_combo_item(self.exp_combo, exp) set_combo_item(self.date_combo, date_keys[date_vals.index(eval(dates))]) set_combo_item(self.zframe_combo, zframes) tab = self.get_active_tab().set_hist_params(eval(hist)) self.filters.load(eval(filters)) self._plot(None) def make_save_group(self): save_button = make_button("save", self.save) load_button = make_button("load", self.load) self.save_load_list = gtk.combo_box_entry_new_text() f = open(".savefile", "r") for line in f.readlines(): save_name = line.split(":")[0] self.save_load_list.append_text(save_name) return make_box(gtk.HBox, [self.save_load_list, save_button, load_button]) def get_xyc(self): x_field = get_combo_item(self.x_val_combo) y_field = get_combo_item(self.y_val_combo) c_field = get_combo_item(self.c_val_combo) return x_field, y_field, c_field