Пример #1
0
    def body(self, master):
        self.results = None # in case we cancel this gets returned
        self.results = None # in case we cancel this gets returned
        self.vars = {}
        self.widgets = {}
        self.values = {}

        colortables = [
         ('Jet (blue to red)',matplotlib.cm.jet),
         ('Gray', matplotlib.cm.gray),
         ('Heat (black-red-yellow)', matplotlib.cm.gist_heat),
         ('Copper (black to tan)',matplotlib.cm.copper),
         ('Stern',matplotlib.cm.gist_stern),
         ('Prism (repeating rainbow)', matplotlib.cm.prism)]

        self.colortables = dict(colortables)


        lf = ttk.LabelFrame(master, text='WebbPSF Advanced Options')

        r=1
        fr2 = ttk.Frame(lf)

        self.values['force_coron'] = ['regular propagation (MFT)', 'full coronagraphic propagation (FFT/SAM)']

        self._add_labeled_dropdown("force_coron", lf, label='Direct imaging calculations use', values=self.values['force_coron'],
                default = self.values['force_coron'][ 1 if self.input_options['force_coron'] else 0]  ,  width=30, position=(r,0), sticky='W')
        r+=1
        self.values['no_sam'] = ['semi-analytic method if possible', 'basic FFT method always']
        self._add_labeled_dropdown("no_sam", lf, label='Coronagraphic calculations use', values=self.values['no_sam'],
                default=self.values['no_sam'][ 1 if self.input_options['no_sam'] else 0] , width=30, position=(r,0), sticky='W')
        r+=1
        self._add_labeled_dropdown("parity", lf, label='Output pixel grid parity is', values=['odd', 'even', 'either'], default=self.input_options['parity'], width=10, position=(r,0), sticky='W')



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

        lf = ttk.LabelFrame(master, text='PSF Display Options')
        r=0
        self._add_labeled_dropdown("psf_scale", lf, label='    Display scale:', values=['log','linear'],default=self.input_options['psf_scale'], width=5, position=(r,0), sticky='W')
        r+=1
        self._add_labeled_entry("psf_vmin", lf, label='    Min scale value:', value="%.2g" % self.input_options['psf_vmin'], width=7, position=(r,0), sticky='W')
        r+=1
        self._add_labeled_entry("psf_vmax", lf, label='    Max scale value:', value="%.2g" % self.input_options['psf_vmax'], width=7, position=(r,0), sticky='W')
        r+=1
        self._add_labeled_dropdown("psf_normalize", lf, label='    Normalize PSF to:', values=['Total', 'Peak'], default=self.input_options['psf_normalize'], width=5, position=(r,0), sticky='W')
        r+=1
        self._add_labeled_dropdown("psf_cmap", lf, label='    Color table:', values=[a[0] for a in colortables],  default=self.input_options['psf_cmap_str'], width=20, position=(r,0), sticky='W')
        lf.grid(row=2, sticky='E,W', padx=10,pady=5)


        return self.widgets['force_coron']# return widget to have initial focus
Пример #2
0
 def _createChartInit(self, text):
     frame = ttk.LabelFrame(self.right_frame, text=text)
     frame.pack(side='top', fill='both', expand=False, padx=20, pady=10)
     style = ttk.Style(self.parent)
     fg = style.lookup('.', 'foreground') or None  # use default if fg == ''
     bg = style.lookup('.', 'background') or None
     self.fg = fg
     #
     w, h = self.tab_x[-1], max(self.tab_y[-1], self.oval_height+40)
     c = tkinter.Canvas(frame, width=w, height=h,
                        bg=bg, highlightthickness=0)
     c.pack(fill='both', expand=True)
     self.canvas = c
