Skip to content

Commit

Permalink
fixes grid preferences in settings window
Browse files Browse the repository at this point in the history
  • Loading branch information
w4ffl35 committed Oct 18, 2023
1 parent dd9cd4d commit da928b2
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
from airunner.widgets.grid_preferences.templates.grid_preferences_ui import Ui_grid_preferences
from airunner.windows.custom_widget import CustomWidget

from PyQt6.QtWidgets import QColorDialog

from airunner.widgets.base_widget import BaseWidget
from airunner.widgets.grid_preferences.templates.grid_preferences_ui import Ui_grid_preferences

class GridWidget(CustomWidget):
def __init__(self, **kwargs):
super().__init__(**kwargs)

self.ui = Ui_grid_preferences()
self.ui.setupUi(self)
class GridPreferencesWidget(BaseWidget):
widget_class_ = Ui_grid_preferences

self.ui.gridLineColorButton.clicked.connect(self.handle_grid_line_color_button)
self.ui.canvas_color.clicked.connect(self.handle_canvas_color_button)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.ui.grid_size_spinbox.setValue(self.settings_manager.grid_settings.size)
self.ui.grid_size_spinbox.valueChanged.connect(self.handle_grid_size_change)
self.ui.grid_line_width_spinbox.blockSignals(True)
self.ui.grid_size_spinbox.blockSignals(True)
self.ui.show_grid_checkbox.blockSignals(True)
self.ui.snap_to_grid_checkbox.blockSignals(True)

self.ui.grid_line_width_spinbox.setValue(self.settings_manager.grid_settings.line_width)
self.ui.grid_line_width_spinbox.valueChanged.connect(self.handle_line_width_change)

self.ui.grid_size_spinbox.setValue(self.settings_manager.grid_settings.size)
self.ui.show_grid_checkbox.setChecked(self.settings_manager.grid_settings.show_grid is True)
self.ui.show_grid_checkbox.stateChanged.connect(self.handle_show_grid_checkbox)

self.ui.snap_to_grid_checkbox.setChecked(self.settings_manager.grid_settings.snap_to_grid is True)
self.ui.snap_to_grid_checkbox.stateChanged.connect(self.handle_snap_to_grid_checkbox)

def handle_grid_line_color_button(self):
self.ui.grid_line_width_spinbox.blockSignals(False)
self.ui.grid_size_spinbox.blockSignals(False)
self.ui.show_grid_checkbox.blockSignals(False)
self.ui.snap_to_grid_checkbox.blockSignals(False)

def action_toggled_snap_to_grid(self, val):
self.settings_manager.set_value("grid_settings.snap_to_grid", val)

def action_toggled_show_grid(self, val):
self.settings_manager.set_value("grid_settings.show_grid", val)

def action_button_clicked_grid_line_color(self):
color = QColorDialog.getColor()
if color.isValid():
self.settings_manager.set_value("grid_settings.line_color", color.name())
self.app.canvas.update_grid_pen()

def handle_canvas_color_button(self):
def action_button_clicked_canvas_color(self):
color = QColorDialog.getColor()
if color.isValid():
self.settings_manager.set_value("grid_settings.canvas_color", color.name())
self.app.canvas.update_canvas_color(color.name())

def handle_grid_size_change(self, val):
def grid_size_changed(self, val):
self.settings_manager.set_value("grid_settings.size", val)
self.app.canvas.update()

def handle_line_width_change(self, val):
def line_width_changed(self, val):
self.settings_manager.set_value("grid_settings.line_width", val)
self.app.canvas.update()

def handle_show_grid_checkbox(self, val):
self.settings_manager.set_value("grid_settings.show_grid", val == 2)
self.app.canvas.update()

