Ejemplo n.º 1
0
    def build(self):
        """widget construction

        Parameters
        ----------
        None

        Results
        -------
        None
        """

        fr4 = LabelFrame(self.fr0, text='hsv')
        fr4.grid(column=2, row=0)

        hl = Label(fr4, text='hue  ')
        hl.grid(column=0, row=0, sticky='s')

        self.hcan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.hcan.grid(column=1, row=0, sticky='s')

        hsc = TtkScale(fr4,
                       from_=0,
                       to=360,
                       variable=self.hvar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.hhandle,
                       tickinterval=30)
        hsc.grid(column=1, row=1, sticky='nw')

        vcmdsb = root.register(sb_okay)

        hsb = Spinbox(fr4,
                      from_=0,
                      to=360,
                      textvariable=self.hvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 360),
                      command=self.hhandle,
                      width=5)
        hsb.grid(column=2, row=1, sticky='nw')
        hsb.bind('<KeyRelease>', self.checksbh)

        hel = Label(fr4, height=1)
        hel.grid(column=2, row=2)

        sl = Label(fr4, text='sat  ')
        sl.grid(column=0, row=3)

        self.scan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.scan.grid(column=1, row=3, sticky='s')

        ssc = TtkScale(fr4,
                       from_=0,
                       to=100,
                       variable=self.svar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.shandle,
                       tickinterval=10)
        ssc.grid(column=1, row=4, sticky='nw')

        ssb = Spinbox(fr4,
                      from_=0,
                      to=100,
                      textvariable=self.svar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.shandle,
                      width=5)
        ssb.grid(column=2, row=4, sticky='nw')
        ssb.bind('<KeyRelease>', self.checksb100)

        sel = Label(fr4, height=1)
        sel.grid(column=2, row=5)

        vl = Label(fr4, text='value')
        vl.grid(column=0, row=6, sticky='s')

        self.vcan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.vcan.grid(column=1, row=6, sticky='n')

        vsc = TtkScale(fr4,
                       from_=0,
                       to=100,
                       variable=self.vvar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.vhandle,
                       tickinterval=10)
        vsc.grid(column=1, row=7, sticky='nw')

        vsb = Spinbox(fr4,
                      from_=0,
                      to=100,
                      textvariable=self.vvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.vhandle,
                      width=5)
        vsb.grid(column=2, row=7, sticky='nw')
        vsb.bind('<KeyRelease>', self.checksb100)

        vel = Label(fr4, height=1)
        vel.grid(column=2, row=8)

        # assume initial setting 0,100,100 hsv
        to_colour = hsv_to_rgb(*(0, 100, 100))

        hue_gradient(self.hcan, width=self.canvas_w)
        draw_gradient(self.scan, (255, 255, 255),
                      to_colour,
                      width=self.canvas_w)
        draw_gradient(self.vcan, (0, 0, 0), to_colour, width=self.canvas_w)
Ejemplo n.º 2
0
    def __init__(self,app):
        info( ' - initializing module: Spectrogram' )

        self.app = app

        self.frame = Frame(self.app.BOTTOM)
        self.frame.grid( row=0, column=1, pady=(self.app.pady*2,self.app.pady/2) )
        self.axis_frame = Frame(self.app.BOTTOM)
        self.axis_frame.grid( row=0, column=0, sticky='e', pady=(self.app.pady*2,self.app.pady/2) )
        self.canvas_width = self.app.TextGrid.canvas_width
        self.canvas_height = 106
        self.canvas = Canvas(self.frame, width=self.canvas_width, height=self.canvas_height, background='gray', highlightthickness=0)
        self.spectrogram = None
        self.spec_freq_max = DoubleVar()
        self.wl = DoubleVar()
        self.dyn_range = DoubleVar()
        self.clicktime = -1
        self.specClick = False
        self.oldSelected = None
        self.doDefaults()

        #make spinboxes & buttons for spectrogram specs
        self.spinwin = Frame(self.axis_frame)
        #spinboxes
        axis_ceil_box = Spinbox(self.spinwin, textvariable=self.spec_freq_max, command=self.drawSpectrogram, width=7, increment=100, from_=0, to_=100000)
        axis_ceil_box.bind('<Return>',self.drawSpectrogram)
        axis_ceil_box.bind('<Escape>',lambda ev: self.spinwin.focus())
        wl_box = Spinbox(self.spinwin, textvariable=self.wl, command=self.drawSpectrogram, width=7, increment=0.0005, from_=0, to_=1)
        wl_box.bind('<Return>',self.drawSpectrogram)
        wl_box.bind('<Escape>',lambda ev: self.spinwin.focus())
        dyn_range_box = Spinbox(self.spinwin, textvariable=self.dyn_range, command=self.drawSpectrogram, width=7, increment=10, from_=0, to_=10000)
        dyn_range_box.bind('<Return>',self.drawSpectrogram)
        dyn_range_box.bind('<Escape>',lambda ev: self.spinwin.focus())
        #buttons
        default_btn = Button(self.spinwin, text='Standards', command=self.restoreDefaults, takefocus=0)
        apply_btn = Button(self.spinwin, text='Apply', command=self.drawSpectrogram, takefocus=0, width=6)

        # self.axis_frame.create_window(wwidth,self.canvas_height, window=self.spinwin, anchor='ne')
        #grid spinboxes & buttons on subframe
        axis_ceil_box.grid(row=0, columnspan=2, sticky='ne')
        wl_box.grid(row=1, columnspan=2, sticky='ne')
        dyn_range_box.grid(row=2, columnspan=2, sticky='ne')
        default_btn.grid(row=3)
        apply_btn.grid(row=3, column=1)

        self.grid()

        self.canvas.bind('<Button-1>', self.jumpToFrame)