Пример #3
0
    def __init__(self, dialog, parent, app, player, gameid):
        ttk.Frame.__init__(self, parent)

        self.app = app
        self.dialog = dialog

        left_label = ttk.Label(self, image=app.gimages.logos[5])
        left_label.pack(side='left', expand=True, fill='both')

        frame = ttk.LabelFrame(self, text=_('Current game'),
                               padding=(10, 5, 10, 10))
        frame.pack(side='top', expand=True, fill='x', padx=10, pady=10)
        # frame.columnconfigure(0, weight=1)
        if not self.createTopFrame(frame, player, gameid):
            ttk.Label(frame, text=_('No TOP for this game')
                      ).pack(padx=10, pady=10)

        frame = ttk.LabelFrame(self, text=_('All games'),
                               padding=(10, 5, 10, 10))
        frame.pack(side='top', expand=True, fill='x', padx=10, pady=10)
        # frame.columnconfigure(0, weight=1)
        if not self.createTopFrame(frame, player, 'all'):
            ttk.Label(frame, text=_('No TOP for all games')
                      ).pack(padx=10, pady=10)
Пример #4
0
    def __init__(self, parent, title, app, gameid, bookmark=None, **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)
        #
        self.app = app
        self.gameid = gameid
        self.bookmark = bookmark
        self.random = None
        if self.TreeDataHolder_Class.data is None:
            self.TreeDataHolder_Class.data = self.TreeData_Class(app)
        #
        self.top.wm_minsize(400, 200)
        sw = self.top.winfo_screenwidth()
        sh = self.top.winfo_screenheight()

        h = sh * .8
        w1, w2 = min(250, sw / 4), max(sw / 2 + ((sw / 4) - 250), sw / 2)

        # print sw, w1, w2
        w2 = max(200, min(w2, 10 + 12 * (app.subsampled_images.CARDW + 10)))
        # print sw, w1, w2
        # padx, pady = kw.padx, kw.pady
        # padx, pady = kw.padx/2, kw.pady/2
        padx, pady = 4, 4
        # PanedWindow
        paned_window = ttk.PanedWindow(top_frame, orient='horizontal')
        paned_window.pack(expand=True, fill='both', padx=8, pady=8)
        left_frame = ttk.Frame(paned_window)
        right_frame = ttk.Frame(paned_window)
        paned_window.add(left_frame)
        paned_window.add(right_frame)
        # Tree
        font = app.getFont("default")
        self.tree = self.Tree_Class(self,
                                    left_frame,
                                    key=gameid,
                                    default=kw.default,
                                    font=font,
                                    width=w1,
                                    height=h)
        self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both')
        # LabelFrame
        info_frame = ttk.LabelFrame(right_frame, text=_('About game'))
        info_frame.grid(row=0,
                        column=0,
                        padx=padx,
                        pady=pady,
                        ipadx=4,
                        ipady=4,
                        sticky='nws')
        stats_frame = ttk.LabelFrame(right_frame, text=_('Statistics'))
        stats_frame.grid(row=0,
                         column=1,
                         padx=padx,
                         pady=pady,
                         ipadx=4,
                         ipady=4,
                         sticky='nws')
        # Info
        self.info_labels = {}
        for n, t, f, row in (
            ('name', _('Name:'), info_frame, 0),
            ('altnames', _('Alternate names:'), info_frame, 1),
            ('category', _('Category:'), info_frame, 2),
            ('type', _('Type:'), info_frame, 3),
            ('skill_level', _('Skill level:'), info_frame, 4),
            ('decks', _('Decks:'), info_frame, 5),
            ('redeals', _('Redeals:'), info_frame, 6),
                #
            ('played', _('Played:'), stats_frame, 0),
            ('won', _('Won:'), stats_frame, 1),
            ('lost', _('Lost:'), stats_frame, 2),
            ('time', _('Playing time:'), stats_frame, 3),
            ('moves', _('Moves:'), stats_frame, 4),
            ('percent', _('% won:'), stats_frame, 5),
        ):
            title_label = ttk.Label(f, text=t, justify='left', anchor='w')
            title_label.grid(row=row, column=0, sticky='nw', padx=4)
            text_label = ttk.Label(f, justify='left', anchor='w')
            text_label.grid(row=row, column=1, sticky='nw', padx=4)
            self.info_labels[n] = (title_label, text_label)
        # info_frame.columnconfigure(1, weight=1)
        info_frame.rowconfigure(6, weight=1)
        stats_frame.rowconfigure(6, weight=1)
        # Canvas
        self.preview = MfxScrolledCanvas(right_frame, width=w2)
        self.preview.setTile(app, app.tabletile_index, force=True)
        self.preview.grid(row=1,
                          column=0,
                          columnspan=3,
                          padx=padx,
                          pady=pady,
                          sticky='nsew')
        right_frame.columnconfigure(1, weight=1)
        right_frame.rowconfigure(1, weight=1)
        #
        focus = self.createButtons(bottom_frame, kw)
        # set the scale factor
        self.preview.canvas.preview = 2
        # create a preview of the current game
        self.preview_key = -1
        self.preview_game = None
        self.preview_app = None
        self.updatePreview(gameid, animations=0)
        # focus = self.tree.frame
        self.mainloop(focus, kw.timeout)