def handle_snap_to_grid_checkbox(self, val):
self.settings_manager.set_value("grid_settings.snap_to_grid", val == 2)
self.app.canvas.update()
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,109 @@
</widget>
<resources/>
<connections>
<connection>
<sender>grid_size_spinbox</sender>
<signal>valueChanged(int)</signal>
<receiver>grid_preferences</receiver>
<slot>grid_size_changed(int)</slot>
<hints>
<hint type="sourcelabel">
<x>37</x>
<y>41</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>-13</y>
</hint>
</hints>
</connection>
<connection>
<sender>grid_line_width_spinbox</sender>
<signal>valueChanged(int)</signal>
<receiver>grid_preferences</receiver>
<slot>line_width_changed(int)</slot>
<hints>
<hint type="sourcelabel">
<x>98</x>
<y>104</y>
</hint>
<hint type="destinationlabel">
<x>94</x>
<y>-11</y>
</hint>
</hints>
</connection>
<connection>
<sender>gridLineColorButton</sender>
<signal>clicked()</signal>
<receiver>grid_preferences</receiver>
<slot>action_button_clicked_grid_line_color()</slot>
<hints>
<hint type="sourcelabel">
<x>236</x>
<y>137</y>
</hint>
<hint type="destinationlabel">
<x>227</x>
<y>-11</y>
</hint>
</hints>
</connection>
<connection>
<sender>canvas_color</sender>
<signal>clicked()</signal>
<receiver>grid_preferences</receiver>
<slot>action_button_clicked_canvas_color()</slot>
<hints>
<hint type="sourcelabel">
<x>262</x>
<y>165</y>
</hint>
<hint type="destinationlabel">
<x>294</x>
<y>5</y>
</hint>
</hints>
</connection>
<connection>
<sender>show_grid_checkbox</sender>
<signal>toggled(bool)</signal>
<receiver>grid_preferences</receiver>
<slot>action_toggled_show_grid(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>45</x>
<y>190</y>
</hint>
<hint type="destinationlabel">
<x>175</x>
<y>4</y>
</hint>
</hints>
</connection>
<connection>
<sender>snap_to_grid_checkbox</sender>
<signal>toggled(bool)</signal>
<receiver>snap_to_grid_checkbox</receiver>
<slot>click()</slot>
<receiver>grid_preferences</receiver>
<slot>action_toggled_snap_to_grid(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>165</x>
<x>87</x>
<y>221</y>
</hint>
<hint type="destinationlabel">
<x>165</x>
<y>221</y>
<x>140</x>
<y>0</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>size_changed(int)</slot>
<slot>line_width_changed(int)</slot>
<slot>action_button_clicked_grid_line_color()</slot>
<slot>action_button_clicked_canvas_color()</slot>
<slot>action_toggled_show_grid(bool)</slot>
<slot>action_toggled_snap_to_grid(bool)</slot>
</slots>
</ui>
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ def setupUi(self, grid_preferences):
self.gridLayout.addWidget(self.canvas_color, 5, 0, 1, 1)

self.retranslateUi(grid_preferences)
self.snap_to_grid_checkbox.toggled['bool'].connect(self.snap_to_grid_checkbox.click) # type: ignore
self.grid_size_spinbox.valueChanged['int'].connect(grid_preferences.grid_size_changed) # type: ignore
self.grid_line_width_spinbox.valueChanged['int'].connect(grid_preferences.line_width_changed) # type: ignore
self.gridLineColorButton.clicked.connect(grid_preferences.action_button_clicked_grid_line_color) # type: ignore
self.canvas_color.clicked.connect(grid_preferences.action_button_clicked_canvas_color) # type: ignore
self.show_grid_checkbox.toggled['bool'].connect(grid_preferences.action_toggled_show_grid) # type: ignore
self.snap_to_grid_checkbox.toggled['bool'].connect(grid_preferences.action_toggled_snap_to_grid) # type: ignore
QtCore.QMetaObject.connectSlotsByName(grid_preferences)

def retranslateUi(self, grid_preferences):
Expand Down
6 changes: 3 additions & 3 deletions src/airunner/windows/settings/airunner_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from PyQt6.QtGui import QStandardItemModel, QStandardItem, QBrush, QColor, QPainter
from PyQt6.QtWidgets import QStyledItemDelegate, QStyleOptionViewItem, QLabel, QWidget, QVBoxLayout, QPlainTextEdit
from airunner.widgets.export_preferences.export_preferences_widget import ExportPreferencesWidget
from airunner.widgets.grid_preferences.grid_preferences_widget import GridPreferencesWidget

from airunner.widgets.keyboard_shortcuts.keyboard_shortcuts_widget import KeyboardShortcutsWidget
from airunner.widgets.paths.paths_widget import PathsWidget
from airunner.windows.settings.templates.airunner_settings_ui import Ui_airunner_settings
from airunner.windows.base_window import BaseWindow
# open the version file from the root of the project and get the VERSION variable string from it
from airunner.windows.grid_widget import GridWidget
from airunner.windows.memory_widget import MemoryWidget


Expand Down Expand Up @@ -235,12 +235,12 @@ def show_content(self, section, display_name, name, description):
"paths": PathsWidget,
"keyboard_shortcuts": KeyboardShortcutsWidget,
"export_preferences": ExportPreferencesWidget,
"grid": GridWidget,
"grid": GridPreferencesWidget,
"memory": MemoryWidget,
# "hf_api_key": HFAPIKeyWidget,
}
if name in widgets:
if name in ["paths", "export_preferences"]:
if name in ["paths", "export_preferences", "grid"]:
widget_object = widgets[name]()
else:
widget_object = widgets[name](
Expand Down

0 comments on commit da928b2

Please sign in to comment.