Ejemplo n.º 3
0
class Window:
    def __init__(self, workstation: WorkstationSettings,
                 wallpaper: Image.Image):
        self._root = Tk()
        self._root.title("wallcrop")
        self._root.minsize(*_MINSIZE)

        self._show_monitor_labels = BooleanVar(self._root, value=False)
        self._show_unselected_area = BooleanVar(self._root, value=True)

        frame = Frame(self._root, padding=_PADDING)
        frame.grid(column=0, row=0, sticky="n w s e")
        self._root.columnconfigure(0, weight=1)  # type: ignore
        self._root.rowconfigure(0, weight=1)  # type: ignore

        frame_top = Frame(frame)
        frame_top.grid(column=0, row=0, sticky="n w s e")

        frame_bot = Frame(frame)
        frame_bot.grid(column=0, row=2, sticky="n w s e")

        self._selection = Selection(aspect_ratio=np.divide(*wallpaper.size))
        self._selection.register_onchange_handler(self._reset_spinbox_values)

        self._selection_widget = SelectionWidget(
            parent=frame,
            workstation=workstation,
            wallpaper=wallpaper,
            selection=self._selection,
        )
        self._selection_widget.set_show_monitor_labels(
            self._show_monitor_labels.get())
        self._selection_widget.set_show_unselected_area(
            self._show_unselected_area.get())
        self._selection_widget.grid(column=0,
                                    row=1,
                                    sticky="n w s e",
                                    pady=_PADDING)
        frame.columnconfigure(0, weight=1)  # type: ignore
        frame.rowconfigure(1, weight=1)  # type: ignore

        label_wallpaper = Label(frame_top, text=workstation.name)
        label_wallpaper.grid(column=0, row=0)

        # Center columns 1-6 on frame_bot.
        frame_bot.columnconfigure(0, weight=1)  # type: ignore
        frame_bot.columnconfigure(7, weight=1)  # type: ignore

        # TODO: Figure out how to not have spinbox show zero when using
        #  increment/decrement buttons.
        label_selection_position_x = Label(frame_bot, text="X: ")
        label_selection_position_x.grid(column=1, row=0)
        self._spinbox_selection_position_x = Spinbox(frame_bot,
                                                     width=5,
                                                     validate="focusout")
        self._spinbox_selection_position_x.grid(column=2, row=0)

        label_selection_position_y = Label(frame_bot, text="  Y: ")
        label_selection_position_y.grid(column=3, row=0)
        self._spinbox_selection_position_y = Spinbox(frame_bot,
                                                     width=5,
                                                     validate="focusout")
        self._spinbox_selection_position_y.grid(column=4, row=0)

        label_selection_zoom = Label(frame_bot, text="  Zoom: ")
        label_selection_zoom.grid(column=5, row=0)
        self._spinbox_selection_zoom = Spinbox(frame_bot,
                                               width=5,
                                               validate="focusout")
        self._spinbox_selection_zoom.grid(column=6, row=0)

        self._bind_actions()
        self._set_up_menubar()
        self._reset_spinbox_values()

    def _bind_actions(self) -> None:
        self._root.bind("<Escape>", lambda _event: self.quit())
        self._root.bind("<q>", lambda _event: self.quit())

        self._root.bind(
            "<m>",
            lambda _event: self._show_monitor_labels.set(not (
                self._show_monitor_labels.get())),
        )
        self._root.bind(
            "<n>",
            lambda _event: self._show_unselected_area.set(not (
                self._show_unselected_area.get())),
        )

        self._root.bind("<i>", lambda _event: self._selection.zoom_increase())
        self._root.bind(
            "<I>", lambda _event: self._selection.zoom_increase(precise=True))

        self._root.bind("<o>", lambda _event: self._selection.zoom_decrease())
        self._root.bind(
            "<O>", lambda _event: self._selection.zoom_decrease(precise=True))

        self._root.bind("<h>", lambda _event: self._selection.move_left())
        self._root.bind("<H>",
                        lambda _event: self._selection.move_left(precise=True))
        self._root.bind("<Left>", lambda _event: self._selection.move_left())
        self._root.bind("<Shift-Left>",
                        lambda _event: self._selection.move_left(precise=True))

        self._root.bind("<l>", lambda _event: self._selection.move_right())
        self._root.bind(
            "<L>", lambda _event: self._selection.move_right(precise=True))
        self._root.bind("<Right>", lambda _event: self._selection.move_right())
        self._root.bind(
            "<Shift-Right>",
            lambda _event: self._selection.move_right(precise=True))

        self._root.bind("<k>", lambda _event: self._selection.move_up())
        self._root.bind("<K>",
                        lambda _event: self._selection.move_up(precise=True))
        self._root.bind("<Up>", lambda _event: self._selection.move_up())
        self._root.bind("<Shift-Up>",
                        lambda _event: self._selection.move_up(precise=True))

        self._root.bind("<j>", lambda _event: self._selection.move_down())
        self._root.bind("<J>",
                        lambda _event: self._selection.move_down(precise=True))
        self._root.bind("<Down>", lambda _event: self._selection.move_down())
        self._root.bind("<Shift-Down>",
                        lambda _event: self._selection.move_down(precise=True))

        self._spinbox_selection_position_x.configure(
            validatecommand=lambda *_args: self._set_selection_position_x())
        self._spinbox_selection_position_x.bind(
            "<Return>",
            lambda _event: self._set_selection_position_x()  # type: ignore
        )
        self._spinbox_selection_position_x.bind(
            "<<Decrement>>", lambda _event: self._selection.move_left())
        self._spinbox_selection_position_x.bind(
            "<<Increment>>", lambda _event: self._selection.move_right())

        self._spinbox_selection_position_y.configure(
            validatecommand=lambda *_args: self._set_selection_position_y())
        self._spinbox_selection_position_y.bind(
            "<Return>",
            lambda _event: self._set_selection_position_y()  # type: ignore
        )
        self._spinbox_selection_position_y.bind(
            "<<Decrement>>", lambda _event: self._selection.move_up())
        self._spinbox_selection_position_y.bind(
            "<<Increment>>", lambda _event: self._selection.move_down())

        self._spinbox_selection_zoom.configure(
            validatecommand=lambda *_args: self._set_selection_zoom())
        self._spinbox_selection_zoom.bind(
            "<Return>",
            lambda _event: self._set_selection_zoom()  # type: ignore
        )
        self._spinbox_selection_zoom.bind(
            "<<Decrement>>", lambda _event: self._selection.zoom_decrease())
        self._spinbox_selection_zoom.bind(
            "<<Increment>>", lambda _event: self._selection.zoom_increase())

        self._show_monitor_labels.trace_add(
            "write",
            lambda *_args: self._selection_widget.set_show_monitor_labels(
                self._show_monitor_labels.get()),
        )
        self._show_unselected_area.trace_add(
            "write",
            lambda *_args: self._selection_widget.set_show_unselected_area(
                self._show_unselected_area.get()),
        )

    def _set_up_menubar(self) -> None:
        # TODO: check that this look good on macOS, as described here:
        #   https://tkdocs.com/tutorial/menus.html#platformmenus

        self._root.option_add("*tearOff", False)

        menu = Menu(self._root)

        menu_file = Menu(menu)
        menu_file.add_command(  # type: ignore
            label="Quit",
            underline=0,
            accelerator="Q, Escape",
            command=self.quit)
        menu.add_cascade(menu=menu_file, label="File",
                         underline=0)  # type: ignore

        menu_edit = Menu(menu)
        menu_edit.add_command(  # type: ignore
            label="Move Left",
            underline=5,
            accelerator="H, Left",
            command=self._selection.move_left,
        )
        menu_edit.add_command(  # type: ignore
            label="Move Right",
            underline=5,
            accelerator="L, Right",
            command=self._selection.move_right,
        )
        menu_edit.add_command(  # type: ignore
            label="Move Up",
            underline=5,
            accelerator="K, Up",
            command=self._selection.move_up,
        )
        menu_edit.add_command(  # type: ignore
            label="Move Down",
            underline=5,
            accelerator="J, Down",
            command=self._selection.move_down,
        )
        menu_edit.add_separator()  # type: ignore
        menu_edit.add_command(  # type: ignore
            label="Increase Zoom",
            underline=0,
            accelerator="I",
            command=self._selection.zoom_increase,
        )
        menu_edit.add_command(  # type: ignore
            label="Decrease Zoom",
            underline=10,
            accelerator="O",
            command=self._selection.zoom_decrease,
        )
        menu.add_cascade(menu=menu_edit, label="Edit",
                         underline=0)  # type: ignore

        menu_view = Menu(menu)
        menu_view.add_checkbutton(  # type: ignore
            label="Label Monitors",
            variable=self._show_monitor_labels,
            underline=6,
            accelerator="M",
        )
        menu_view.add_checkbutton(  # type: ignore
            label="Show Unselected",
            variable=self._show_unselected_area,
            underline=6,
            accelerator="N",
        )
        menu.add_cascade(menu=menu_view, label="View",
                         underline=0)  # type: ignore

        menu_help = Menu(menu, name="help")
        menu_help.add_command(  # type: ignore
            label="About Wallcrop",
            underline=0,
            command=lambda: messagebox.showinfo(
                parent=self._root,
                title="About Wallcrop",
                message=f"Wallcrop {wallcrop.__version__}",
                detail=("Copyright 2021 Lukas Schmelzeisen.\n"
                        "Licensed under the Apache License, Version 2.0.\n"
                        "https://github.com/lschmelzeisen/wallcrop/"),
            ),
        )
        menu.add_cascade(menu=menu_help, label="Help",
                         underline=3)  # type: ignore

        self._root["menu"] = menu

    def mainloop(self) -> None:
        self._root.mainloop()

    def quit(self) -> None:
        self._root.destroy()

    def _set_selection_position_x(self) -> bool:
        try:
            value = float(
                self._spinbox_selection_position_x.get())  # type: ignore
        except ValueError:
            self._spinbox_selection_position_x.set(self._selection.position[0])
            return False
        self._selection.set_position(
            np.array((value, self._selection.position[1])))
        return True

    def _set_selection_position_y(self) -> bool:
        try:
            value = float(
                self._spinbox_selection_position_y.get())  # type: ignore
        except ValueError:
            self._spinbox_selection_position_y.set(self._selection.position[1])
            return False
        self._selection.set_position(
            np.array((self._selection.position[0], value)))
        return True

    def _set_selection_zoom(self) -> bool:
        try:
            value = float(self._spinbox_selection_zoom.get())  # type: ignore
        except ValueError:
            self._spinbox_selection_zoom.set(self._selection.zoom)
            return False
        self._selection.set_zoom(value)
        return True

    def _reset_spinbox_values(self) -> None:
        self._spinbox_selection_position_x.set(
            f"{self._selection.position[0]:.3f}")
        self._spinbox_selection_position_y.set(
            f"{self._selection.position[1]:.3f}")
        self._spinbox_selection_zoom.set(f"{self._selection.zoom:.3f}")