Пример #5
0
    def __init__(self, dialog, parent, app, player, gameid, **kw):
        ttk.Frame.__init__(self, parent)

        self.mapped = False

        self.dialog = dialog
        self.app = app
        self.player = player
        self.gameid = gameid
        self.items = []
        self.formatter = ProgressionFormatter(app, player, gameid)

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

        # constants
        w = dialog.tkfont.measure('M') * 42
        w = max(w, 500)
        w = min(w, 600)
        self.canvas_width, self.canvas_height = w, 325
        cond = parent.winfo_screenwidth() < 800 or \
            parent.winfo_screenheight() < 600
        if cond:
            self.canvas_width, self.canvas_height = 400, 200
        self.xmargin, self.ymargin = 10, 10
        self.graph_dx, self.graph_dy = 10, 10
        self.played_color = '#ff7ee9'
        self.won_color = '#00dc28'
        self.percent_color = 'blue'
        # create canvas
        self.canvas = canvas = tkinter.Canvas(frame, bg='#dfe8ff', bd=0,
                                              highlightthickness=1,
                                              highlightbackground='black',
                                              width=self.canvas_width,
                                              height=self.canvas_height)
        canvas.pack(side='left', padx=5)

        # right frame
        right_frame = ttk.Frame(frame)
        right_frame.pack(side='left', fill='x', padx=5)
        self.all_games_variable = var = tkinter.StringVar()
        var.set('all')
        b = ttk.Radiobutton(right_frame, text=_('All games'),
                            variable=var, value='all',
                            command=self.updateGraph)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        b = ttk.Radiobutton(right_frame, text=_('Current game'),
                            variable=var, value='current',
                            command=self.updateGraph)
        b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Statistics for'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.variable = var = tkinter.StringVar()
        var.set('week')
        for v, t in (
            ('week',  _('Last 7 days')),
            ('month', _('Last month')),
            ('year',  _('Last year')),
            ('all',   _('All time')),
                ):
            b = ttk.Radiobutton(label_frame, text=t, variable=var,
                                value=v, command=self.updateGraph)
            b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Show graphs'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.played_graph_var = tkinter.BooleanVar()
        self.played_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('Played'),
                            command=self.updateGraph,
                            variable=self.played_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.won_graph_var = tkinter.BooleanVar()
        self.won_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('Won'),
                            command=self.updateGraph,
                            variable=self.won_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)
        self.percent_graph_var = tkinter.BooleanVar()
        self.percent_graph_var.set(True)
        b = ttk.Checkbutton(label_frame, text=_('% won'),
                            command=self.updateGraph,
                            variable=self.percent_graph_var)
        b.pack(fill='x', expand=True, padx=3, pady=1)

        label_frame = ttk.LabelFrame(right_frame, text=_('Date format'))
        label_frame.pack(side='top', fill='x', pady=5)
        self.date_format = tkinter.StringVar()
        self.date_format.set(self.app.opt.date_format)
        b = ttk.Radiobutton(label_frame, text=_('MM-DD'),
                            command=self.updateDateFormat,
                            variable=self.date_format,
                            value='%m-%d')
        b.pack(fill='x', expand=True, padx=3, pady=1)
        b = ttk.Radiobutton(label_frame, text=_('DD-MM'),
                            command=self.updateDateFormat,
                            variable=self.date_format,
                            value='%d-%m')
        b.pack(fill='x', expand=True, padx=3, pady=1)

        # self.createGraph()
        bind(canvas, '<Map>', self.createGraph)
