Skip to content

Commit

Permalink
added controls dialog that can be opened with a tickbox or by pressin…
Browse files Browse the repository at this point in the history
…g C (#139)

* added controls dialog

* Update controls_dialog.py with copyright notice

* fix controls_dialog.py typos
  • Loading branch information
Felipegalind0 authored May 28, 2024
1 parent 7faa328 commit ec26022
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
69 changes: 69 additions & 0 deletions painter/src/main/python/controls_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Copyright (C) 2024 Felipe Galindo
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import sys
from PyQt5 import QtWidgets
from PyQt5 import QtCore

# class to create a new dialog window that shows the controls of the application
class ControlsDialog(QtWidgets.QDialog):
closed = QtCore.pyqtSignal()

def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Controls")
self.setMinimumSize(300, 200)

# controls_text = """
# Controls:
# - Left Click: Draw
# - Right Click: Erase
# - Scroll: Zoom
# - Arrow Keys: Move around
# - Ctrl + Z: Undo
# - Ctrl + Y: Redo
# """

controls_text = """
Controls:
- Show/Hide Predicted Segmentation: S
- Show/Hide Human Annotations: A
- Show/Hide Image: I
- Foreground: Q
- Background: W
- Erase: E
- Change Brush Size: Shift + Scroll
- Undo: Z
- Redo: Shift + cmd + Z
- Zoom In: Shift + '+'
- Zoom Out: -
- Zoom: Scroll
- Pan: cmd + drag the on the image with right click
"""

layout = QtWidgets.QVBoxLayout()
label = QtWidgets.QLabel(controls_text)
layout.addWidget(label)
self.setLayout(layout)

def closeEvent(self, event):
self.closed.emit()
super().closeEvent(event)
26 changes: 26 additions & 0 deletions painter/src/main/python/root_painter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
from im_viewer import ContextViewer
from random_split import RandomSplitWidget
from resize_images import ResizeWidget
from controls_dialog import ControlsDialog

use_plugin("pil")

Image.MAX_IMAGE_PIXELS = None
Expand Down Expand Up @@ -798,6 +800,15 @@ def init_active_project_ui(self):
bottom_bar_r_layout.addWidget(info_container_right)
bottom_bar_r_layout.setContentsMargins(0, 0, 0, 0)

# checkbox to show controls
self.controls_checkbox = QtWidgets.QCheckBox("Controls (C)")
self.controls_checkbox.stateChanged.connect(self.show_controls)
info_container_right_layout.addWidget(self.controls_checkbox)

# Add keyboard shortcut to show controls
shortcut = QtWidgets.QShortcut(QtGui.QKeySequence("C"), self)
shortcut.activated.connect(self.check_controls_checkbox)

self.add_menu()

self.resize(container_layout.sizeHint())
Expand All @@ -810,6 +821,21 @@ def view_fix():
self.graphics_view.fit_to_view()
QtCore.QTimer.singleShot(100, view_fix)

def show_controls(self, state):
if state == QtCore.Qt.Checked:
self.controls_dialog = ControlsDialog(self)
self.controls_dialog.closed.connect(self.uncheck_controls_checkbox)
self.controls_dialog.show()
else:
if hasattr(self, 'controls_dialog') and self.controls_dialog.isVisible():
self.controls_dialog.close()

def uncheck_controls_checkbox(self):
self.controls_checkbox.setChecked(False)

def check_controls_checkbox(self):
self.controls_checkbox.setChecked(True)

def track_changes(self):
if self.tracking:
return
Expand Down

0 comments on commit ec26022

Please sign in to comment.