Beispiel #1
0
    def buttonbox(self):
        # add standard button box. override if you don't want the
        # standard buttons

        box = ttk.Frame(self)

        w = ttk.Button(box, text="OK", width=10, command=self.ok, default=tk.ACTIVE)
        w.pack(side=tk.LEFT, padx=5, pady=5)
        w = ttk.Button(box, text="Cancel", width=10, command=self.cancel)
        w.pack(side=tk.LEFT, padx=5, pady=5)

        self.bind("<Return>", self.ok)
        self.bind("<Escape>", self.cancel)

        box.pack()
Beispiel #2
0
    def __init__(self):
        TkToolWindow.__init__(self)

        driver_tab = tk.Frame(self._tool_tabs)
        self._tool_tabs.add(driver_tab, text='Driver')

        # Load Group {
        load_group = Group(driver_tab)
        load_group.pack(side='left', fill='y')
        load_group.name = 'Load'

        load_att_button = ttk.Button(load_group, text='Load Att Driver')
        load_att_button.pack(fill='x')
        load_ps_button = ttk.Button(load_group, text='Load PS Driver')
        load_ps_button.pack(fill='x')
        # } End

        self._make_window_manager_tab()

        iq_slider = IQSlider(self.tk_object,
                             i_range=128,
                             q_range=128,
                             relief='raised')
        iq_slider.pack(expand='yes', fill='both')
 def __init__(self, master=None):
     """Initialise the GUI."""
     ttk.Frame.__init__(self, master)
     # Load the merged metadata from file, and extract the template experiment
     user_metadata = metadata.read_user_config()
     self.template_expt = user_metadata['experiments'].pop('template')
     del user_metadata['devices']  # Until we support editing it
     self.metadata = wrap_dict(user_metadata)
     add_yaml_representers()
     # self.original_metadata = copy.deepcopy(self.metadata)
     # Action buttons
     # ttk.Button(self, text="REVERT", command=self.revert).grid(
     #     row=0, column=0, sticky=T.W, padx=5, pady=5)
     ttk.Button(self, text="SAVE", command=self.save).grid(row=0,
                                                           column=1,
                                                           sticky=T.W,
                                                           padx=5,
                                                           pady=5)
     ttk.Button(self, text="DONE", command=self.done).grid(row=0,
                                                           column=2,
                                                           sticky=T.W,
                                                           padx=5,
                                                           pady=5)
     # Content tabs
     tabs = self.tabs = ttk.Notebook(self, padding=2)
     self.session_tab = self.make_session_tab(tabs)
     self.people_tab = self.make_people_tab(tabs)
     self.expts_tab = self.make_expts_tab(tabs)
     tabs.enable_traversal()
     tabs.grid(row=1, column=0, columnspan=3)
     # Resize support - make the content section take it all
     self.rowconfigure(1, weight=1)
     self.columnconfigure('all', weight=1)
     tabs.rowconfigure('all', weight=1)
     tabs.columnconfigure('all', weight=1)
     self.pack(side="top", fill="both", expand=True)
 def make_people_tab(self, parent):
     """Build the people tab and add it to the parent."""
     frame = ttk.Frame(parent)
     # Choosing who to edit
     ttk.Label(frame, text='Edit person:').grid(row=0, column=0, sticky='e')
     person_list = ttk.Combobox(frame,
                                state='readonly',
                                width=10,
                                values=sorted(
                                    self.metadata['people'].keys()))
     person_list.bind('<<ComboboxSelected>>',
                      lambda e: self.update_people_tab(person_list.get()))
     person_list.grid(row=0, column=1, sticky='w')
     # Section for adding new people
     ttk.Label(frame, text='New person:').grid(row=2, column=0, sticky='e')
     new_person_var = T.StringVar()
     ttk.Entry(frame, textvariable=new_person_var,
               width=10).grid(row=2, column=1, sticky='w')
     # TODO: Make hitting return in the Entry click the Add button
     # TODO: Make the Add button stick next to the Entry box
     ttk.Button(frame,
                text='Add',
                command=lambda: self.add_person(new_person_var.get(
                ), person_list)).grid(row=2, column=2, sticky='w')
     # Fields to edit current person
     widgets = self.session_widgets = {}
     ttk.Label(frame, text='Full name:').grid(row=0, column=4, sticky='e')
     widgets['name'] = ttk.Entry(frame)
     widgets['name'].grid(row=0, column=5, sticky='w')
     ttk.Label(frame, text='ORCID:').grid(row=1, column=4, sticky='e')
     widgets['orcid'] = ttk.Entry(frame)
     widgets['orcid'].grid(row=1, column=5, sticky='w')
     ttk.Label(frame, text='SCOPUS ID:').grid(row=2, column=4, sticky='e')
     widgets['scopus_id'] = ttk.Entry(frame)
     widgets['scopus_id'].grid(row=2, column=5, sticky='w')
     if self.metadata['people']:
         person_list.set(person_list['values'][0])
         self.update_people_tab(person_list.get())
     # Resize support
     frame.rowconfigure('all', weight=0)
     frame.columnconfigure(0, weight=2)
     frame.columnconfigure(3, weight=1)
     frame.columnconfigure(6, weight=2)
     parent.add(frame, text='People')
     return frame
