Пример #1
0
    def template_window(self):
        mini_root = tk.Toplevel(self)
        mini_root.title('Scenarios')
        mini_root.focus_set()
        mini_root.grab_set()
        mini_root.resizable(False, False)
        mini_root.iconphoto(False, tk.PhotoImage(file='./data/icons/scenario.png'))

        mini_root.bind("<Escape>", lambda _: mini_root.destroy())
        mini_root.bind("<Control-w>", lambda _: mini_root.destroy())
        mini_root.bind("<Control-s>", lambda _: self.load_config_file(mini_root, scenario_var))
        mini_root.bind("<Control-i>", lambda _: blop_catalogue.show_info('catalogue'))

        # scenario
        scenario_lbl = ttk.Label(mini_root, text="Choose saved")
        scenario_lbl.grid(row=0, column=1, columnspan=2, pady=(10, 0))

        scenario_lbl2 = ttk.Label(mini_root, text="Open file")
        scenario_lbl2.grid(row=0, column=0, columnspan=1, pady=(10, 0), padx=5)

        paths = glob.glob("./data/scenarios/*.crum")
        paths.insert(0, "None")
        paths[:] = [ntpath.basename(s).replace('.crum', '') for s in paths]

        scenario_var = tk.StringVar(mini_root)
        scenario_options = ttk.OptionMenu(mini_root, scenario_var, *paths)
        scenario_options.grid(row=1, column=1, padx=(0, 0))

        folder_icon = ImageTk.PhotoImage(Image.open("./data/icons/folder.png").resize((55, 55), Image.ANTIALIAS))
        folder_btn = tk.Button(mini_root, command=lambda: self.choose_file(scenario_options, scenario_var),
                               image=folder_icon,
                               border=0)
        folder_btn.image = folder_icon
        folder_btn.grid(row=1, column=0, pady=10, padx=(10, 10))

        scenario_icon = ImageTk.PhotoImage(Image.open("./data/icons/scenario.png").resize((60, 60), Image.ANTIALIAS))
        scenario_btn = tk.Button(mini_root, image=scenario_icon, border=0,
                                 command=lambda: show_template_description(mini_root, scenario_var))
        scenario_btn.image = scenario_icon
        scenario_btn.grid(row=1, column=2, padx=(0, 20), pady=8)

        self.widgets['scenario'] = scenario_options
        # control buttons
        save_btn = ttk.Button(mini_root, text='Save', command=lambda: self.load_config_file(mini_root, scenario_var))
        save_btn.grid(row=2, column=2, padx=10, pady=10)

        cancel_btn = ttk.Button(mini_root, text="Cancel", command=lambda: mini_root.destroy())
        cancel_btn.grid(row=2, column=1, padx=10, pady=10)

        info_icon = ImageTk.PhotoImage(Image.open("./data/icons/info3.png").resize((30, 30), Image.ANTIALIAS))
        info_btn = tk.Button(mini_root, command=lambda: blop_catalogue.show_info('template'), image=info_icon, border=0)
        info_btn.image = info_icon
        info_btn.grid(row=2, column=0)
