Пример #1
0
 def create_canvas_frame(self, frame, row, col):
     """Create, grid and bind workspace units."""
     parent_frame = tk.Frame(frame, bd=10)
     grid_frame(parent_frame, [0], [0], row, col)
     scrolled_frame = ScrolledFrame(parent_frame, True, True)
     compass = {
         'n': (-1, 0),
         'e': (0, 1),
         'w': (0, -1),
         's': (1, 0)
     }
     self.add_buttons = {}
     for key, (row, col) in compass.items():
         sticky = 'news'.replace(key, '')
         button = tk.Button(scrolled_frame.inner, text='+', command=self.get_add_photo_command(key))
         button.grid(row=row + 1, column=col + 1, sticky=sticky)
         self.add_buttons[key] = button
     self.collage = Collage(
         margin=self.collage_margin.get(),
         border_width=self.collage_border_width.get(),
         corner_width=self.corner_width.get(),
         corner_curve=self.corner_curve.get(),
         scrolled_parent=scrolled_frame,
         master_args=[],
         master_kwargs={
             "bg": "white",
             "height": self.collage_height.get(),
             "width": self.collage_width.get(),
         }
     )
     self.collage.grid(row=1, column=1)
Пример #2
0
    def __init__(self, parent, vertical, horizontal):
        self.parent = parent

        super().__init__(parent)
        grid_frame(self, [], [])

        self._canvas = tk.Canvas(self)
        self._canvas.grid(row=0, column=0)

        self._vertical_bar = tk.Scrollbar(self, orient='vertical', command=self._canvas.yview)
        self._canvas.configure(yscrollcommand=self._vertical_bar.set)
        self._vertical_bar.activate()

        self._horizontal_bar = tk.Scrollbar(self, orient='horizontal', command=self._canvas.xview)
        self._canvas.configure(xscrollcommand=self._horizontal_bar.set)
        self._horizontal_bar.activate()

        if vertical:
            self._vertical_bar.grid(row=0, column=1, sticky='wns')

        if horizontal:
            self._horizontal_bar.grid(row=1, column=0, sticky='nwe')

        self.inner = tk.Frame(self._canvas)
        self.inner.grid()

        self._window = self._canvas.create_window((0, 0), window=self.inner, anchor='nw')
        self.bind('<Configure>', self.frame_config)
        self._canvas.bind('<Configure>', self.canvas_config)
        self.inner.bind('<Configure>', self.resize_handler)
Пример #3
0
 def create_change_buttons(self, frame, row, col):
     """Create, bind and bind menu bottom buttons block."""
     button_frame = tk.Frame(frame, bd=10)
     grid_frame(button_frame, [], [0], row, col, 'news')
     commands = {
         _('Change parameters'): self.change_canvas_parameters,
         # _('Add text...'): self.open_text_window
     }
     for i, (text, command) in enumerate(commands.items()):
         button = tk.Button(button_frame, text=text, command=command, padx=5, pady=5)
         button.grid(row=i, column=0, sticky='new')
Пример #4
0
 def create_font_chooser(self, frame, row, col):
     """Create and grid font chooser listbox, fill the options."""
     # TODO: add scrollbar
     font_frame = tk.Frame(frame, bd=10)
     grid_frame(font_frame, [1], [0], row, col, 'news')
     label = tk.Label(font_frame, text="Select font:", bd=10)
     label.grid(row=0, column=0, sticky='s')
     self.font_chooser = tk.Listbox(font_frame, selectmode='SINGLE')
     self.font_chooser.grid(row=1, column=0, sticky='news')
     for item in self.system_fonts:
         self.font_chooser.insert(tk.END, item)
     self.font_chooser.selection_set(0)
Пример #5
0
 def create_text_redactor(self, frame, row, col):
     """Create, grid and initialize text redactor."""
     # TODO: add scrollbar
     text_frame = tk.Frame(frame, bd=10)
     grid_frame(text_frame, [1], [0], row, col, 'news')
     label = tk.Label(text_frame, text="Type text here:", bd=10)
     label.grid(row=0, column=0, sticky='s')
     self.text_redactor = tk.Text(text_frame,
                                  width=45,
                                  height=15,
                                  wrap=tk.WORD)
     self.text_redactor.grid(row=1, column=0, sticky='news')
     self.text_redactor.insert(tk.END,
                               datetime.now().date().strftime("%B %Y"))