Beispiel #5
0
    def __init__(self, parent, title, app, **kw):
        kw = self.initKw(kw)
        MfxDialog.__init__(self, parent, title, kw.resizable, kw.default)
        top_frame, bottom_frame = self.createFrames(kw)
        self.createBitmaps(top_frame, kw)

        frame = ttk.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=10)
        frame.columnconfigure(0, weight=1)

        self.fonts = {}
        row = 0
        for fn, title in (  # ('default',        _('Default')),
            ('sans', _('HTML: ')),
            ('small', _('Small: ')),
            ('fixed', _('Fixed: ')),
            ('canvas_default', _('Tableau default: ')),
            ('canvas_fixed', _('Tableau fixed: ')),
            ('canvas_large', _('Tableau large: ')),
            ('canvas_small', _('Tableau small: ')),
        ):
            font = app.opt.fonts[fn]
            self.fonts[fn] = font
            ttk.Label(frame, text=title, anchor='w').grid(row=row,
                                                          column=0,
                                                          sticky='we')
            if font:
                title = ' '.join(
                    [str(i) for i in font if i not in ('roman', 'normal')])
            elif font is None:
                title = 'Default'
            label = ttk.Label(frame, font=font, text=title)
            label.grid(row=row, column=1, padx=8)
            b = ttk.Button(
                frame,
                text=_('Change...'),
                width=10,
                command=lambda label=label, fn=fn: self.selectFont(label, fn))
            b.grid(row=row, column=2)
            row += 1
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
Beispiel #6
0
    def createTopFrame(self, frame, player, gameid):
        app = self.app

        cond = (player not in app.stats.games_stats or
                gameid not in app.stats.games_stats[player] or
                not app.stats.games_stats[player][gameid].time_result.top)
        if cond:
            return False

        ttk.Label(frame, text=_('Minimum')
                  ).grid(row=0, column=1, padx=5, pady=5)
        ttk.Label(frame, text=_('Maximum')
                  ).grid(row=0, column=2, padx=5, pady=5)
        ttk.Label(frame, text=_('Average')
                  ).grid(row=0, column=3, padx=5, pady=5)
        # ttk.Label(frame, text=_('Total')).grid(row=0, column=4)

        s = app.stats.games_stats[player][gameid]

        row = 1
        ll = [
            (_('Playing time:'),
             format_time(s.time_result.min),
             format_time(s.time_result.max),
             format_time(s.time_result.average),
             format_time(s.time_result.total),
             s.time_result.top,
             ),
            (_('Moves:'),
             s.moves_result.min,
             s.moves_result.max,
             round(s.moves_result.average, 2),
             s.moves_result.total,
             s.moves_result.top,
             ),
            (_('Total moves:'),
             s.total_moves_result.min,
             s.total_moves_result.max,
             round(s.total_moves_result.average, 2),
             s.total_moves_result.total,
             s.total_moves_result.top,
             ),
            ]
        #  if s.score_result.min:
        #      ll.append(('Score:',
        #                 s.score_result.min,
        #                 s.score_result.max,
        #                 round(s.score_result.average, 2),
        #                 s.score_result.top,
        #                 ))
        #  if s.score_casino_result.min:
        #      ll.append(('Casino Score:',
        #                 s.score_casino_result.min,
        #                 s.score_casino_result.max,
        #                 round(s.score_casino_result.average, 2), ))
        for label, min, max, avr, tot, top in ll:
            ttk.Label(frame, text=label
                      ).grid(row=row, column=0, padx=5, pady=5)
            ttk.Label(frame, text=str(min)
                      ).grid(row=row, column=1, padx=5, pady=5)
            ttk.Label(frame, text=str(max)
                      ).grid(row=row, column=2, padx=5, pady=5)
            ttk.Label(frame, text=str(avr)
                      ).grid(row=row, column=3, padx=5, pady=5)
            # ttk.Label(frame, text=str(tot)).grid(row=row, column=4)

            def command(gameid=gameid, top=top):
                self.showTop(gameid, top)
            b = ttk.Button(frame, text=TOP_TITLE+' ...',
                           width=10, command=command)
            b.grid(row=row, column=5)
            row += 1
        return True
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        ttk.Frame.__init__(self, *args, **kwargs)
        self.init_settings()

        self.cookie = cookielib.MozillaCookieJar(self.cookie_filename)
        if (os.path.isfile(self.cookie_filename)):
            self.cookie.load(ignore_discard=True, ignore_expires=True)
        self.opener = urllib.request.build_opener(
            urllib.request.HTTPCookieProcessor(self.cookie))

        self.students = []
        self.username = StringVar()
        self.password = StringVar()
        self.course_listvar = StringVar()
        self.assignment_listvar = StringVar()
        self.student_listvar = StringVar()

        ttk.Label(self, text='Username: '******'Password: '******'*')
        self.password_entry.grid(column=2, row=2, sticky=(W, E))
        self.login_button = ttk.Button(self, text='Login', command=self.login)
        self.login_button.grid(column=2, row=3, stick=E)

        self.course_listbox = Listbox(self,
                                      height=6,
                                      width=35,
                                      listvariable=self.course_listvar,
                                      relief='sunken')
        self.course_listbox.grid(column=3,
                                 row=1,
                                 rowspan=3,
                                 padx=(5, 0),
                                 stick=(N, W, E, S))
        self.course_listbox.configure(exportselection=False)
        self.course_listbox.bind('<<ListboxSelect>>', self.load_assignments)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.course_listbox.yview)
        s.grid(column=4, row=1, rowspan=3, sticky=(N, S))
        self.course_listbox['yscrollcommand'] = s.set

        self.assignment_listbox = Listbox(self,
                                          height=6,
                                          width=35,
                                          listvariable=self.assignment_listvar,
                                          relief='sunken')
        self.assignment_listbox.grid(column=5,
                                     row=1,
                                     rowspan=3,
                                     padx=(5, 0),
                                     stick=(N, W, E, S))
        self.assignment_listbox.configure(exportselection=False)
        self.assignment_listbox.bind('<<ListboxSelect>>', self.load_students)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.assignment_listbox.yview)
        s.grid(column=6, row=1, rowspan=3, sticky=(N, S))
        self.assignment_listbox['yscrollcommand'] = s.set

        self.student_listbox = Listbox(self,
                                       height=20,
                                       listvariable=self.student_listvar,
                                       relief='sunken',
                                       font=font.Font(family='Consolas',
                                                      size=11))
        self.student_listbox.grid(column=1,
                                  row=4,
                                  columnspan=5,
                                  pady=(10, 5),
                                  stick=(N, W, E, S))
        self.student_listbox.configure(exportselection=False)
        s = ttk.Scrollbar(self,
                          orient=VERTICAL,
                          command=self.student_listbox.yview)
        s.grid(column=6, row=4, pady=(10, 5), sticky=(N, S))
        self.student_listbox['yscrollcommand'] = s.set

        self.readtxt_button = ttk.Button(self,
                                         text='读入成绩',
                                         command=self.read_txt)
        self.readtxt_button.grid(column=1, row=5, stick=E)
        self.dopublish_button = ttk.Button(self,
                                           text='确认发布',
                                           command=self.do_publish)
        self.dopublish_button.grid(column=2, row=5, stick=W)
        self.exportcsv_button = ttk.Button(self,
                                           text='导出成绩',
                                           command=self.export_csv)
        self.exportcsv_button.grid(column=3, row=5, stick=E)

        self.grid_columnconfigure(5, weight=1)
        self.grid_rowconfigure(4, weight=1)

        self.try_load_courses()