Пример #2
0
    def guess_window(self):
        mini_root = tk.Toplevel(self)
        mini_root.title('Guess!')
        mini_root.focus_set()
        mini_root.grab_set()
        mini_root.resizable(False, False)
        mini_root.iconphoto(False, tk.PhotoImage(file='./data/icons/guess.png'))

        label = ttk.Label(mini_root, font=("Didot", 12),
                          text="You're ready to go! \nNow let us record your prediction of the simulation "
                               "outcome. \nWe will show you these after simulation ends for comparison. "
                               "\nYou may be surprised by results! Challenge your intuition!")
        label.grid(row=0, column=0, padx=20, pady=20, columnspan=4)

        label2 = ttk.Label(mini_root, font=("Didot", 10),
                           text="Place kinds in descending order")
        label2.grid(row=1, column=2, columnspan=2, sticky='s', pady=15)

        listbox = DragDropListbox(mini_root, height=len(self.kinds), font=("Cambria", 10))
        for idx, key in enumerate(self.kinds):
            listbox.insert((idx + 1), self.kinds[key]['name'].get())
        listbox.grid(row=2, column=2, columnspan=2, sticky='n')

        img = ImageTk.PhotoImage(Image.open("./data/icons/choice.png").resize((200, 200), Image.ANTIALIAS))
        confused = ttk.Label(mini_root, image=img)
        confused.image = img
        confused.grid(row=1, column=0, pady=10, padx=10, columnspan=2, rowspan=2)

        # control buttons
        save_btn = ttk.Button(mini_root, text='Save', command=lambda: self.save_guess(listbox.get(0, tk.END)))
        save_btn.grid(row=3, column=3, pady=10)

        cancel_btn = ttk.Button(mini_root, text='Cancel', command=lambda: mini_root.destroy())
        cancel_btn.grid(row=3, column=2, pady=10)

        info_icon = ImageTk.PhotoImage(Image.open("./data/icons/info3.png").resize((30, 30), Image.ANTIALIAS))
        info_btn = tk.Button(mini_root, command=lambda: blop_catalogue.show_info('developer'), image=info_icon,
                             border=0)
        info_btn.image = info_icon
        info_btn.grid(row=3, column=0, padx=(0, 35))

        mini_root.bind("<Escape>", lambda _: mini_root.destroy())
        mini_root.bind("<Control-w>", lambda _: mini_root.destroy())
        mini_root.bind("<Control-s>", lambda _: self.save_guess(listbox.get(0, tk.END)))
        mini_root.bind("<Control-i>", lambda _: blop_catalogue.show_info('guess'))
Пример #3
0
    def dev_window(self):
        messagebox.showwarning("Attention!",
                               "You're entering the dangerous zone! Manipulating values presented here may "
                               "result in unforeseen consequences")
        root = tk.Toplevel(self)
        root.grab_set()
        root.focus_set()
        root.resizable(False, False)
        root.title("Developer settings")
        root.iconphoto(False, tk.PhotoImage(file='./data/icons/incognito.png'))

        # speed
        speed_lbl = ttk.Label(root, text='Absolute speed', anchor='w')
        speed_var = tk.DoubleVar(self, value=self.base_data['speed'].get())
        speed_lbl.grid(row=1, column=0, padx=15, pady=15, columnspan=2)
        speed_entry = ttk.Entry(root, textvariable=speed_var, justify='right', font=("Helvetica", 10),
                                width=10)
        speed_entry.grid(row=1, column=2, padx=15)

        # size
        size_lbl = tk.Label(root, text='Window size', justify='left')
        size_lbl.grid(row=2, column=0, padx=15, pady=15, columnspan=2)
        size_var = tk.DoubleVar(self, value=self.base_data['winsize'].get())
        size_entry = ttk.Entry(root, textvariable=size_var, justify='right', font=("Helvetica", 10),
                               width=10)
        size_entry.grid(row=2, column=2, padx=15)

        icon = ImageTk.PhotoImage(Image.open("./data/icons/hacker.png").resize((300, 300), Image.ANTIALIAS))
        lbl = ttk.Label(root, image=icon)
        lbl.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
        lbl.image = icon

        guess_var = tk.BooleanVar(self)
        check_guess = ttk.Checkbutton(root, text="Disable guesses", variable=guess_var)
        check_guess.grid(row=3, column=0, columnspan=2, padx=0, pady=10)

        abort_var = tk.BooleanVar(self)
        check_abort = ttk.Checkbutton(root, text="Use & in aborts", variable=abort_var)
        check_abort.grid(row=3, column=2, columnspan=2, padx=0, pady=10)

        configs = {'speed': speed_var, 'winsize': size_var, 'guess': guess_var, 'abort': abort_var}

        # control buttons
        save_btn = ttk.Button(root, text='Save', command=lambda: self.update_config(root, configs))
        save_btn.grid(row=4, column=2, padx=10, pady=10)

        cancel_btn = ttk.Button(root, text='Cancel', command=lambda: root.destroy())
        cancel_btn.grid(row=4, column=1, padx=10, pady=10)

        info_icon = ImageTk.PhotoImage(Image.open("./data/icons/info3.png").resize((30, 30), Image.ANTIALIAS))
        info_btn = tk.Button(root, command=lambda: blop_catalogue.show_info('developer'), image=info_icon, border=0)
        info_btn.image = info_icon
        info_btn.grid(row=4, column=0, padx=(10, 15))
