Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
UncertainProd
GitHub Repository: UncertainProd/FnF-Spritesheet-and-XML-Maker
Path: blob/master/src/settingswindow.py
254 views
1
import spritesheetgensettings
2
from PyQt5.QtWidgets import QWidget
3
from utils import g_settings
4
5
class SettingsWindow(QWidget):
6
def __init__(self, *args, **kwargs):
7
super().__init__(*args, **kwargs)
8
self.ui = spritesheetgensettings.Ui_Form()
9
self.ui.setupUi(self)
10
11
self.ui.packingalgo_combobox.addItems([
12
"Growing Packer (Fits the frames as tightly as possible but doesn't maintain frame ordering)",
13
"Ordered Packer (Fits the frames in the order they were added but produces a slightly bigger spritesheet)"
14
])
15
self.ui.packingalgo_combobox.setCurrentIndex(0)
16
# self.setStyleSheet(get_stylesheet_from_file("app-styles.qss"))
17
18
# self.isclip = self.ui.clip_checkbox.checkState()
19
# self.prefix_type = 'custom' if self.ui.custom_prefix_radiobtn.isChecked() else 'charname'
20
# self.custom_prefix = self.ui.custom_prefix_text.text()
21
# self.must_use_prefix = self.ui.insist_prefix_checkbox.checkState()
22
self.saveSettings(False)
23
24
self.ui.custom_prefix_radiobtn.toggled.connect(lambda is_toggled: self.ui.custom_prefix_text.setEnabled(is_toggled))
25
self.ui.save_settings_btn.clicked.connect(lambda: self.saveSettings()) # make sure event related parameters don't get accidentally sent to self.saveSettings
26
self.ui.settings_cancel_btn.clicked.connect(self.restoreToNormal)
27
28
# hide the no_merge checkbox for now as it is a WIP
29
self.ui.no_merge_checkbox.setVisible(False)
30
31
def _get_prefix_type(self):
32
if self.ui.custom_prefix_radiobtn.isChecked():
33
return 'custom'
34
elif self.ui.charname_first_radiobtn.isChecked():
35
return 'charname'
36
elif self.ui.no_prefix_radiobtn.isChecked():
37
return 'noprefix'
38
39
def _set_radiobuttons(self):
40
self.ui.custom_prefix_radiobtn.setChecked(self.prefix_type == 'custom')
41
self.ui.charname_first_radiobtn.setChecked(self.prefix_type == 'charname')
42
self.ui.no_prefix_radiobtn.setChecked(self.prefix_type == 'noprefix')
43
44
def restoreToNormal(self):
45
self.ui.clip_checkbox.setCheckState(self.isclip)
46
self._set_radiobuttons()
47
self.ui.custom_prefix_text.setText(self.custom_prefix)
48
self.ui.insist_prefix_checkbox.setCheckState(self.must_use_prefix)
49
self.ui.frame_padding_spinbox.setValue(self.frame_padding)
50
self.ui.packingalgo_combobox.setCurrentIndex(self.packing_algo)
51
# self.ui.no_merge_checkbox.setCheckState(self.no_merge)
52
self.close()
53
54
def saveSettings(self, shouldclose=True):
55
self.isclip = self.ui.clip_checkbox.checkState()
56
# self.prefix_type = 'custom' if self.ui.custom_prefix_radiobtn.isChecked() else 'charname'
57
self.prefix_type = self._get_prefix_type()
58
self.custom_prefix = self.ui.custom_prefix_text.text()
59
self.must_use_prefix = self.ui.insist_prefix_checkbox.checkState()
60
self.frame_padding = self.ui.frame_padding_spinbox.value()
61
self.packing_algo = self.ui.packingalgo_combobox.currentIndex()
62
# self.no_merge = self.ui.no_merge_checkbox.checkState()
63
# saving to global settings obj
64
g_settings['isclip'] = self.isclip
65
g_settings['prefix_type'] = self.prefix_type
66
g_settings['custom_prefix'] = self.custom_prefix
67
g_settings['must_use_prefix'] = self.must_use_prefix
68
g_settings['frame_padding'] = self.frame_padding
69
g_settings['packing_algo'] = self.packing_algo
70
# g_settings['no_merge'] = self.no_merge
71
if shouldclose:
72
self.close()
73
74
def closeEvent(self, a0):
75
self.restoreToNormal()
76
# return super().closeEvent(a0)
77