Beispiel #8
0
    def wand():
        gui.WandGUI()

    # Make Tkinter image objects for the icons
    dwarpim = PhotoImage(file=os.path.join(RESOURCE_PATH, 'icons/eye-8x.gif'))
    syncim = PhotoImage(file=os.path.join(RESOURCE_PATH, 'icons/pulse-8x.gif'))
    patternsim = PhotoImage(
        file=os.path.join(RESOURCE_PATH, 'icons/grid-four-up-8x.gif'))
    calibim = PhotoImage(
        file=os.path.join(RESOURCE_PATH, 'icons/calculator-8x.gif'))
    clickim = PhotoImage(
        file=os.path.join(RESOURCE_PATH, 'icons/location-8x.gif'))
    wandim = PhotoImage(file=os.path.join(RESOURCE_PATH, 'icons/wand.gif'))

    DWARP = ttk.Button(root, command=dwarp, image=dwarpim)
    DWARP.grid(row=0, column=0, padx=20, pady=10)
    Label(text="DWarp").grid(row=1, column=0, padx=10, pady=10)

    SYNC = ttk.Button(root, command=sync, image=syncim)
    SYNC.grid(row=0, column=1, padx=20, pady=10)
    Label(text="Sync").grid(row=1, column=1, padx=10, pady=10)

    PATTERNS = ttk.Button(root, command=patterns, image=patternsim)
    PATTERNS.grid(row=0, column=2, padx=20, pady=10)
    Label(text="Patterns").grid(row=1, column=2, padx=10, pady=10)

    CALIBRATE = ttk.Button(root, command=calibrate, image=calibim)
    CALIBRATE.grid(row=0, column=3, padx=20, pady=10)
    Label(text="Calibrate").grid(row=1, column=3, padx=10, pady=10)
Beispiel #9
0
    def createButtons(self, frame, kw):
        padx, pady = 4, 4
        xbutton = column = -1
        focus = None
        max_len = 0
        if 'sep' in kw.strings:
            sep_column = list(kw.strings).index('sep')
            strings = kw.strings[sep_column + 1:]
        else:
            sep_column = 0
            strings = kw.strings
        for s in strings:
            if isinstance(s, tuple):
                s = s[0]
            if s:
                s = s.replace('&', '')
                max_len = max(max_len, len(s))
            # print s, len(s)
        if max_len > 12 and WIN_SYSTEM == 'x11':
            button_width = max_len
        elif max_len > 9:
            button_width = max_len + 1
        elif max_len > 6:
            button_width = max_len + 2
        else:
            button_width = 8
        #
        for s in kw.strings:
            if s is None:
                xbutton += 1
                continue
            if s == 'sep':
                column += 1
                continue
            if isinstance(s, tuple):
                assert len(s) == 2
                button = int(s[1])
                s = s[0]
            else:
                xbutton += 1
                button = xbutton
            accel_indx = s.find('&')
            button_img = None
            if MfxDialog.button_img:
                button_img = MfxDialog.button_img.get(s)
            s = s.replace('&', '')
            if button < 0:
                widget = ttk.Button(frame, text=s, state="disabled")
            else:
                widget = ttk.Button(frame,
                                    text=s,
                                    default="normal",
                                    command=lambda self=self, button=button:
                                    self.mDone(button))
                if button == kw.default:
                    focus = widget
                    focus.config(default="active")
            self.buttons.append(widget)
            #
            column += 1
            if column >= sep_column:
                widget.config(width=button_width)
            else:
                widget.config(width=max(button_width, len(s)))
            if accel_indx >= 0:
                # key accelerator
                widget.config(underline=accel_indx)
                key = s[accel_indx]
                self.accel_keys[key.lower()] = widget
            #
            if button_img:
                widget.config(compound='left', image=button_img)
            widget.grid(column=column,
                        row=0,
                        sticky="nse",
                        padx=padx,
                        pady=pady)
        if focus is not None:

            def cb(event=None, w=focus):
                return w.event_generate('<<Invoke>>')

            bind(self.top, "<Return>", cb)
            bind(self.top, "<KP_Enter>", cb)
        # right justify
        frame.columnconfigure(sep_column, weight=1)
        return focus