Пример #6
0
 def create_buttons(self, frame, row, col):
     """Create and grid buttons block."""
     buttons = tk.Frame(frame, bd=10)
     grid_frame(buttons, [], [0, 1, 2], row, col, 'news')
     commands = {
         'Change color...': self.choose_color,
         'Try font': self.choose_font,
         'OK': self.ok_quit
     }
     for i, (text, command) in enumerate(commands.items()):
         button = tk.Button(buttons,
                            text=text,
                            command=command,
                            padx=5,
                            pady=5,
                            width=15)
         button.grid(row=0, column=i, sticky='ews')
Пример #7
0
 def create_entries(self, frame, row, col):
     """Create, grid and bind menu entries block."""
     entries_frame = tk.Frame(frame, bd=10)
     grid_frame(entries_frame, [0, 1, 2, 3], [0, 1], row, col, 'news')
     variables = {
         _('Width in pixels'): self.collage_width,
         _('Height in pixels'): self.collage_height,
         _('Photo padding in pixels'): self.collage_margin,
         _('Border scroller in pixels (>1)'): self.collage_border_width,
         _('Corner size in pixels'): self.corner_width,
         _('Corner curvature (0-1)'): self.corner_curve
     }
     for i, (text, variable) in enumerate(variables.items()):
         label = tk.Label(entries_frame, text=text, padx=5)
         entry = tk.Entry(entries_frame, textvariable=variable, width=10)
         label.grid(row=i, column=0, sticky='e')
         entry.grid(row=i, column=1, sticky='w')
Пример #8
0
 def create_menu_buttons(self, frame, row, col):
     """Create, grid and bind menu top buttons block."""
     buttons_frame = tk.Frame(frame, bd=10)
     grid_frame(buttons_frame, [0, 1, 2], [0, 1], row, col, 'news')
     commands = {
         _("Undo"): None,
         _("Redo"): None,
         _("Load project"): self.load_command,
         _("Dump project"): self.dump_command,
         _("Save as..."): self.save_as_command,
         _("Print..."): None,
     }
     for i, (text, command) in enumerate(commands.items()):
         if command is None:
             continue
         button = tk.Button(buttons_frame, text=text, command=command)
         button.grid(row=i // 2, column=i % 2, sticky='news')
Пример #9
0
    def create_widgets(self):
        """Create and grid menu and workspace."""
        grid_frame(self.master, is_root=True)
        grid_frame(self, [0], [1])
        left_frame = tk.LabelFrame(self, text=_("Menu"))
        grid_frame(left_frame, [0, 1, 2], [0], 0, 0, 'nw')
        right_frame = tk.Frame(self)
        grid_frame(right_frame, [0], [0], 0, 1, 'news')

        self.create_menu_buttons(left_frame, 0, 0)
        self.create_entries(left_frame, 1, 0)
        self.create_change_buttons(left_frame, 2, 0)
        self.create_canvas_frame(right_frame, 0, 0)
Пример #10
0
 def create_modifiers(self, frame, row, col):
     """Create and grid font modifiers block."""
     # TODO: add validation function
     buttons = tk.Frame(frame, bd=10)
     grid_frame(buttons, [1], [0, 1, 2], row, col, 'news')
     variables = {
         'italic': self.italic_var,
         'bold': self.bold_var,
         'underlined': self.lined_var
     }
     for i, (text, variable) in enumerate(variables.items()):
         check = tk.Checkbutton(buttons,
                                text=text,
                                variable=variable,
                                onvalue=1,
                                offvalue=0,
                                bd=10)
         check.grid(row=0, column=i, sticky='ne')
     label = tk.Label(buttons, text="Font size:", padx=5)
     label.grid(row=1, column=0, sticky='ne')
     entry = tk.Entry(buttons, textvariable=self.font_size, width=30)
     entry.grid(row=1, column=1, sticky='new', columnspan=2)
Пример #11
0
 def create_widgets(self):
     """Create and grid all widgets."""
     grid_frame(self.master, is_root=True)
     grid_frame(self, [0], [0], 0, 0, 'news')
     frame = tk.Frame(self, bd=10)
     grid_frame(frame, [0, 1, 2], [0, 1], 0, 0, 'news')
     self.create_text_redactor(frame, 0, 0)
     self.create_font_chooser(frame, 0, 1)
     self.create_canvas(frame, 1, 0)
     self.create_modifiers(frame, 1, 1)
     self.create_buttons(frame, 2, 1)
     self.draw()