def _add_labeled_entry(self, name, root, label="Entry:", value="", width=5, position=(0, 0), postlabel=None, **kwargs): "convenient wrapper for adding an Entry" ttk.Label(root, text=label).grid(row=position[0], column=position[1], sticky='W') self.vars[name] = tk.StringVar() self.widgets[name] = ttk.Entry(root, textvariable=self.vars[name], width=width) self.widgets[name].insert(0, value) self.widgets[name].grid(row=position[0], column=position[1] + 1, **kwargs) if postlabel is not None: ttk.Label(root, text=postlabel).grid(row=position[0], column=position[1] + 2, sticky='W')
def __init__(self, app, parent, title, **kw): self._url = kw['url'] 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.button = kw.default frame = ttk.Frame(top_frame) frame.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady) msg = ttk.Label(frame, text=kw.text, justify=kw.justify, width=kw.width) msg.pack(fill='both', expand=True) # font_name = msg.lookup('TLabel', 'font') font_name = 'TkDefaultFont' font = tkinter_font.Font(parent, name=font_name, exists=True) font = font.copy() font.configure(underline=True) url_label = ttk.Label(frame, text=kw.url, font=font, foreground='blue', cursor='hand2') url_label.pack() from pysollib.options import calcCustomMouseButtonsBinding url_label.bind(calcCustomMouseButtonsBinding('<{mouse_button1}>'), self._urlClicked) # focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
def createBitmaps(self, frame, kw): if kw.bitmap: # in ("error", "info", "question", "warning") img = self.img.get(kw.bitmap) b = ttk.Label(frame, image=img) b.pack(side=kw.bitmap_side, padx=kw.bitmap_padx, pady=kw.bitmap_pady) elif kw.image: b = ttk.Label(frame, image=kw.image) b.pack(side=kw.image_side, padx=kw.image_padx, pady=kw.image_pady)
def _add_labeled_dropdown(self, name, root, label="Entry:", values=None, default=None, width=5, position=(0, 0), **kwargs): "convenient wrapper for adding a Combobox" ttk.Label(root, text=label).grid(row=position[0], column=position[1], sticky='W') self.vars[name] = tk.StringVar() self.widgets[name] = ttk.Combobox(root, textvariable=self.vars[name], width=width, state='readonly') self.widgets[name].grid(row=position[0], column=position[1] + 1, **kwargs) self.widgets[name]['values'] = values if default is None: default = values[0] self.widgets[name].set(default)
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
def make_session_tab(self, parent): """Build a tab for setting session properties.""" frame = ttk.Frame(parent) ttk.Label(frame, text='Description:').grid(row=2, column=0, sticky='e') desc = ttk.Entry(frame, width=70) desc.grid(row=2, column=1, sticky='w') ttk.Label(frame, text='Researcher:').grid(row=0, column=0, sticky='e') researcher = ttk.Combobox(frame, state='readonly', values=sorted( self.metadata['people'].keys())) researcher.bind( '<<ComboboxSelected>>', lambda e: self.update_session( person=researcher.get(), expt=experiment, desc=desc)) researcher.grid(row=0, column=1, sticky='w') self.session_researcher_box = researcher ttk.Label(frame, text='Experiment:').grid(row=1, column=0, sticky='e') experiment = ttk.Combobox(frame, state='readonly', values=sorted( self.metadata['experiments'].keys())) experiment.bind( '<<ComboboxSelected>>', lambda e: self.update_session(person=researcher.get(), expt=experiment.get())) experiment.grid(row=1, column=1, sticky='w') self.session_experiment_box = experiment if 'last_session' not in self.metadata: self.metadata['last_session'] = T.StringVar() self.metadata['last_session'].set(researcher['values'][0]) last_person = self.metadata['last_session'].get() researcher.set(last_person) self.update_session(person=researcher.get(), desc=desc, expt=experiment) # Resize support & add to tabs frame.rowconfigure('all', weight=0) frame.columnconfigure('all', weight=1) parent.add(frame, text='This session') return frame
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)
def __init__(self, parent, **kw): if 'resolution' in kw: self.resolution = kw['resolution'] del kw['resolution'] else: self.resolution = 1 if 'from_' in kw: kw['from_'] //= self.resolution if 'to' in kw: kw['to'] //= self.resolution if 'variable' in kw: self.variable = kw['variable'] del kw['variable'] else: self.variable = None value = None if 'value' in kw: value = kw['value'] del kw['value'] elif self.variable: value = self.variable.get() self.value = value self.command = command = None if 'command' in kw: command = kw['command'] kw['command'] = self._scale_command if 'label' in kw: self.label_text = kw['label'] width = len(self.label_text) + 4 # width = None del kw['label'] else: self.label_text = None width = 3 # create widgets side = 'left' # 'top' self.frame = ttk.Frame(parent) self.label = ttk.Label(self.frame, anchor='w', width=width, padding=(5, 0)) self.label.pack(side=side, expand=False, fill='x') self.scale = ttk.Scale(self.frame, **kw) self.scale.pack(side=side, expand=True, fill='both', pady=4) if self.variable: self.variable.trace('w', self._trace_var) if value is not None: self._set_text(self._round(value)) if self.variable: self.variable.set(value) self.command = command
def __init__(self, app, parent, title=None, images=None, color="blue", width=300, height=25, show_text=1, norm=1): self.parent = parent self.percent = 0 self.top = makeToplevel(parent, title=title) self.top.wm_protocol("WM_DELETE_WINDOW", self.wmDeleteWindow) self.top.wm_group(parent) self.top.wm_resizable(False, False) self.top.config(cursor="watch") # self.frame = ttk.Frame(self.top, relief='flat', borderwidth=0) self.progress = ttk.Progressbar(self.frame, maximum=100, length=250) # style = ttk.Style(self.progress) # style.configure('TProgressbar', background=color) if images: self.f1 = ttk.Label(self.frame, image=images[0]) self.f1.pack(side='left', ipadx=8, ipady=4) self.progress.pack(side='left', expand=True, fill='x') self.f2 = ttk.Label(self.frame, image=images[1]) self.f2.pack(side='left', ipadx=8, ipady=4) else: self.progress.pack(expand=True, fill='x') self.frame.pack(expand=True, fill='both') if 1: setTransient(self.top, None, relx=0.5, rely=0.5) else: self.update(percent=0) self.norm = norm self.steps_sum = 0
def __init__(self, parent, title, **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.button = kw.default msg = ttk.Label(top_frame, text=kw.text, justify=kw.justify, width=kw.width) msg.pack(fill='both', expand=True, padx=kw.padx, pady=kw.pady) # focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
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)
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) self.app = app # self.update_stats_var = tkinter.BooleanVar() self.update_stats_var.set(app.opt.update_player_stats != 0) self.confirm_var = tkinter.BooleanVar() self.confirm_var.set(app.opt.confirm != 0) self.win_animation_var = tkinter.BooleanVar() self.win_animation_var.set(app.opt.win_animation != 0) # frame = ttk.Frame(top_frame) frame.pack(expand=True, fill='both', padx=5, pady=10) widget = ttk.Label(frame, text=_("\nPlease enter your name"), takefocus=0) widget.grid(row=0, column=0, columnspan=2, sticky='ew', padx=0, pady=5) # w = kw.get("e_width", 30) # width in characters names = self.app.getAllUserNames() self.player_var = ttk.Combobox(frame, width=w, values=tuple(names)) self.player_var.current(names.index(app.opt.player)) self.player_var.grid(row=1, column=0, sticky='ew', padx=0, pady=5) # widget = ttk.Checkbutton(frame, variable=self.confirm_var, text=_("Confirm quit")) widget.grid(row=2, column=0, columnspan=2, sticky='ew', padx=0, pady=5) widget = ttk.Checkbutton(frame, variable=self.update_stats_var, text=_("Update statistics and logs")) widget.grid(row=3, column=0, columnspan=2, sticky='ew', padx=0, pady=5) # widget = ttk.Checkbutton(frame, variable=self.win_animation_var, # text="Win animation") # widget.pack(side='top', padx=kw.padx, pady=kw.pady) frame.columnconfigure(0, weight=1) # self.player = self.player_var.get() self.confirm = self.confirm_var.get() self.update_stats = self.update_stats_var.get() self.win_animation = self.win_animation_var.get() # focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
def __init__(self, parent, title, label, value, **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.value = value if label: label = ttk.Label(top_frame, text=label, takefocus=0) label.pack(pady=5) w = kw.get("e_width", 0) # width in characters self.var = ttk.Entry(top_frame, exportselection=1, width=w) self.var.insert(0, value) self.var.pack(side='top', padx=kw.padx, pady=kw.pady) # focus = self.createButtons(bottom_frame, kw) focus = self.var self.mainloop(focus, kw.timeout)
def _createLabel(self, name, expand=False, width=0, tooltip=None): frame = ttk.Frame(self.frame, borderwidth=1, relief=self.label_relief) frame.grid(row=0, column=self._label_column, sticky='nsew', padx=self.padx) if expand: self.frame.grid_columnconfigure(self._label_column, weight=1) self._label_column += 1 setattr(self, name + '_frame', frame) self._widgets.append(frame) label = ttk.Label(frame, width=width, anchor='center') label.pack(expand=True, fill='both') setattr(self, name + '_label', label) self._widgets.append(label) if tooltip: b = MfxTooltip(label) self._tooltips.append(b) b.setText(tooltip) return label
def __init__(self, dialog, parent, app, player, gameid, **kw): ttk.Frame.__init__(self, parent) self.oval_width = 120 self.oval_height = 60 left_label = ttk.Label(self, image=app.gimages.logos[5]) left_label.pack(side='left', expand=True, fill='both') self.right_frame = ttk.Frame(self) self.right_frame.pack(side='right', expand=True) self.dialog = dialog self.app = app self.parent = parent self.player = player or _("Demo games") # self._calc_tabs() # won, lost = app.stats.getStats(player, gameid) self.createPieChart(app, won, lost, _("Total")) won, lost = app.stats.getSessionStats(player, gameid) self.createPieChart(app, won, lost, _("Current session"))
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
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
def __init__(self, parent, title, app, gameid, top, **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) cnf = {'master': top_frame, 'padding': (4, 1), } frame = ttk.Frame(**cnf) frame.pack(expand=True, fill='both', padx=10, pady=10) frame.columnconfigure(0, weight=1) cnf['master'] = frame cnf['text'] = _('N') label = ttk.Label(**cnf) label.grid(row=0, column=0, sticky='ew') if gameid == 'all': cnf['text'] = _('Game') label = ttk.Label(**cnf) label.grid(row=0, column=1, sticky='ew') cnf['text'] = _('Game number') label = ttk.Label(**cnf) label.grid(row=0, column=2, sticky='ew') cnf['text'] = _('Started at') label = ttk.Label(**cnf) label.grid(row=0, column=3, sticky='ew') cnf['text'] = _('Result') label = ttk.Label(**cnf) label.grid(row=0, column=4, sticky='ew') row = 1 for i in top: # N cnf['text'] = str(row) label = ttk.Label(**cnf) label.grid(row=row, column=0, sticky='ew') if gameid == 'all': name = app.getGameTitleName(i.gameid) if name is None: name = _("** UNKNOWN %d **") % i.gameid cnf['text'] = name label = ttk.Label(**cnf) label.grid(row=row, column=1, sticky='ew') # Game number cnf['text'] = '#'+str(i.game_number) label = ttk.Label(**cnf) label.grid(row=row, column=2, sticky='ew') # Start time t = time.strftime( '%Y-%m-%d %H:%M', time.localtime(i.game_start_time)) cnf['text'] = t label = ttk.Label(**cnf) label.grid(row=row, column=3, sticky='ew') # Result if isinstance(i.value, float): # time s = format_time(i.value) else: # moves s = str(i.value) cnf['text'] = s label = ttk.Label(**cnf) label.grid(row=row, column=4, sticky='ew') row += 1 focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
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)
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)
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=10, pady=10) frame.columnconfigure(0, weight=1) notebook = ttk.Notebook(frame) notebook.pack(expand=True, fill='both') for w in WizardWidgets: if isinstance(w, six.string_types): frame = ttk.Frame(notebook) notebook.add(frame, text=w, sticky='nsew', padding=5) frame.columnconfigure(1, weight=1) row = 0 continue ttk.Label(frame, text=w.label).grid(row=row, column=0) if w.widget == 'preset': if w.variable is None: w.variable = tkinter.StringVar() values = [_(v) for v in w.values] default = _(w.default) values.remove(default) values.sort() values.insert(0, default) def callback(e, w=w): self.presetSelected(e, w) cb = PysolCombo(frame, values=tuple(values), textvariable=w.variable, exportselection=False, selectcommand=callback, state='readonly', width=32) cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'entry': if w.variable is None: w.variable = tkinter.StringVar() en = ttk.Entry(frame, textvariable=w.variable) en.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'menu': if w.variable is None: w.variable = tkinter.StringVar() values = [_(v) for v in w.values] cb = PysolCombo(frame, values=tuple(values), textvariable=w.variable, exportselection=False, state='readonly', width=32) cb.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'spin': if w.variable is None: w.variable = tkinter.IntVar() else: # delete all trace callbacks for mod, cbname in w.variable.trace_vinfo(): w.variable.trace_vdelete(mod, cbname) from_, to = w.values # s = Spinbox( # frame, textvariable=w.variable, from_=from_, to=to) s = PysolScale(frame, from_=from_, to=to, resolution=1, orient='horizontal', variable=w.variable) s.grid(row=row, column=1, sticky='ew', padx=2, pady=2) elif w.widget == 'check': if w.variable is None: w.variable = tkinter.BooleanVar() ch = ttk.Checkbutton(frame, variable=w.variable, takefocus=False) ch.grid(row=row, column=1, sticky='ew', padx=2, pady=2) if w.current_value is None: v = w.default else: v = w.current_value if w.widget in ('menu', 'preset'): v = _(v) w.variable.set(v) row += 1 focus = self.createButtons(bottom_frame, kw) self.mainloop(focus, kw.timeout)
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()
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
def make_label(self, parent, name, row=0, sticky='w'): """Make the human-friendly label for a form section.""" name = name.capitalize().replace('_', ' ') + ':' ttk.Label(parent, text=name).grid(row=row, column=0, sticky=sticky)
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 __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)
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)
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)