Beispiel #10
0
    def __init__(self):
        self._root = tk.Tk()
        self._root.title('Loopy Upload Client')

        #self._root.geometry('500x300')
        self._root.resizable(width=False, height=False)

        self._root.grid_columnconfigure(0, weight=1)
        self._root.grid_rowconfigure(0, weight=1)

        self._frame = ttk.Frame(self._root)
        self._frame.columnconfigure(1, weight=1)
        self._frame.columnconfigure(1, weight=3)

        self._u_thread = None
        self._u_error = None

        self._auth_ok = False
        self._auth_ok_message = 'Ready'

        self._progress = 0

        def _label_entry(_lbl,
                         _txt,
                         _row,
                         is_password=False,
                         width=None,
                         **gridpos):
            l = ttk.Label(self._frame, text=_lbl)
            l.grid(column=0, row=_row, sticky='W', padx=5, pady=5, **gridpos)

            sv = tk.StringVar()
            sv.set(_txt or '')
            sve = ttk.Entry(self._frame,
                            textvariable=sv,
                            show="*" if is_password else None,
                            width=width)
            sve.grid(column=1,
                     row=_row,
                     padx=5,
                     pady=5,
                     sticky="EW",
                     **gridpos)

            return sv, sve

        self._url, self._urle = _label_entry(
            'Loopy URL', 'https://app.loopb.io/file-upload', 1)
        self._api_key, self._api_keye = _label_entry('API Key',
                                                     '',
                                                     2,
                                                     width=32)
        self._email, self._emaile = _label_entry('Email (optional)', '', 3)

        self._c_button = ttk.Button(self._frame,
                                    text='Connect',
                                    state='enabled')
        self._c_button.grid(column=1, row=4, sticky='E', padx=5, pady=5)
        self._c_button.configure(command=self._connect_button_clicked)

        self._u_button = ttk.Button(self._frame,
                                    text='Select & Upload',
                                    state='disabled')
        self._u_button.grid(column=1, row=5, sticky='E', padx=5, pady=5)
        self._u_button.configure(command=self._upload_button_clicked)

        self._result_label = ttk.Label(self._frame)
        self._result_label.grid(row=6, columnspan=3, padx=5, pady=5)

        self._frame.grid(padx=10, pady=10, sticky='NSEW')
    def make_expts_tab(self, parent):
        """Build a tab for setting experiment info."""
        expt_frame = ttk.Frame(parent)
        # Control pane along the top
        frame = ttk.Frame(expt_frame)

        ttk.Label(frame, text='Edit experiment:').grid(row=0,
                                                       column=0,
                                                       sticky='e')
        experiment = ttk.Combobox(frame,
                                  state='readonly',
                                  width=15,
                                  values=sorted(
                                      self.metadata['experiments'].keys()))
        experiment.bind(
            '<<ComboboxSelected>>',
            lambda e: self.update_expts_tab(expt_id=experiment.get()))
        experiment.grid(row=0, column=1, sticky='w')
        self.experiment_shown = None
        self.experiment_selector = experiment

        ttk.Label(frame, text='Clone experiment as:').grid(row=1,
                                                           column=0,
                                                           sticky='e')
        clone_var = T.StringVar()
        ttk.Entry(frame, textvariable=clone_var, width=15).grid(row=1,
                                                                column=1,
                                                                sticky='we')
        self.clone_expt_button = ttk.Button(
            frame,
            text='Clone',
            command=lambda: self.add_expt(clone_var.get(),
                                          clone=experiment.get()))
        self.clone_expt_button.grid(row=1, column=2, sticky='w')
        if not self.metadata['experiments']:
            self.clone_expt_button.state(['disabled'])

        ttk.Label(frame, text='Add experiment:').grid(row=2,
                                                      column=0,
                                                      sticky='e')
        add_var = T.StringVar()
        ttk.Entry(frame, textvariable=add_var, width=15).grid(row=2,
                                                              column=1,
                                                              sticky='we')
        ttk.Button(frame,
                   text='Add',
                   command=lambda: self.add_expt(add_var.get())).grid(
                       row=2, column=2, sticky='w')

        frame.columnconfigure(0, weight=1)  # Expand at the sides
        frame.columnconfigure(3, weight=1)
        frame.pack(side='top', fill='x', expand=True)
        # Experiment property editing below the control pane; frame per 'item',
        # all in a scrolling canvas
        self.expts_canvas = canvas = T.Canvas(expt_frame, borderwidth=0)
        canvas.pack(side='left', fill='both', expand=True)
        frame = ttk.Frame(canvas)
        scrollbar = ttk.Scrollbar(expt_frame,
                                  orient='vertical',
                                  command=canvas.yview)
        scrollbar.pack(side='right', fill='y')
        canvas.configure(yscrollcommand=scrollbar.set)
        canvas.create_window((0, 0), window=frame, anchor='nw')
        frame.bind("<Configure>", self.on_expts_frame_configure)
        # The contents
        self.expts_boxes = {}
        self.make_expts_part(frame, 'description')
        self.make_expts_part(frame, 'optophysiology')
        self.make_stim_frame(frame)
        for part in [
                'data_collection', 'pharmacology', 'protocol', 'slices',
                'stimulus', 'subject', 'surgery', 'virus',
                'related_publications', 'notes'
        ]:
            self.make_expts_part(frame, part)
        # Show current experiment, if any
        if self.metadata['experiments']:
            experiment.set(experiment['values'][0])
            self.update_expts_tab(expt_id=experiment.get())
        # Add to tabs
        parent.add(expt_frame, text='Experiments')
        return expt_frame