Ejemplo n.º 4
0
    def build(self):
        """Widget construction."""

        lf1 = LabelFrame(self.fr0, text='rgb')
        lf1.grid(column=0, row=0, sticky='new')
        lf1.columnconfigure(1, weight=1)

        rl0 = Label(lf1, text='red  ')
        rl0.grid(column=0, row=0, sticky='s')

        self.rcan = Canvas(lf1,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.rcan.grid(column=1,
                       row=0,
                       sticky='sew',
                       padx=self.sliderlength // 2)
        self.rcan.bind("<Configure>", self.resize_rcan)

        rsc = TtkScale(lf1,
                       self.scale_l,
                       from_=0,
                       to=255,
                       variable=self.rvar,
                       orient='horizontal',
                       command=self.rhandle,
                       tickinterval=20)
        rsc.grid(column=1, row=1, sticky='new')

        vcmdsb = root.register(sb_okay)

        rsb = Spinbox(lf1,
                      from_=0,
                      to=255,
                      textvariable=self.rvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%d', '%P', '%S', 255),
                      command=self.rhandle,
                      width=5)
        rsb.grid(column=2, row=1, sticky='nw')
        rsb.bind('<KeyRelease>', self.checksb)

        rel = Label(lf1)
        rel.grid(column=2, row=2)

        gl0 = Label(lf1, text='green')
        gl0.grid(column=0, row=3)

        self.gcan = Canvas(lf1,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.gcan.grid(column=1,
                       row=3,
                       sticky='sew',
                       padx=self.sliderlength // 2)
        self.gcan.bind("<Configure>", self.resize_gcan)

        gsc = TtkScale(lf1,
                       self.scale_l,
                       from_=0,
                       to=255,
                       variable=self.gvar,
                       orient='horizontal',
                       command=self.ghandle,
                       tickinterval=20)
        gsc.grid(column=1, row=4, sticky='new')

        gsb = Spinbox(lf1,
                      from_=0,
                      to=255,
                      textvariable=self.gvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%d', '%P', '%S', 255),
                      command=self.ghandle,
                      width=5)
        gsb.grid(column=2, row=4, sticky='nw')
        gsb.bind('<KeyRelease>', self.checksb)

        gel = Label(lf1)
        gel.grid(column=2, row=5)

        bl0 = Label(lf1, text='blue ')
        bl0.grid(column=0, row=6, sticky='s')

        self.bcan = Canvas(lf1,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.bcan.grid(column=1,
                       row=6,
                       sticky='new',
                       padx=self.sliderlength // 2)
        self.bcan.bind("<Configure>", self.resize_bcan)

        bsc = TtkScale(lf1,
                       self.scale_l,
                       from_=0,
                       to=255,
                       variable=self.bvar,
                       orient='horizontal',
                       command=self.bhandle,
                       tickinterval=20)
        bsc.grid(column=1, row=7, sticky='new')

        bsb = Spinbox(lf1,
                      from_=0,
                      to=255,
                      textvariable=self.bvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%d', '%P', '%S', 255),
                      command=self.bhandle,
                      width=5)
        bsb.grid(column=2, row=7, sticky='nw')
        bsb.bind('<KeyRelease>', self.checksb)

        bel = Label(lf1)
        bel.grid(column=2, row=8)

        lf3 = LabelFrame(self.fr0, text='colour mix')
        lf3.grid(column=1, row=0, sticky='nw')

        self.cmcan = cmcan = Canvas(lf3,
                                    width=30,
                                    height=30,
                                    bd=0,
                                    highlightthickness=0)
        cmcan.grid(column=0, row=0, sticky='n', columnspan=2)
        cmcan.grid_propagate(0)
        vdraw_gradient(self.cmcan, (255, 0, 0), alpha=255)

        cml = Label(lf3, text='hash\nvalue')
        cml.grid(column=0, row=1)

        vcmd = root.register(is_okay)
        self.ent0 = ent0 = Entry(lf3,
                                 width=8,
                                 validate='key',
                                 validatecommand=(vcmd, '%i', '%P', '%S'),
                                 textvariable=self.evar)
        ent0.grid(column=1, row=1)
        ent0.bind('<KeyRelease>', self.checkhash)

        lf5 = LabelFrame(lf3, text='related colours', style='Wide.TLabelframe')
        lf5.grid(column=0, row=2, sticky='nw', columnspan=2)

        self.srcls = []
        self.vrcls = []
        self.srccans = []
        self.vrccans = []
        relateds = [25, 50, 75, 100]
        stexts = ['25% sat', '50% sat', '75% sat', '100% sat']
        vtexts = ['25% val', '50% val', '75% val', '100% val']

        for ix, rel in enumerate(relateds):
            Label(lf5, text=stexts[ix]).grid(row=1 + 2 * ix,
                                             column=0,
                                             sticky='n')
            self.srcls.append(Label(lf5))
            self.srcls[ix].grid(row=1 + 2 * ix, column=1, sticky='n')
            self.srccans.append(
                Canvas(lf5, width=30, height=30, bd=0, highlightthickness=0))
            self.srccans[ix].grid(row=2 * ix,
                                  column=0,
                                  sticky='n',
                                  columnspan=2)
            Label(lf5, text=vtexts[ix]).grid(row=9 + 2 * ix,
                                             column=0,
                                             sticky='n')
            self.vrcls.append(Label(lf5))
            self.vrcls[ix].grid(row=9 + 2 * ix, column=1, sticky='n')
            self.vrccans.append(
                Canvas(lf5, width=30, height=30, bd=0, highlightthickness=0))
            self.vrccans[ix].grid(row=8 + 2 * ix,
                                  column=0,
                                  sticky='n',
                                  columnspan=2)

        self.cccan = Canvas(lf5,
                            width=30,
                            height=30,
                            bd=0,
                            highlightthickness=0)
        self.cccan.grid(column=0, row=17, sticky='n', columnspan=2)

        self.ccla = Label(lf5, text="comp'y")
        self.ccla.grid(column=0, row=18, sticky='n')

        self.ccl = Label(lf5, text="")
        self.ccl.grid(column=1, row=18, sticky='n')

        al0 = Label(lf1, text='alpha')
        al0.grid(column=0, row=10, sticky='s')

        self.acan = Canvas(lf1,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.acan.grid(column=1,
                       row=10,
                       sticky='new',
                       padx=self.sliderlength // 2)
        self.acan.bind("<Configure>", self.resize_acan)

        asc = TtkScale(lf1,
                       self.scale_l,
                       from_=0,
                       to=255,
                       variable=self.avar,
                       orient='horizontal',
                       command=self.ahandle,
                       tickinterval=20)
        asc.grid(column=1, row=11, sticky='new')

        asb = Spinbox(lf1,
                      from_=0,
                      to=255,
                      textvariable=self.avar,
                      validate='key',
                      validatecommand=(vcmdsb, '%d', '%P', '%S', 255),
                      command=self.ahandle,
                      width=5)
        asb.grid(column=2, row=11, sticky='nw')
        asb.bind('<KeyRelease>', self.checksba)

        ael = Label(lf1, text=' ')
        ael.grid(column=2, row=12, sticky='s')

        draw_gradient(self.rcan, (0, 0, 0), (255, 0, 0), width=self.canvas_w)
        draw_gradient(self.gcan, (255, 0, 0), (255, 0, 255),
                      width=self.canvas_w)
        draw_gradient(self.bcan, (255, 0, 0), (255, 255, 0),
                      width=self.canvas_w)
        draw_agradient(self.acan, (127, 127, 127), (255, 0, 0),
                       width=self.canvas_w)

        lf4 = LabelFrame(self.fr0, text='hsv')
        lf4.grid(column=2, row=0, sticky='news')
        lf4.columnconfigure(1, weight=1)

        hl0 = Label(lf4, text='hue  ')
        hl0.grid(column=0, row=0, sticky='s')

        self.hcan = Canvas(lf4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.hcan.grid(column=1,
                       row=0,
                       sticky='sew',
                       padx=self.sliderlength // 2)
        self.hcan.bind("<Configure>", self.resize_hcan)

        hsc = TtkScale(lf4,
                       self.scale_l,
                       from_=0,
                       to=360,
                       variable=self.hvar,
                       orient='horizontal',
                       command=self.hhandle,
                       tickinterval=30)
        hsc.grid(column=1, row=1, sticky='new')

        vcmdsb = root.register(sb_okay)

        hsb = Spinbox(lf4,
                      from_=0,
                      to=360,
                      textvariable=self.hvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 360),
                      command=self.hhandle,
                      width=5)
        hsb.grid(column=2, row=1, sticky='nw')
        hsb.bind('<KeyRelease>', self.checksbh)

        hel = Label(lf4)
        hel.grid(column=2, row=2)

        sl0 = Label(lf4, text='sat  ')
        sl0.grid(column=0, row=3)

        self.scan = Canvas(lf4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.scan.grid(column=1,
                       row=3,
                       sticky='sew',
                       padx=self.sliderlength // 2)
        self.scan.bind("<Configure>", self.resize_scan)

        ssc = TtkScale(lf4,
                       self.scale_l,
                       from_=0,
                       to=100,
                       variable=self.svar,
                       orient='horizontal',
                       command=self.shandle,
                       tickinterval=10)
        ssc.grid(column=1, row=4, sticky='new')

        ssb = Spinbox(lf4,
                      from_=0,
                      to=100,
                      textvariable=self.svar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.shandle,
                      width=5)
        ssb.grid(column=2, row=4, sticky='nw')
        ssb.bind('<KeyRelease>', self.checksb100)

        sel = Label(lf4)
        sel.grid(column=2, row=5)

        vl0 = Label(lf4, text='value')
        vl0.grid(column=0, row=6, sticky='s')

        self.vcan = Canvas(lf4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.vcan.grid(column=1,
                       row=6,
                       sticky='new',
                       padx=self.sliderlength // 2)
        self.vcan.bind("<Configure>", self.resize_vcan)

        vsc = TtkScale(lf4,
                       self.scale_l,
                       from_=0,
                       to=100,
                       variable=self.vvar,
                       orient='horizontal',
                       command=self.vhandle,
                       tickinterval=10)
        vsc.grid(column=1, row=7, sticky='new')

        vsb = Spinbox(lf4,
                      from_=0,
                      to=100,
                      textvariable=self.vvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.vhandle,
                      width=5)
        vsb.grid(column=2, row=7, sticky='nw')
        vsb.bind('<KeyRelease>', self.checksb100)

        vel = Label(lf4)
        vel.grid(column=2, row=8)

        # assume initial setting 0,100,100 hsv
        to_colour = hsv_to_rgb(*(0, 100, 100))

        hue_gradient(self.hcan, width=self.canvas_w)
        draw_gradient(self.scan, (255, 255, 255),
                      to_colour,
                      width=self.canvas_w)
        draw_gradient(self.vcan, (0, 0, 0), to_colour, width=self.canvas_w)

        self.can_hsv = can_hsv = Canvas(lf4,
                                        width=self.wheel_w,
                                        height=self.wheel_w,
                                        bg='#d9d9d9')
        can_hsv.grid(column=0, row=9, columnspan=3, pady=25, sticky='n')
        self.hsv_gamut = PhotoImage(file='../figures/colour_wheel.png')
        can_hsv.create_image(0, 0, anchor='nw', image=self.hsv_gamut)
        self.ring = circle(can_hsv,
                           307,
                           158,
                           self.ring_radius,
                           width=self.ring_width,
                           outline='#555555',
                           activeoutline='black',
                           tags='ring')

        can_hsv.bind('<Button-1>', self.click_ring)
        can_hsv.tag_bind('ring', '<B1-Motion>', self.drag_ring)

        self.related(0, 100, 100, 255, 0, 0)
Ejemplo n.º 5
0
    def makeFrameWidget(self):
        '''
        makes frame widget
        '''
        #make regular frame stuff -- label and tier
        self.frames_canvas = Canvas(self.canvas_frame,
                                    width=self.canvas_width,
                                    height=self.canvas_height,
                                    background='gray',
                                    highlightthickness=0)
        frames_label = Canvas(self.frame,
                              width=self.label_width,
                              height=self.canvas_height,
                              highlightthickness=0,
                              background='gray')
        frames_label.create_text(self.label_width,
                                 0,
                                 anchor='ne',
                                 justify='center',
                                 text='frames: ',
                                 width=self.label_width,
                                 activefill='blue')

        # make subframe to go on top of label canvas
        sbframe = Frame(frames_label)
        #put new widgets onto subframe
        offset = self.app.Data.getFileLevel('offset')
        if offset != None:
            self.frame_shift.set(offset)
        # for audio alignment
        go_btn = Button(sbframe,
                        text='Offset',
                        command=self.shiftFrames,
                        takefocus=0)
        # minmax = len(self.app.Audio.sfile)*1000
        txtbox = Spinbox(sbframe,
                         textvariable=self.frame_shift,
                         width=7,
                         from_=-10000000,
                         to=10000000)
        txtbox.bind('<Escape>', lambda ev: sbframe.focus())
        txtbox.bind('<Return>', lambda ev: self.shiftFrames())
        go_btn.grid(row=0, column=0, sticky='e')
        txtbox.grid(row=0, column=1, sticky='e')
        # put subframe on canvas
        window = frames_label.create_window(self.label_width * .3,
                                            self.canvas_height / 3,
                                            anchor='nw',
                                            window=sbframe)
        # ensure position of subframe gets updated
        frames_label.bind(
            '<Configure>',
            lambda e: frames_label.itemconfig(window, width=e.width))
        sbframe.bind(
            '<Configure>', lambda e: frames_label.configure(
                scrollregion=frames_label.bbox("all")))

        self.TkWidgets.append({
            'name': self.frameTierName,
            'frames': self.frames_canvas,
            'frames-label': frames_label
        })

        self.frames_canvas.bind("<Button-1>", self.getClickedFrame)
Ejemplo n.º 6
0
 def bind_time_changing_events(self, spinbox: ttk.Spinbox) -> None:
     time_changing_events = ('<KeyRelease>', 'Backspace', '<<Increment>>',
                             '<<Decrement>>')
     for event in time_changing_events:
         spinbox.bind(event, self.generate_time_change_event, add=True)
Ejemplo n.º 7
0
class Slider(Frame):
    MINIMO = 100
    MAXIMO = 2400
    
    def __init__(self, master, label, *args, **kwargs):
        '''
        parametros
        ----------
        master : tkinter.widget
        
        label : str
        
        '''
        super(Slider, self).__init__(master, *args, **kwargs)
        self._criar_estilo_label()
       
        self._criar_scale()
        self._criar_spinbox()
        self._criar_label(label)
        self.set_atual(self.MINIMO)

    def _criar_estilo_label(self):
        estilo = Style()
        estilo.configure('Slider.TLabel', font=('Arial', 14, 'normal'))
          
    def _criar_label(self, label):
        '''
        Criar label.
        '''
        frame = Frame(self, width=150, height=50)
        label = Label(frame, text=label, anchor='center', style='Slider.TLabel')
        
        label.bind('<Double-Button-1>', lambda e: self._spinbox.focus())

        label.pack(fill='both', expand=True, padx=5, pady=5)
        frame.pack(side='left')
        frame.pack_propagate(False)
                                       
    def _criar_spinbox(self):
        '''
        Criar Widget spinbox.
        '''
        self._spinbox = Spinbox(self, from_=self.MINIMO, 
                                         to=self.MAXIMO,
                            font=('Arial', 14, 'normal'),
                            width=10)
        
        self._spinbox['command'] = lambda: \
            self.set_atual(self._spinbox.get(), widget=self._spinbox)
        
        self._spinbox.bind('<Return>', lambda e: \
            self.set_atual(self._spinbox.get()))
        
        self._spinbox.pack(side='left', anchor='center')
    
    def _criar_scale(self):
        '''
        Criar widget Scale.
        '''
        self._scale = Scale(self, from_=self.MINIMO, 
                                    to=self.MAXIMO, 
                                orient='horizontal')
        
        self._scale['command'] = lambda e: \
            self.set_atual(self._scale.get(), widget=self._scale)  
                                        
        self._scale.pack(side='left', fill='x', anchor='center', expand=True, )
        
    def atual(self):
        '''
        Obter o valor atual
        
        retornos
        --------
        int
        '''
        return self._scale.get()
        
    def set_atual(self, atual, **kwargs):
        '''
        Define o valor atual.
        
        parametros
        ----------
        atual : int
        '''
        # caractere númerico é convertido em inteiro.
        if isinstance(atual, str) and atual.isdigit():
            atual = int(atual)
        
        # caractere não númerico convertido em inteiro.
        if not isinstance(atual, int):
            atual = self._scale.get()
        
        # atual fora do range.
        if atual not in range(self.MINIMO, self.MAXIMO):
            atual = self._scale.get()        
        
        widget = kwargs.get('widget')
        if widget:
            if isinstance(widget, Scale):
                self._spinbox.delete(0, 'end')
                self._spinbox.insert(0, str(atual))
            elif isinstance(widget, Spinbox):
                self._scale.set(atual)
        
        else:
            self._spinbox.delete(0, 'end')
            self._spinbox.insert(0, str(atual))
            self._scale.set(atual)
Ejemplo n.º 8
0
    def build(self):
        """widget construction

        Parameters
        ----------
        None

        Results
        -------
        None
        """

        fr4 = LabelFrame(self.fr0, text='hsv')
        fr4.grid(column=2, row=0, sticky='ns')

        hl0 = Label(fr4, text='hue  ')
        hl0.grid(column=0, row=0, sticky='s')

        self.hcan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.hcan.grid(column=1, row=0, sticky='s')

        hsc = TtkScale(fr4,
                       from_=0,
                       to=360,
                       variable=self.hvar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.hhandle,
                       tickinterval=30)
        hsc.grid(column=1, row=1, sticky='nw')

        vcmdsb = root.register(sb_okay)

        hsb = Spinbox(fr4,
                      from_=0,
                      to=360,
                      textvariable=self.hvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 360),
                      command=self.hhandle,
                      width=5)
        hsb.grid(column=2, row=1, sticky='nw')
        hsb.bind('<KeyRelease>', self.checksbh)

        hel = Label(fr4, height=1)
        hel.grid(column=2, row=2)

        sl0 = Label(fr4, text='sat  ')
        sl0.grid(column=0, row=3)

        self.scan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.scan.grid(column=1, row=3, sticky='s')

        ssc = TtkScale(fr4,
                       from_=0,
                       to=100,
                       variable=self.svar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.shandle,
                       tickinterval=10)
        ssc.grid(column=1, row=4, sticky='nw')

        ssb = Spinbox(fr4,
                      from_=0,
                      to=100,
                      textvariable=self.svar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.shandle,
                      width=5)
        ssb.grid(column=2, row=4, sticky='nw')
        ssb.bind('<KeyRelease>', self.checksb100)

        sel = Label(fr4, height=1)
        sel.grid(column=2, row=5)

        vl0 = Label(fr4, text='value')
        vl0.grid(column=0, row=6, sticky='s')

        self.vcan = Canvas(fr4,
                           width=self.canvas_w,
                           height=self.canvas_h,
                           bd=0,
                           highlightthickness=0)
        self.vcan.grid(column=1, row=6, sticky='n')

        vsc = TtkScale(fr4,
                       from_=0,
                       to=100,
                       variable=self.vvar,
                       orient='horizontal',
                       length=self.scale_l,
                       command=self.vhandle,
                       tickinterval=10)
        vsc.grid(column=1, row=7, sticky='nw')

        vsb = Spinbox(fr4,
                      from_=0,
                      to=100,
                      textvariable=self.vvar,
                      validate='key',
                      validatecommand=(vcmdsb, '%P', '%S', 100),
                      command=self.vhandle,
                      width=5)
        vsb.grid(column=2, row=7, sticky='nw')
        vsb.bind('<KeyRelease>', self.checksb100)

        vel = Label(fr4, height=1)
        vel.grid(column=2, row=8)

        # assume initial setting 0,100,100 hsv
        to_colour = hsv_to_rgb(*(0, 100, 100))

        hue_gradient(self.hcan, width=self.canvas_w)
        draw_gradient(self.scan, (255, 255, 255),
                      to_colour,
                      width=self.canvas_w)
        draw_gradient(self.vcan, (0, 0, 0), to_colour, width=self.canvas_w)

        can_hsv = Canvas(fr4,
                         width=self.wheel_w,
                         height=self.wheel_w,
                         bg='#d9d9d9')
        can_hsv.grid(column=1, row=9, pady=25, sticky='n')
        self.hsv_gamut = PhotoImage(file='../../figures/colour_wheel.png')
        can_hsv.create_image(0, 0, anchor='nw', image=self.hsv_gamut)
        self.ring = circle(can_hsv,
                           307,
                           158,
                           self.ring_radius,
                           width=self.ring_width,
                           tags='ring')