Пример #6
0
    def __init__(self, parent, title, cardset, images, **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(fill="both", expand=True, padx=5, pady=10)
        #
        #
        row = 0
        info_frame = ttk.LabelFrame(frame, text=_('About cardset'))
        info_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
                        padx=0, pady=5, ipadx=5, ipady=5)
        row += 1
        styles = nationalities = year = None
        if cardset.si.styles:
            styles = '\n'.join([CSI.STYLE[i] for i in cardset.si.styles])
        if cardset.si.nationalities:
            nationalities = '\n'.join([CSI.NATIONALITY[i]
                                       for i in cardset.si.nationalities])
        if cardset.year:
            year = str(cardset.year)
        frow = 0
        for n, t in (
            # ('Version:', str(cardset.version)),
            (_('Type:'),          CSI.TYPE[cardset.type]),
            (_('Styles:'),        styles),
            (_('Nationality:'),   nationalities),
            (_('Year:'),          year),
            # (_('Number of cards:'), str(cardset.ncards)),
            (_('Size:'), '%d x %d' % (cardset.CARDW, cardset.CARDH)),
                ):
            if t is not None:
                label = ttk.Label(info_frame, text=n,
                                  anchor='w', justify='left')
                label.grid(row=frow, column=0, sticky='nw', padx=4)
                label = ttk.Label(info_frame, text=t,
                                  anchor='w', justify='left')
                label.grid(row=frow, column=1, sticky='nw', padx=4)
                frow += 1
        if images:
            try:
                from random import choice
                im = choice(images)
                f = os.path.join(cardset.dir, cardset.backname)
                self.back_image = loadImage(file=f)  # store the image
                label = ttk.Label(info_frame, image=im, padding=5)
                label.grid(row=0, column=2, rowspan=frow+1, sticky='ne')
                label = ttk.Label(info_frame, image=self.back_image,
                                  padding=(0, 5, 5, 5))  # left margin = 0
                label.grid(row=0, column=3, rowspan=frow+1, sticky='ne')

                info_frame.columnconfigure(2, weight=1)
                info_frame.rowconfigure(frow, weight=1)
            except Exception:
                pass
        if USE_PIL:
            padx = 4
            pady = 0
            settings_frame = ttk.LabelFrame(frame, text=_('Settings'))
            settings_frame.grid(row=row, column=0, columnspan=2, sticky='ew',
                                padx=0, pady=5, ipadx=5, ipady=5)
            row += 1
            var = tkinter.IntVar()
            self.x_offset = PysolScale(
                settings_frame, label=_('X offset:'),
                from_=5, to=40, resolution=1,
                orient='horizontal', variable=var,
                value=cardset.CARD_XOFFSET,
                # command=self._updateScale
                )
            self.x_offset.grid(row=0, column=0, sticky='ew',
                               padx=padx, pady=pady)
            var = tkinter.IntVar()
            self.y_offset = PysolScale(
                settings_frame, label=_('Y offset:'),
                from_=5, to=40, resolution=1,
                orient='horizontal', variable=var,
                value=cardset.CARD_YOFFSET,
                # command=self._updateScale
                )
            self.y_offset.grid(row=1, column=0, sticky='ew',
                               padx=padx, pady=pady)
            row += 1

        # bg = top_frame["bg"]
        bg = 'white'
        text_w = tkinter.Text(frame, bd=1, relief="sunken", wrap="word",
                              padx=4, width=64, height=16, bg=bg)
        text_w.grid(row=row, column=0, sticky='nsew')
        sb = ttk.Scrollbar(frame)
        sb.grid(row=row, column=1, sticky='ns')
        text_w.configure(yscrollcommand=sb.set)
        sb.configure(command=text_w.yview)
        frame.columnconfigure(0, weight=1)
        frame.rowconfigure(1, weight=1)
        #
        text = ''
        fn = os.path.join(cardset.dir, "COPYRIGHT")
        try:
            with open(fn, "rt") as fh:
                text = fh.read()
        except Exception:
            pass
        if text:
            text_w.config(state="normal")
            text_w.insert("insert", text)
        text_w.config(state="disabled")
        #
        focus = self.createButtons(bottom_frame, kw)
        # focus = text_w
        self.mainloop(focus, kw.timeout)
