2023-04-25 03:31:05 +00:00
|
|
|
# Python imports
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
import gi
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk
|
|
|
|
|
|
|
|
# Application imports
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ButtonControls(Gtk.ButtonBox):
|
|
|
|
def __init__(self):
|
|
|
|
super(ButtonControls, self).__init__()
|
|
|
|
|
2023-04-25 21:12:30 +00:00
|
|
|
self.one2one_button = None
|
|
|
|
self.fit_button = None
|
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
self._setup_styling()
|
|
|
|
self._setup_signals()
|
|
|
|
self._load_widgets()
|
|
|
|
|
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
|
|
|
|
def _setup_styling(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def _setup_signals(self):
|
|
|
|
...
|
|
|
|
|
|
|
|
def _load_widgets(self):
|
2023-04-25 21:12:30 +00:00
|
|
|
icons_path = settings.get_icons_path()
|
2023-04-25 03:31:05 +00:00
|
|
|
center_widget = Gtk.ButtonBox()
|
2023-04-25 21:12:30 +00:00
|
|
|
zoomout_button = Gtk.Button()
|
|
|
|
lrotate_button = Gtk.Button()
|
|
|
|
vflip_button = Gtk.Button()
|
2023-04-27 00:26:19 +00:00
|
|
|
self.one2one_button = Gtk.Button()
|
|
|
|
self.fit_button = Gtk.Button()
|
2023-04-25 21:12:30 +00:00
|
|
|
hflip_button = Gtk.Button()
|
|
|
|
rrotate_button = Gtk.Button()
|
|
|
|
zoomin_button = Gtk.Button()
|
2023-04-25 03:31:05 +00:00
|
|
|
|
2023-04-27 03:00:13 +00:00
|
|
|
self._set_class(self.fit_button)
|
2023-04-25 21:12:30 +00:00
|
|
|
|
|
|
|
zoomout_button.set_tooltip_text("Zoom Out")
|
|
|
|
lrotate_button.set_tooltip_text("Rotate Left")
|
|
|
|
vflip_button.set_tooltip_text("Flip Vertical")
|
|
|
|
self.one2one_button.set_tooltip_text("Zoom 1:1")
|
|
|
|
self.fit_button.set_tooltip_text("Zoom Fit")
|
|
|
|
hflip_button.set_tooltip_text("Flip Horizontal")
|
|
|
|
rrotate_button.set_tooltip_text("Rotate Right")
|
|
|
|
zoomin_button.set_tooltip_text("Zoom In")
|
|
|
|
|
|
|
|
zoomout_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-out.png") )
|
|
|
|
lrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-left.png") )
|
|
|
|
vflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-virtical.png") )
|
|
|
|
self.one2one_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-original.png") )
|
|
|
|
self.fit_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-fit.png") )
|
|
|
|
hflip_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/flip-horizontal.png") )
|
|
|
|
rrotate_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/rotate-right.png") )
|
|
|
|
zoomin_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/zoom-in.png") )
|
|
|
|
|
|
|
|
zoomout_button.set_always_show_image(True)
|
|
|
|
lrotate_button.set_always_show_image(True)
|
|
|
|
vflip_button.set_always_show_image(True)
|
|
|
|
self.one2one_button.set_always_show_image(True)
|
|
|
|
self.fit_button.set_always_show_image(True)
|
|
|
|
hflip_button.set_always_show_image(True)
|
|
|
|
rrotate_button.set_always_show_image(True)
|
|
|
|
zoomin_button.set_always_show_image(True)
|
|
|
|
|
|
|
|
zoomout_button.connect("clicked", self._zoom_out)
|
2023-04-25 03:31:05 +00:00
|
|
|
lrotate_button.connect("clicked", self._rotate_left)
|
|
|
|
vflip_button.connect("clicked", self._vertical_flip)
|
2023-04-27 03:00:13 +00:00
|
|
|
self.one2one_button.connect("clicked", self._scale_1_two_1)
|
|
|
|
self.fit_button.connect("clicked", self._fit_to_container)
|
2023-04-25 03:31:05 +00:00
|
|
|
hflip_button.connect("clicked", self._horizontal_flip)
|
|
|
|
rrotate_button.connect("clicked", self._rotate_right)
|
2023-04-25 21:12:30 +00:00
|
|
|
zoomin_button.connect("clicked", self._zoom_in)
|
|
|
|
|
|
|
|
center_widget.add(zoomout_button)
|
|
|
|
center_widget.add(lrotate_button)
|
|
|
|
center_widget.add(vflip_button)
|
|
|
|
center_widget.add(self.one2one_button)
|
|
|
|
center_widget.add(self.fit_button)
|
|
|
|
center_widget.add(hflip_button)
|
|
|
|
center_widget.add(rrotate_button)
|
|
|
|
center_widget.add(zoomin_button)
|
2023-04-25 03:31:05 +00:00
|
|
|
|
|
|
|
self.set_center_widget(center_widget)
|
|
|
|
|
2023-04-25 21:12:30 +00:00
|
|
|
def _zoom_out(self, widget = None, eve = None):
|
|
|
|
event_system.emit("zoom_out")
|
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _rotate_left(self, widget = None, eve = None):
|
|
|
|
event_system.emit("rotate_left")
|
2023-04-25 21:12:30 +00:00
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _vertical_flip(self, widget = None, eve = None):
|
|
|
|
event_system.emit("vertical_flip")
|
2023-04-25 21:12:30 +00:00
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _scale_1_two_1(self, widget = None, eve = None):
|
2023-04-25 21:12:30 +00:00
|
|
|
if eve.button == 1:
|
2023-04-27 00:26:19 +00:00
|
|
|
self._unset_class(self.fit_button)
|
|
|
|
self._set_class(self.one2one_button)
|
2023-04-25 21:12:30 +00:00
|
|
|
|
|
|
|
event_system.emit("scale_1_two_1")
|
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _fit_to_container(self, widget = None, eve = None):
|
2023-04-25 21:12:30 +00:00
|
|
|
if eve.button == 1:
|
2023-04-27 00:26:19 +00:00
|
|
|
self._unset_class(self.one2one_button)
|
|
|
|
self._set_class(self.fit_button)
|
2023-04-25 21:12:30 +00:00
|
|
|
|
|
|
|
event_system.emit("fit_to_container")
|
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _horizontal_flip(self, widget = None, eve = None):
|
|
|
|
event_system.emit("horizontal_flip")
|
2023-04-25 21:12:30 +00:00
|
|
|
|
2023-04-25 03:31:05 +00:00
|
|
|
def _rotate_right(self, widget = None, eve = None):
|
|
|
|
event_system.emit("rotate_right")
|
2023-04-25 21:12:30 +00:00
|
|
|
|
|
|
|
def _zoom_in(self, widget = None, eve = None):
|
|
|
|
event_system.emit("zoom_in")
|
2023-04-27 00:26:19 +00:00
|
|
|
|
|
|
|
def _set_class(self, target):
|
|
|
|
ctx = target.get_style_context()
|
|
|
|
ctx.add_class("button-highlighted")
|
|
|
|
|
|
|
|
def _unset_class(self, target):
|
|
|
|
ctx = target.get_style_context()
|
|
|
|
ctx.remove_class("button-highlighted")
|