Beispiel #12
0
 def addbutton(self, lf, text, command, pos, disabled=False):
     self.widgets[text] = ttk.Button(lf, text=text, command=command)
     self.widgets[text].grid(column=pos, row=0, sticky='E')
     if disabled:
         self.widgets[text].state(['disabled'])
Beispiel #13
0
    def _create_widgets(self):
        """Create a nice GUI using the enhanced widget set provided by
        the ttk extension to Tkinter, available in Python 2.7 or newer
        """
        #---- create the GUIs
        insts = ['NIRCam', 'NIRSpec', 'NIRISS', 'MIRI', 'FGS']
        self.root = tk.Tk()
        self.root.geometry('+50+50')
        self.root.title("James Webb Space Telescope PSF Calculator")

        frame = ttk.Frame(self.root)
        #frame = ttk.Frame(self.root, padx=10,pady=10)

        #ttk.Label(frame, text='James Webb PSF Calculator' ).grid(row=0)

        #-- star
        lf = ttk.LabelFrame(frame, text='Source Properties')

        if _HAS_PYSYNPHOT:
            self._add_labeled_dropdown("SpType",
                                       lf,
                                       label='    Spectral Type:',
                                       values=poppy.specFromSpectralType(
                                           "", return_list=True),
                                       default='G0V',
                                       width=25,
                                       position=(0, 0),
                                       sticky='W')
            ttk.Button(lf, text='Plot spectrum',
                       command=self.ev_plotspectrum).grid(row=0,
                                                          column=2,
                                                          sticky='E',
                                                          columnspan=4)

        r = 1
        fr2 = ttk.Frame(lf)

        self._add_labeled_entry("source_off_r",
                                fr2,
                                label='    Source Position: r=',
                                value='0.0',
                                width=5,
                                position=(r, 0),
                                sticky='W')
        self._add_labeled_entry("source_off_theta",
                                fr2,
                                label='arcsec,  PA=',
                                value='0',
                                width=3,
                                position=(r, 2),
                                sticky='W')

        self.vars["source_off_centerpos"] = tk.StringVar()
        self.vars["source_off_centerpos"].set('corner')

        ttk.Label(fr2, text='deg, centered on ').grid(row=r, column=4)
        pixel = ttk.Radiobutton(fr2,
                                text='pixel',
                                variable=self.vars["source_off_centerpos"],
                                value='pixel')
        pixel.grid(row=r, column=5)
        corner = ttk.Radiobutton(fr2,
                                 text='corner',
                                 variable=self.vars["source_off_centerpos"],
                                 value='corner')
        corner.grid(row=r, column=6)
        fr2.grid(row=r, column=0, columnspan=5, sticky='W')

        lf.columnconfigure(2, weight=1)
        lf.grid(row=1, sticky='E,W', padx=10, pady=5)

        #-- instruments
        lf = ttk.LabelFrame(frame, text='Instrument Config')
        notebook = ttk.Notebook(lf)
        self.widgets['tabset'] = notebook
        notebook.pack(fill='both')
        for iname, i in zip(insts, range(len(insts))):
            page = ttk.Frame(notebook)
            notebook.add(page, text=iname)
            notebook.select(i)  # make it active
            self.widgets[notebook.select(
            )] = iname  # save reverse lookup from meaningless widget "name" to string name
            if iname == 'NIRCam':
                lframe = ttk.Frame(page)

                ttk.Label(lframe,
                          text='Configuration Options for ' + iname +
                          ',     module: ').grid(row=0, column=0, sticky='W')
                mname = 'NIRCam module'
                self.vars[mname] = tk.StringVar()
                self.widgets[mname] = ttk.Combobox(
                    lframe,
                    textvariable=self.vars[mname],
                    width=2,
                    state='readonly')
                self.widgets[mname].grid(row=0, column=1, sticky='W')
                self.widgets[mname]['values'] = ['A', 'B']
                self.widgets[mname].set('A')

                lframe.grid(row=0, columnspan=2, sticky='W')
            else:
                ttk.Label(page,
                          text='Configuration Options for ' + iname +
                          "                      ").grid(row=0,
                                                         columnspan=2,
                                                         sticky='W')

            ttk.Button(page,
                       text='Display Optics',
                       command=self.ev_displayOptics).grid(column=2,
                                                           row=0,
                                                           sticky='E',
                                                           columnspan=3)

            #if  iname != 'TFI':
            self._add_labeled_dropdown(
                iname + "_filter",
                page,
                label='    Filter:',
                values=self.instrument[iname].filter_list,
                default=self.instrument[iname].filter,
                width=12,
                position=(1, 0),
                sticky='W')
            #else:
            #ttk.Label(page, text='Etalon wavelength: ' , state='disabled').grid(row=1, column=0, sticky='W')
            #self.widgets[iname+"_wavelen"] = ttk.Entry(page, width=7) #, disabledforeground="#A0A0A0")
            #self.widgets[iname+"_wavelen"].insert(0, str(self.instrument[iname].etalon_wavelength))
            #self.widgets[iname+"_wavelen"].grid(row=1, column=1, sticky='W')
            #ttk.Label(page, text=' um' ).grid(row=1, column=2, sticky='W')

            #self.vars[iname+"_filter"] = tk.StringVar()
            #self.widgets[iname+"_filter"] = ttk.Combobox(page,textvariable =self.vars[iname+"_filter"], width=10, state='readonly')
            #self.widgets[iname+"_filter"]['values'] = self.instrument[iname].filter_list
            #self.widgets[iname+"_filter"].set(self.instrument[iname].filter)
            #self.widgets[iname+"_filter"]['readonly'] = True
            #ttk.Label(page, text='    Filter: ' ).grid(row=1, column=0)
            #self.widgets[iname+"_filter"].grid(row=1, column=1)

            #if hasattr(self.instrument[iname], 'ifu_wavelength'):
            if iname == 'NIRSpec' or iname == 'MIRI':
                fr2 = ttk.Frame(page)
                #label = 'IFU' if iname !='TFI' else 'TF'
                ttk.Label(fr2, text='   IFU wavelen: ',
                          state='disabled').grid(row=0, column=0)
                self.widgets[iname + "_ifu_wavelen"] = ttk.Entry(
                    fr2, width=5)  #, disabledforeground="#A0A0A0")
                self.widgets[iname + "_ifu_wavelen"].insert(
                    0, str(self.instrument[iname].monochromatic))
                self.widgets[iname + "_ifu_wavelen"].grid(row=0, column=1)
                self.widgets[iname + "_ifu_wavelen"].state(['disabled'])
                ttk.Label(fr2, text=' um', state='disabled').grid(row=0,
                                                                  column=2)
                fr2.grid(row=1, column=2, columnspan=6, sticky='E')

                iname2 = iname + ""  # need to make a copy so the following lambda function works right:
                self.widgets[iname + "_filter"].bind(
                    '<<ComboboxSelected>>',
                    lambda e: self.ev_update_ifu_label(iname2))

            if len(self.instrument[iname].image_mask_list) > 0:
                masks = self.instrument[iname].image_mask_list
                masks.insert(0, "")

                self._add_labeled_dropdown(iname + "_coron",
                                           page,
                                           label='    Coron:',
                                           values=masks,
                                           width=12,
                                           position=(2, 0),
                                           sticky='W')
                #self.vars[iname+"_coron"] = tk.StringVar()
                #self.widgets[iname+"_coron"] = ttk.Combobox(page,textvariable =self.vars[iname+"_coron"], width=10, state='readonly')
                #self.widgets[iname+"_coron"]['values'] = masks
                #ttk.Label(page, text='    Coron: ' ).grid(row=2, column=0)
                #self.widgets[iname+"_coron"].set(self.widgets[iname+"_coron"]['values'][0])
                #self.widgets[iname+"_coron"].grid(row=2, column=1)

                #fr2 = ttk.Frame(page)
                #self.vars[iname+"_cor_off_r"] = tk.StringVar()
                #self.vars[iname+"_cor_off_theta"] = tk.StringVar()
                #ttk.Label(fr2, text='target offset:  r=' ).grid(row=2, column=4)
                #self.widgets[iname+"_cor_off_r"] = ttk.Entry(fr2,textvariable =self.vars[iname+"_cor_off_r"], width=5)
                #self.widgets[iname+"_cor_off_r"].insert(0,"0.0")
                #self.widgets[iname+"_cor_off_r"].grid(row=2, column=5)
                #ttk.Label(fr2, text='arcsec,  PA=' ).grid(row=2, column=6)
                #self.widgets[iname+"_cor_off_theta"] = ttk.Entry(fr2,textvariable =self.vars[iname+"_cor_off_theta"], width=3)
                #self.widgets[iname+"_cor_off_theta"].insert(0,"0")
                #self.widgets[iname+"_cor_off_theta"].grid(row=2, column=7)
                #ttk.Label(fr2, text='deg' ).grid(row=2, column=8)
                #fr2.grid(row=2,column=3, sticky='W')

            if len(self.instrument[iname].image_mask_list) > 0:
                masks = self.instrument[iname].pupil_mask_list
                masks.insert(0, "")
                self._add_labeled_dropdown(iname + "_pupil",
                                           page,
                                           label='    Pupil:',
                                           values=masks,
                                           width=12,
                                           position=(3, 0),
                                           sticky='W')

                fr2 = ttk.Frame(page)
                self._add_labeled_entry(iname + "_pupilshift_x",
                                        fr2,
                                        label='  pupil shift in X:',
                                        value='0',
                                        width=3,
                                        position=(3, 4),
                                        sticky='W')
                self._add_labeled_entry(iname + "_pupilshift_y",
                                        fr2,
                                        label=' Y:',
                                        value='0',
                                        width=3,
                                        position=(3, 6),
                                        sticky='W')

                ttk.Label(fr2, text='% of pupil').grid(row=3, column=8)
                fr2.grid(row=3, column=3, sticky='W')

            ttk.Label(page, text='Configuration Options for the OTE').grid(
                row=4, columnspan=2, sticky='W')
            fr2 = ttk.Frame(page)

            opd_list = self.instrument[iname].opd_list
            opd_list.insert(0, "Zero OPD (perfect)")
            #if os.getenv("WEBBPSF_ITM") or 1:
            if self._enable_opdserver:
                opd_list.append("OPD from ITM Server")
            default_opd = self.instrument[iname].pupilopd if self.instrument[
                iname].pupilopd is not None else "Zero OPD (perfect)"
            self._add_labeled_dropdown(iname + "_opd",
                                       fr2,
                                       label='    OPD File:',
                                       values=opd_list,
                                       default=default_opd,
                                       width=21,
                                       position=(0, 0),
                                       sticky='W')

            self._add_labeled_dropdown(iname + "_opd_i",
                                       fr2,
                                       label=' # ',
                                       values=[str(i) for i in range(10)],
                                       width=3,
                                       position=(0, 2),
                                       sticky='W')

            self.widgets[iname + "_opd_label"] = ttk.Label(
                fr2, text=' 0 nm RMS            ', width=35)
            self.widgets[iname + "_opd_label"].grid(column=4,
                                                    sticky='W',
                                                    row=0)

            self.widgets[iname + "_opd"].bind(
                '<<ComboboxSelected>>', lambda e: self.ev_update_OPD_labels())
            # The below code does not work, and I can't tell why. This only ever has iname = 'FGS' no matter which instrument.
            # So instead brute-force it with the above to just update all 5.
            #lambda e: self.ev_update_OPD_label(self.widgets[iname+"_opd"], self.widgets[iname+"_opd_label"], iname) )
            ttk.Button(fr2, text='Display',
                       command=self.ev_displayOPD).grid(column=5,
                                                        sticky='E',
                                                        row=0)

            fr2.grid(row=5, column=0, columnspan=4, sticky='S')

            # ITM interface here - build the widgets now but they will be hidden by default until the ITM option is selected
            fr2 = ttk.Frame(page)
            self._add_labeled_entry(iname + "_coords",
                                    fr2,
                                    label='    Source location:',
                                    value='0, 0',
                                    width=12,
                                    position=(1, 0),
                                    sticky='W')
            units_list = ['V1,V2 coords', 'detector pixels']
            self._add_labeled_dropdown(iname + "_coord_units",
                                       fr2,
                                       label='in:',
                                       values=units_list,
                                       default=units_list[0],
                                       width=11,
                                       position=(1, 2),
                                       sticky='W')
            choose_list = [
                '', 'SI center', 'SI upper left corner',
                'SI upper right corner', 'SI lower left corner',
                'SI lower right corner'
            ]
            self._add_labeled_dropdown(iname + "_coord_choose",
                                       fr2,
                                       label='or select:',
                                       values=choose_list,
                                       default=choose_list[0],
                                       width=21,
                                       position=(1, 4),
                                       sticky='W')

            ttk.Label(fr2, text='    ITM output:').grid(row=2,
                                                        column=0,
                                                        sticky='W')
            self.widgets[iname + "_itm_output"] = ttk.Label(
                fr2, text='    - no file available yet -')
            self.widgets[iname + "_itm_output"].grid(row=2,
                                                     column=1,
                                                     columnspan=4,
                                                     sticky='W')
            ttk.Button(fr2,
                       text='Access ITM...',
                       command=self.ev_launch_ITM_dialog).grid(column=5,
                                                               sticky='E',
                                                               row=2)

            fr2.grid(row=6, column=0, columnspan=4, sticky='SW')
            self.widgets[iname + "_itm_coords"] = fr2

        self.ev_update_OPD_labels()
        lf.grid(row=2, sticky='E,W', padx=10, pady=5)
        notebook.select(0)

        lf = ttk.LabelFrame(frame, text='Calculation Options')
        r = 0
        self._add_labeled_entry('FOV',
                                lf,
                                label='Field of View:',
                                width=3,
                                value='5',
                                postlabel='arcsec/side',
                                position=(r, 0))
        r += 1
        self._add_labeled_entry(
            'detector_oversampling',
            lf,
            label='Output Oversampling:',
            width=3,
            value='2',
            postlabel='x finer than instrument pixels       ',
            position=(r, 0))

        #self.vars['downsamp'] = tk.BooleanVar()
        #self.vars['downsamp'].set(True)
        #self.widgets['downsamp'] = ttk.Checkbutton(lf, text='Save in instr. pixel scale, too?', onvalue=True, offvalue=False,variable=self.vars['downsamp'])
        #self.widgets['downsamp'].grid(row=r, column=4, sticky='E')

        output_options = [
            'Oversampled PSF only', 'Oversampled + Detector Res. PSFs',
            'Mock full image from JWST DMS'
        ]
        self._add_labeled_dropdown("output_type",
                                   fr2,
                                   label='Output format:',
                                   values=output_options,
                                   default=output_options[1],
                                   width=31,
                                   position=(r, 4),
                                   sticky='W')

        r += 1
        self._add_labeled_entry('fft_oversampling',
                                lf,
                                label='Coronagraph FFT Oversampling:',
                                width=3,
                                value='2',
                                postlabel='x finer than Nyquist',
                                position=(r, 0))
        r += 1
        self._add_labeled_entry('nlambda',
                                lf,
                                label='# of wavelengths:',
                                width=3,
                                value='',
                                position=(r, 0),
                                postlabel='Leave blank for autoselect')
        r += 1

        self._add_labeled_dropdown("jitter",
                                   lf,
                                   label='Jitter model:',
                                   values=[
                                       'Just use OPDs', 'Gaussian - 7 mas rms',
                                       'Gaussian - 30 mas rms'
                                   ],
                                   width=20,
                                   position=(r, 0),
                                   sticky='W',
                                   columnspan=2)
        r += 1
        self._add_labeled_dropdown("output_format",
                                   lf,
                                   label='Output Format:',
                                   values=[
                                       'Oversampled image',
                                       'Detector sampled image',
                                       'Both as FITS extensions',
                                       'Mock JWST DMS Output'
                                   ],
                                   width=30,
                                   position=(r, 0),
                                   sticky='W',
                                   columnspan=2)
        #self._add_labeled_dropdown("jitter", lf, label='Jitter model:', values=  ['Just use OPDs', 'Gaussian blur', 'Accurate yet SLOW grid'], width=20, position=(r,0), sticky='W', columnspan=2)

        lf.grid(row=4, sticky='E,W', padx=10, pady=5)

        lf = ttk.Frame(frame)

        def addbutton(self, lf, text, command, pos, disabled=False):
            self.widgets[text] = ttk.Button(lf, text=text, command=command)
            self.widgets[text].grid(column=pos, row=0, sticky='E')
            if disabled:
                self.widgets[text].state(['disabled'])

        addbutton(self, lf, 'Compute PSF', self.ev_calc_psf, 0)
        addbutton(self,
                  lf,
                  'Display PSF',
                  self.ev_displayPSF,
                  1,
                  disabled=True)
        addbutton(self,
                  lf,
                  'Display profiles',
                  self.ev_displayProfiles,
                  2,
                  disabled=True)
        addbutton(self, lf, 'Save PSF As...', self.ev_SaveAs, 3, disabled=True)
        addbutton(self,
                  lf,
                  'More options...',
                  self.ev_options,
                  4,
                  disabled=False)

        ttk.Button(lf, text='Quit', command=self.quit).grid(column=5, row=0)
        lf.columnconfigure(2, weight=1)
        lf.columnconfigure(4, weight=1)
        lf.grid(row=5, sticky='E,W', padx=10, pady=15)

        frame.grid(row=0, sticky='N,E,S,W')
        frame.columnconfigure(0, weight=1)
        frame.rowconfigure(0, weight=1)
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=1)
Beispiel #14
0
    def __init__(self, parent, app=None, home=None):
        self.parent = parent
        self.app = app
        self.home = home
        self.url = None
        self.history = Struct(
            list=[],
            index=0,
        )
        self.visited_urls = []
        # need to keep a reference because of garbage collection
        self.images = {}
        self.defcursor = parent["cursor"]
        # self.defcursor = 'xterm'
        self.handcursor = "hand2"

        frame = ttk.Frame(parent, width=640, height=440)
        frame.pack(expand=True, fill='both')
        frame.grid_propagate(False)

        # create buttons
        button_width = 8
        self.homeButton = ttk.Button(frame,
                                     text=_("Index"),
                                     width=button_width,
                                     command=self.goHome)
        self.homeButton.grid(row=0, column=0, sticky='w')
        self.backButton = ttk.Button(frame,
                                     text=_("Back"),
                                     width=button_width,
                                     command=self.goBack)
        self.backButton.grid(row=0, column=1, sticky='w')
        self.forwardButton = ttk.Button(frame,
                                        text=_("Forward"),
                                        width=button_width,
                                        command=self.goForward)
        self.forwardButton.grid(row=0, column=2, sticky='w')
        self.closeButton = ttk.Button(frame,
                                      text=_("Close"),
                                      width=button_width,
                                      command=self.destroy)
        self.closeButton.grid(row=0, column=3, sticky='e')

        # create text widget
        text_frame = ttk.Frame(frame)
        text_frame.grid(row=1,
                        column=0,
                        columnspan=4,
                        sticky='nsew',
                        padx=1,
                        pady=1)
        vbar = ttk.Scrollbar(text_frame)
        vbar.pack(side='right', fill='y')
        self.text = tkinter.Text(text_frame,
                                 fg='black',
                                 bg='white',
                                 bd=1,
                                 relief='sunken',
                                 cursor=self.defcursor,
                                 wrap='word',
                                 padx=10)
        self.text.pack(side='left', fill='both', expand=True)
        self.text["yscrollcommand"] = vbar.set
        vbar["command"] = self.text.yview

        # statusbar
        self.statusbar = HtmlStatusbar(frame, row=2, column=0, columnspan=4)

        frame.columnconfigure(2, weight=1)
        frame.rowconfigure(1, weight=1)

        # load images
        for name, fn in self.symbols_fn.items():
            self.symbols_img[name] = self.getImage(fn)

        self.initBindings()