Пример #7
0
    def __init__(self, parent, title, app, **kw):
        self.app = app
        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)
        #
        self.saved_opt = app.opt.copy()
        self.sound = tkinter.BooleanVar()
        self.sound.set(app.opt.sound != 0)
        self.sound_mode = tkinter.BooleanVar()
        self.sound_mode.set(app.opt.sound_mode != 0)
        self.sample_volume = tkinter.IntVar()
        self.sample_volume.set(app.opt.sound_sample_volume)
        self.music = tkinter.BooleanVar()
        self.music.set(app.opt.music != 0)
        self.music_volume = tkinter.IntVar()
        self.music_volume.set(app.opt.sound_music_volume)
        self.samples = [
            ('areyousure', _('Are You Sure'), tkinter.BooleanVar()),
            ('deal', _('Deal'), tkinter.BooleanVar()),
            ('dealwaste', _('Deal waste'), tkinter.BooleanVar()),
            ('turnwaste', _('Turn waste'), tkinter.BooleanVar()),
            ('startdrag', _('Start drag'), tkinter.BooleanVar()),
            ('drop', _('Drop'), tkinter.BooleanVar()),
            ('droppair', _('Drop pair'), tkinter.BooleanVar()),
            ('autodrop', _('Auto drop'), tkinter.BooleanVar()),
            ('flip', _('Flip'), tkinter.BooleanVar()),
            ('autoflip', _('Auto flip'), tkinter.BooleanVar()),
            ('move', _('Move'), tkinter.BooleanVar()),
            ('nomove', _('No move'), tkinter.BooleanVar()),
            ('undo', _('Undo'), tkinter.BooleanVar()),
            ('redo', _('Redo'), tkinter.BooleanVar()),
            ('autopilotlost', _('Autopilot lost'), tkinter.BooleanVar()),
            ('autopilotwon', _('Autopilot won'), tkinter.BooleanVar()),
            ('gamefinished', _('Game finished'), tkinter.BooleanVar()),
            ('gamelost', _('Game lost'), tkinter.BooleanVar()),
            ('gamewon', _('Game won'), tkinter.BooleanVar()),
            ('gameperfect', _('Perfect game'), tkinter.BooleanVar()),
            ('extra', _('Other'), tkinter.BooleanVar()),
        ]

        #
        frame = ttk.Frame(top_frame)
        frame.pack(expand=True, fill='both', padx=5, pady=5)
        frame.columnconfigure(1, weight=1)
        #
        row = 0
        w = ttk.Checkbutton(frame,
                            variable=self.sound,
                            text=_("Sound enabled"))
        w.grid(row=row, column=0, columnspan=2, sticky='ew')
        #
        if os.name == "nt" and pysolsoundserver:
            row += 1
            w = ttk.Checkbutton(frame,
                                variable=self.sound_mode,
                                text=_("Use DirectX for sound playing"),
                                command=self.mOptSoundDirectX)
            w.grid(row=row, column=0, columnspan=2, sticky='ew')
        #
        if app.audio.CAN_PLAY_MUSIC:  # and app.startup_opt.sound_mode > 0:
            row += 1
            ttk.Label(frame, text=_('Sample volume:'),
                      anchor='w').grid(row=row, column=0, sticky='ew')
            w = PysolScale(
                frame,
                from_=0,
                to=128,
                resolution=1,
                orient='horizontal',
                takefocus=0,
                length="3i",  # label=_('Sample volume'),
                variable=self.sample_volume)
            w.grid(row=row, column=1, sticky='w', padx=5)
            row += 1
            w = ttk.Checkbutton(frame,
                                variable=self.music,
                                text=_("Music enabled"))
            w.grid(row=row, column=0, columnspan=2, sticky='ew')

            row += 1
            ttk.Label(frame, text=_('Music volume:'),
                      anchor='w').grid(row=row, column=0, sticky='ew')
            w = PysolScale(
                frame,
                from_=0,
                to=128,
                resolution=1,
                orient='horizontal',
                takefocus=0,
                length="3i",  # label=_('Music volume'),
                variable=self.music_volume)
            w.grid(row=row, column=1, sticky='w', padx=5)

        else:
            # remove "Apply" button
            kw.strings[1] = None
        #
        frame = ttk.LabelFrame(top_frame, text=_('Enable samples'))
        frame.pack(expand=True, fill='both', padx=5, pady=5)
        frame.columnconfigure(0, weight=1)
        frame.columnconfigure(1, weight=1)
        #
        row = 0
        col = 0
        for n, t, v in self.samples:
            v.set(app.opt.sound_samples[n])
            w = ttk.Checkbutton(frame, text=t, variable=v)
            w.grid(row=row, column=col, sticky='ew', padx=3, pady=1)
            if col == 1:
                col = 0
                row += 1
            else:
                col = 1
        #
        top_frame.columnconfigure(1, weight=1)
        #
        focus = self.createButtons(bottom_frame, kw)
        self.mainloop(focus, kw.timeout)
