# 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.ToggleButton() self.fit_button = Gtk.ToggleButton() hflip_button = Gtk.Button() rrotate_button = Gtk.Button() zoomin_button = Gtk.Button() # TODO: add if check against settings pull to set 1:1 or fit self.one2one_button.set_active(True) self.fit_button.set_active(False) 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) lrotate_button.connect("clicked", self._rotate_left) vflip_button.connect("clicked", self._vertical_flip) self.one2one_button.connect("button-release-event", self._scale_1_two_1) self.fit_button.connect("button-release-event", 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) 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) 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): if eve.button == 1: self.fit_button.set_active(False) self.one2one_button.set_active(True) event_system.emit("scale_1_two_1") def _fit_to_container(self, widget = None, eve = None): if eve.button == 1: self.one2one_button.set_active(False) self.fit_button.set_active(True) 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")