Пример #4
0
 def __init__(self, up_root, *args, **kwargs):
     tk.Frame.__init__(self, *args, **kwargs)
     self.root = up_root
     # self.root.geometry("800x900")
     self.root.title("Settings")
     self.root.iconphoto(True, tk.PhotoImage(file='./data/icons/settings.png'))
     self.data = {}
     self.kinds = {}
     self.aborts = {}
     self.widgets = {}
     self.base_data = {}
     self.fill_base()
     self.notebook = None
     self.guess = None
     up_root.resizable(False, False)
     self.root.bind("<Control-i>", lambda _: blop_catalogue.show_info('catalogue'))
     self.root.bind("<Control-r>", lambda _: self.run())
     self.root.bind("<Control-l>", lambda _: self.template_window())
     self.root.bind("<Control-Shift-S>", lambda _: self.save_template())
     self.create_widgets()
Пример #5
0
    def create_widgets(self):
        self['padx'] = 10
        self['pady'] = 5

        title = tk.Label(self, text="General Settings", font=("Helvetica", 11))
        title.grid(row=1, column=0, pady=18, columnspan=7)

        # name
        name_lbl = ttk.Label(self, text="Name")
        name_lbl.grid(row=2, column=0, columnspan=2, pady=(8, 4))

        name_icon = ImageTk.PhotoImage(Image.open("./data/icons/resume.png").resize((55, 55), Image.ANTIALIAS))
        name_icon_lbl = ttk.Label(self, image=name_icon)
        name_icon_lbl.image = name_icon
        name_icon_lbl.grid(row=3, column=0, padx=(5, 5), pady=(0, 8))

        name_var = tk.StringVar(self)
        name_field = ttk.Entry(self, width=12, font=("Helvetica", 10), textvariable=name_var)
        self.data['name'] = name_var
        name_field.grid(row=3, column=1)
        name_field.focus_set()

        # design
        design_lbl = ttk.Label(self, text="Theme")
        design_lbl.grid(row=2, column=2, columnspan=2, pady=(0, 0))

        design_icon = ImageTk.PhotoImage(Image.open("./data/icons/design.png").resize((60, 60), Image.ANTIALIAS))
        design_icon_lbl = ttk.Label(self, image=design_icon)
        design_icon_lbl.image = design_icon
        design_icon_lbl.grid(row=3, column=2, padx=(20, 0), pady=8)
        design_var = tk.StringVar(self)
        design_options = ttk.OptionMenu(self, design_var, "Abstract", "Body", "Farm", "Space", "Ground", 'Water',
                                        "Abstract", )
        self.data['design'] = design_var
        design_options.grid(row=3, column=3, padx=(0, 10))

        # - - - - - - - - - - - - - - - - - - - - -
        speed_lbl = ttk.Label(self, text="Time Unit")
        speed_lbl.grid(row=4, column=0, columnspan=2, pady=(8, 4))

        speed_icon = ImageTk.PhotoImage(Image.open("./data/icons/duration.png").resize((60, 60), Image.ANTIALIAS))
        speed_icon_lbl = ttk.Label(self, image=speed_icon)
        speed_icon_lbl.image = speed_icon  # we need to keep reference to it
        speed_icon_lbl.grid(row=5, column=0, padx=(10, 5), pady=(0, 0))

        speed_var = tk.DoubleVar(self)
        slider = tk.DoubleVar(self)
        speed_val_lbl = ttk.Label(self, textvariable=slider)
        speed_val_lbl.grid(row=5, column=1, sticky='n')
        speed_scale = ttk.Scale(self, from_=0.5, to=5, orient=tk.HORIZONTAL, length=100,
                                variable=speed_var, command=lambda s: slider.set('%0.1f' % float(s)))
        speed_scale.grid(row=5, column=1, sticky='ew', padx=(5, 0), pady=(20, 0))
        speed_scale.set(1)
        self.data['speed'] = speed_var

        # - - - - - - - - - - - - - - - - - - - - -
        unit_lbl = ttk.Label(self, text="Duration")
        unit_lbl.grid(row=4, column=2, columnspan=2, pady=(8, 4))

        unit_icon = ImageTk.PhotoImage(Image.open("./data/icons/calendar.png").resize((60, 60), Image.ANTIALIAS))
        unit_icon_lbl = ttk.Label(self, image=unit_icon)
        unit_icon_lbl.image = unit_icon  # we need to keep reference to it
        unit_icon_lbl.grid(row=5, column=2, padx=(10, 5), pady=(0, 0))

        unit_var = tk.DoubleVar(self)
        unit_slider = tk.DoubleVar(self)
        unit_val_lbl = ttk.Label(self, textvariable=unit_slider)
        unit_val_lbl.grid(row=5, column=3, sticky='n')
        unit_scale = ttk.Scale(self, from_=0.2, to=5, orient=tk.HORIZONTAL, length=100,
                               variable=unit_var, command=lambda s: unit_slider.set('%0.1f' % float(s)))
        unit_scale.grid(row=5, column=3, sticky='ew', padx=(5, 0), pady=(20, 0))
        unit_scale.set(1)
        self.data['unit'] = unit_var

        abort_dict = {}
        self.data['abort'] = abort_dict
        abort_icon = ImageTk.PhotoImage(
            Image.open("./data/icons/exit.png").resize((60, 60), Image.ANTIALIAS))
        abort_icon_lbl = ttk.Label(self, image=abort_icon)
        abort_icon_lbl.image = abort_icon
        abort_icon_lbl.grid(row=5, column=4, padx=(20, 0), pady=15)

        abort_btn = ttk.Button(self, text='F-condition', command=lambda: self.abort_window())
        abort_btn.grid(row=5, column=5, pady=15)

        # - - - - - - - - - - - - - - - - - - - - -
        notebook_label = ttk.Label(self, text="Blops Catalogue", font=("Helvetica", 11))
        notebook_label.grid(row=6, column=0, pady=18, columnspan=7)

        notebook = blop_catalogue.BlopCatalogue(self)
        self.notebook = notebook
        self.kinds = notebook.valid_blops
        notebook.grid(row=7, column=0, sticky='wens', pady=4, padx=(0, 0), columnspan=6)
        # - - - - - - - - - - - - - - - - - - - - -

        # -----------buttons--------------
        dev_button = ttk.Button(self, text="Developer mode", command=lambda: self.dev_window())
        self.root.bind("<Control-Alt-e>", lambda _: show_btn(dev_button))
        dev_button.grid_forget()

        load_button = ttk.Button(self, text="Load template", command=lambda: self.template_window())
        load_button.grid(row=0, column=3, pady=15, padx=10)

        save_button = ttk.Button(self, text="Save template", command=lambda: self.save_template())
        save_button.grid(row=0, column=4, pady=15, padx=10)

        run_button = ttk.Button(self, text="Run", command=lambda: self.run())
        run_button.grid(row=0, column=5, pady=15, padx=10)

        info_icon = ImageTk.PhotoImage(Image.open("./data/icons/info2.png").resize((30, 30), Image.ANTIALIAS))
        info_btn = tk.Button(self, command=lambda: blop_catalogue.show_info('settings'), image=info_icon, border=0)
        info_btn.image = info_icon
        info_btn.grid(row=0, column=0, padx=(0, 30))