Пример #8
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)
Пример #9
0
    def __init__(self, parent, title, app, gameid, bookmark=None, **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)
        #
        self.app = app
        self.gameid = gameid
        self.bookmark = bookmark
        self.random = None
        if self.TreeDataHolder_Class.data is None:
            self.TreeDataHolder_Class.data = self.TreeData_Class(app)
        #
        sw = self.top.winfo_screenwidth()
        sh = self.top.winfo_screenheight()

        h = int(sh * .8)
        w = int(sw * .8)
        w1 = int(min(275, sw / 2.5))
        geometry = ("%dx%d+%d+%d" % (w, h, (sw - w) / 2, (sh - h) / 2))
        self.top.wm_minsize(400, 200)

        # print sw, w1, w2
        # w2 = max(200, min(w2, 10 + 12 * (app.subsampled_images.CARDW + 10)))
        # print sw, w1, w2
        # padx, pady = kw.padx, kw.pady
        # padx, pady = kw.padx/2, kw.pady/2
        padx, pady = 4, 4
        # PanedWindow
        paned_window = ttk.PanedWindow(top_frame, orient='horizontal')
        paned_window.pack(expand=True, fill='both', padx=8, pady=8)
        left_frame = ttk.Frame(paned_window)
        right_frame = ttk.Frame(paned_window)
        paned_window.add(left_frame)
        paned_window.add(right_frame)

        notebook = ttk.Notebook(left_frame)
        notebook.pack(expand=True, fill='both')
        tree_frame = ttk.Frame(notebook)
        notebook.add(tree_frame, text=_('Tree View'))
        search_frame = ttk.Frame(notebook)
        notebook.add(search_frame, text=_('Search'))

        # Tree
        font = app.getFont("default")
        self.tree = self.Tree_Class(self,
                                    tree_frame,
                                    key=gameid,
                                    default=kw.default,
                                    font=font,
                                    width=w1)
        self.tree.frame.pack(padx=padx, pady=pady, expand=True, fill='both')

        # Search
        searchText = tkinter.StringVar()
        self.list_searchlabel = tkinter.Label(search_frame,
                                              text="Search:",
                                              justify='left',
                                              anchor='w')
        self.list_searchlabel.pack(side="top", fill='both', ipadx=1)
        self.list_searchtext = tkinter.Entry(search_frame,
                                             textvariable=searchText)
        self.list_searchtext.pack(side="top",
                                  fill='both',
                                  padx=padx,
                                  pady=pady,
                                  ipadx=1)
        searchText.trace('w', self.performSearch)

        self.list_scrollbar = tkinter.Scrollbar(search_frame)
        self.list_scrollbar.pack(side="right", fill='both')

        self.createBitmaps(search_frame, kw)
        self.list = tkinter.Listbox(search_frame, exportselection=False)
        self.list.pack(padx=padx,
                       pady=pady,
                       expand=True,
                       side='left',
                       fill='both',
                       ipadx=1)
        self.updateSearchList("")
        bind(self.list, '<<ListboxSelect>>', self.selectSearchResult)
        bind(self.list, '<FocusOut>',
             lambda e: self.list.selection_clear(0, 'end'))

        self.list.config(yscrollcommand=self.list_scrollbar.set)
        self.list_scrollbar.config(command=self.list.yview)

        # LabelFrame
        info_frame = ttk.LabelFrame(right_frame, text=_('About game'))
        info_frame.grid(row=0,
                        column=0,
                        padx=padx,
                        pady=pady,
                        ipadx=4,
                        ipady=4,
                        sticky='nws')
        stats_frame = ttk.LabelFrame(right_frame, text=_('Statistics'))
        stats_frame.grid(row=0,
                         column=1,
                         padx=padx,
                         pady=pady,
                         ipadx=4,
                         ipady=4,
                         sticky='nws')
        # Info
        self.info_labels = {}
        for n, t, f, row in (
            ('name', _('Name:'), info_frame, 0),
            ('altnames', _('Alternate names:'), info_frame, 1),
            ('category', _('Category:'), info_frame, 2),
            ('type', _('Type:'), info_frame, 3),
            ('skill_level', _('Skill level:'), info_frame, 4),
            ('decks', _('Decks:'), info_frame, 5),
            ('redeals', _('Redeals:'), info_frame, 6),
                #
            ('played', _('Played:'), stats_frame, 0),
            ('won', _('Won:'), stats_frame, 1),
            ('lost', _('Lost:'), stats_frame, 2),
            ('time', _('Playing time:'), stats_frame, 3),
            ('moves', _('Moves:'), stats_frame, 4),
            ('percent', _('% won:'), stats_frame, 5),
        ):
            title_label = ttk.Label(f, text=t, justify='left', anchor='w')
            title_label.grid(row=row, column=0, sticky='nw', padx=4)
            text_label = ttk.Label(f, justify='left', anchor='w')
            text_label.grid(row=row, column=1, sticky='nw', padx=4)
            self.info_labels[n] = (title_label, text_label)
        # info_frame.columnconfigure(1, weight=1)
        info_frame.rowconfigure(6, weight=1)
        stats_frame.rowconfigure(6, weight=1)
        # Canvas
        self.preview = MfxScrolledCanvas(right_frame)
        self.preview.setTile(app, app.tabletile_index, force=True)
        self.preview.grid(row=1,
                          column=0,
                          columnspan=3,
                          padx=padx,
                          pady=pady,
                          sticky='nsew')
        right_frame.columnconfigure(1, weight=1)
        right_frame.rowconfigure(1, weight=1)
        #
        focus = self.createButtons(bottom_frame, kw)
        # set the scale factor
        self.preview.canvas.preview = 2
        # create a preview of the current game
        self.preview_key = -1
        self.preview_game = None
        self.preview_app = None
        self.updatePreview(gameid, animations=0)
        # focus = self.tree.frame
        self.mainloop(focus, kw.timeout, geometry=geometry)