Mirage2/src/core/widgets/button_controls.py

137 lines
4.9 KiB
Python

# 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__()
self.one2one_button = None
self.fit_button = None
self._setup_styling()
self._setup_signals()
self._load_widgets()
self.show_all()
def _setup_styling(self):
...
def _setup_signals(self):
...
def _load_widgets(self):
icons_path = settings.get_icons_path()
center_widget = Gtk.ButtonBox()
zoomout_button = Gtk.Button()
lrotate_button = Gtk.Button()
vflip_button = Gtk.Button()
self.one2one_button = Gtk.Button()
self.fit_button = Gtk.Button()
hflip_button = Gtk.Button()
rrotate_button = Gtk.Button()
zoomin_button = Gtk.Button()
ocr_button = Gtk.Button()
self._set_class(self.fit_button)
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")
ocr_button.set_tooltip_text("OCR")
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") )
ocr_button.set_image( Gtk.Image.new_from_file(f"{icons_path}/ocr.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)
ocr_button.set_always_show_image(True)
zoomout_button.connect("clicked", self._zoom_out)
lrotate_button.connect("clicked", self._rotate_left)
vflip_button.connect("clicked", self._vertical_flip)
self.one2one_button.connect("clicked", self._scale_1_two_1)
self.fit_button.connect("clicked", self._fit_to_container)
hflip_button.connect("clicked", self._horizontal_flip)
rrotate_button.connect("clicked", self._rotate_right)
zoomin_button.connect("clicked", self._zoom_in)
ocr_button.connect("clicked", self._show_ocr)
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)
center_widget.add(ocr_button)
self.set_center_widget(center_widget)
def _zoom_out(self, widget = None, eve = None):
event_system.emit("zoom_out")
def _rotate_left(self, widget = None, eve = None):
event_system.emit("rotate_left")
def _vertical_flip(self, widget = None, eve = None):
event_system.emit("vertical_flip")
def _scale_1_two_1(self, widget = None, eve = None):
self._unset_class(self.fit_button)
self._set_class(self.one2one_button)
event_system.emit("scale_1_two_1")
def _fit_to_container(self, widget = None, eve = None):
self._unset_class(self.one2one_button)
self._set_class(self.fit_button)
event_system.emit("fit_to_container")
def _horizontal_flip(self, widget = None, eve = None):
event_system.emit("horizontal_flip")
def _rotate_right(self, widget = None, eve = None):
event_system.emit("rotate_right")
def _zoom_in(self, widget = None, eve = None):
event_system.emit("zoom_in")
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")
def _show_ocr(self, widget):
event_system.emit("show_ocr")