Skip to content

Commit

Permalink
hotfixing settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenNingia committed May 8, 2019
1 parent 78590bf commit 64d13b8
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 38 deletions.
2 changes: 2 additions & 0 deletions l5r/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,8 @@ def main():

# Setup translation
settings = L5RCMSettings()
settings.load_defaults()
settings.sync()

app_translator = QtCore.QTranslator(app)
qt_translator = QtCore.QTranslator(app)
Expand Down
86 changes: 62 additions & 24 deletions l5r/util/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,61 @@ def pc_export(self):
def npc_export(self):
return self._npc_export

def __exit__(self):
# probably not needed
def sync(self):
self._qsettings.sync()

def load_defaults(self):
self._app.load_defaults()
self._ui.load_defaults()
self._pc_export.load_defaults()
self._npc_export.load_defaults()



class L5RCMSettings_UI(object):
"""Contains UI settings"""

def __init__(self, qsettings):
self._qsettings = qsettings

def load_defaults(self):
self.table_row_color_bg = self.table_row_color_bg
self.table_row_color_fg = self.table_row_color_fg
self.table_row_color_alt_bg = self.table_row_color_alt_bg
self.table_row_color_alt_fg = self.table_row_color_alt_fg
self.table_row_size = self.table_row_size
self.use_system_font = self.use_system_font
self.user_font = self.user_font
self.banner_enabled = self.banner_enabled

# getter
@property
def table_row_color_bg(self):
return self._qsettings.value('ui/table-row-color-bg')
return self._qsettings.value('ui/table_row_color_bg')

@property
def table_row_color_fg(self):
return self._qsettings.value('ui/table-row-color-fg')
return self._qsettings.value('ui/table_row_color_fg')

@property
def table_row_color_alt_bg(self):
return self._qsettings.value('ui/table-row-color-alt-bg', QBrush(QColor("#eeeeee")))
return self._qsettings.value('ui/table_row_color_alt_bg', QBrush(QColor("#eeeeee")))

@property
def table_row_color_alt_fg(self):
return self._qsettings.value('ui/table-row-color-alt-fg')
return self._qsettings.value('ui/table_row_color_alt_fg')

@property
def table_row_size(self):
return self._qsettings.value('ui/table-row-size')
return self._qsettings.value('ui/table_row_size')

@property
def use_system_font(self):
return self._qsettings.value('ui/use-system-font')
return self._qsettings.value('ui/use_system_font', True)

@property
def user_font(self):
return self._qsettings.value('ui/user-font')
return self._qsettings.value('ui/user_font')

@property
def banner_enabled(self):
Expand All @@ -101,35 +117,35 @@ def banner_enabled(self):
# setter
@table_row_color_bg.setter
def table_row_color_bg(self, value):
self._qsettings.setValue('ui/table-row-color-bg', value)
self._qsettings.setValue('ui/table_row_color_bg', value)

@table_row_color_fg.setter
def table_row_color_fg(self, value):
self._qsettings.setValue('ui/table-row-color-fg', value)
self._qsettings.setValue('ui/table_row_color_fg', value)

@table_row_color_alt_bg.setter
def table_row_color_alt_bg(self, value):
self._qsettings.setValue('ui/table-row-color-alt-bg', value)
self._qsettings.setValue('ui/table_row_color_alt_bg', value)

@table_row_color_alt_fg.setter
def table_row_color_alt_fg(self, value):
self._qsettings.setValue('ui/table-row-color-alt-fg', value)
self._qsettings.setValue('ui/table_row_color_alt_fg', value)

@table_row_size.setter
def table_row_size(self, value):
self._qsettings.setValue('ui/table-row-size', value)
self._qsettings.setValue('ui/table_row_size', value)

@use_system_font.setter
def use_system_font(self, value):
self._qsettings.setValue('ui/use-system-font', value)
self._qsettings.setValue('ui/use_system_font', value)

@user_font.setter
def font_size(self, value):
self._qsettings.setValue('ui/user-font', value)
def user_font(self, value):
self._qsettings.setValue('ui/user_font', value)

@banner_enabled.setter
def banner_enabled(self, value):
self._qsettings.setValue('ui/isbannerenabled', str(value))
self._qsettings.setValue('ui/isbannerenabled', value)


class L5RCMSettings_PcExport(object):
Expand All @@ -138,9 +154,16 @@ class L5RCMSettings_PcExport(object):
def __init__(self, qsettings):
self._qsettings = qsettings

def load_defaults(self):
self.first_page_skills = self.first_page_skills

@property
def first_page_skills(self):
return _is_true(self._qsettings.value('pcexport/first-page-skills', True))
return _is_true(self._qsettings.value('pcexport/first_page_skills', True))

@first_page_skills.setter
def first_page_skills(self, value):
self._qsettings.setValue('pcexport/first_page_skills', value)


class L5RCMSettings_NpcExport(object):
Expand All @@ -149,12 +172,28 @@ class L5RCMSettings_NpcExport(object):
def __init__(self, qsettings):
self._qsettings = qsettings

def load_defaults(self):
pass


class L5RCMSettings_App(object):
"""Contains application settings"""
def __init__(self, qsettings):
self._qsettings = qsettings

def load_defaults(self):
self.health_method = self.health_method
self.data_pack_blacklist = self.data_pack_blacklist
self.warn_about_refund = self.warn_about_refund
self.last_open_image_dir = self.last_open_image_dir
self.last_open_data_dir = self.last_open_data_dir
self.last_open_dir = self.last_open_dir
self.insight_calculation = self.insight_calculation
self.advise_successful_import = self.advise_successful_import
# skip geometry
self.user_locale = self.user_locale
self.use_system_locale = self.use_system_locale

# getter
@property
def health_method(self):
Expand Down Expand Up @@ -186,7 +225,7 @@ def insight_calculation(self):

@property
def advise_successful_import(self):
return _is_true(self._qsettings.value('advise_successfull_import', True))
return _is_true(self._qsettings.value('advise_successful_import', True))

@property
def geometry(self):
Expand All @@ -207,12 +246,11 @@ def health_method(self, value):

@data_pack_blacklist.setter
def data_pack_blacklist(self, value):
print('set data_pack_blacklist', value)
self._qsettings.setValue('data_pack_blacklist', value)

@warn_about_refund.setter
def warn_about_refund(self, value):
self._qsettings.setValue('warn_about_refund', str(value))
self._qsettings.setValue('warn_about_refund', value)

@last_open_image_dir.setter
def last_open_image_dir(self, value):
Expand All @@ -232,15 +270,15 @@ def insight_calculation(self, value):

@advise_successful_import.setter
def advise_successful_import(self, value):
self._qsettings.setValue('advise_successfull_import', str(value))
self._qsettings.setValue('advise_successful_import', value)

@geometry.setter
def geometry(self, value):
self._qsettings.setValue('geometry', value)

@use_system_locale.setter
def use_system_locale(self, value):
self._qsettings.setValue('use_machine_locale', str(value))
self._qsettings.setValue('use_machine_locale', value)

@user_locale.setter
def user_locale(self, value):
Expand Down
33 changes: 19 additions & 14 deletions l5r/widgets/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QObject, pyqtProperty
from l5r.util.settings import L5RCMSettings
import api

class QExampleListModel(QtCore.QAbstractListModel):
Expand Down Expand Up @@ -159,10 +160,9 @@ def __init__(self, parent, signal, prop, setting, data_converter=None, callback=
self.converter = data_converter
self.callback = callback

self.settings = QtCore.QSettings()
signal.connect(self.on_notify)

self.update_property()
signal.connect(self.on_notify)

def on_notify(self, *args, **kwargs):
if self.converter:
Expand All @@ -171,14 +171,17 @@ def on_notify(self, *args, **kwargs):
nv = self.parent().property(self.prop)

print("update settings {} = {}".format(self.setting, nv))
self.settings.setValue(self.setting, nv)
settings = QtCore.QSettings()
settings.setValue(self.setting, nv)
self.update_property()

def update_property(self):
settings = QtCore.QSettings()

if self.converter:
nv = self.converter.convert_to(self.settings.value(self.setting))
nv = self.converter.convert_to(settings.value(self.setting))
else:
nv = self.settings.value(self.setting)
nv = settings.value(self.setting)

#if self.parent().property(self.prop) == nv:
# return
Expand All @@ -195,8 +198,10 @@ class QComboBoxSettingsBinder(QPropertySettingsBinder):
def __init__(self, parent, setting, data_converter=None, callback=None):
super(QComboBoxSettingsBinder, self).__init__(parent, parent.activated, 'currentData', setting, data_converter, callback)

settings = QtCore.QSettings()

# workaround for combobox
idx = parent.findData(self.settings.value(setting))
idx = parent.findData(settings.value(setting))
parent.setCurrentIndex(idx)


Expand Down Expand Up @@ -327,7 +332,7 @@ def setup(self, app):
self.bt_select_font,
self.bt_select_font.clicked,
"text",
"ui/user-font",
"ui/user_font",
QFontSelectorDataConverter(self))

self.ck_use_system_font.toggled.connect(
Expand All @@ -342,8 +347,8 @@ def setup(self, app):
QPropertySettingsBinder(
self.ck_show_banner,
self.ck_show_banner.stateChanged,
"checked", "isbannerenabled",
callback=lambda x: app.sink1.set_banner_visibility(x == 'true'))
"checked", "ui/isbannerenabled",
callback=lambda x: app.sink1.set_banner_visibility(x))

# health display
hmethods = [
Expand Down Expand Up @@ -377,35 +382,35 @@ def setup(self, app):
self.lv_example_model,
self.bt_odd_bg.clicked,
"odd_bg",
"ui/table-row-color-bg",
"ui/table_row_color_bg",
QBrushSelectorDataConverter(self))

QPropertySettingsBinder(
self.lv_example_model,
self.bt_evn_bg.clicked,
"evn_bg",
"ui/table-row-color-alt-bg",
"ui/table_row_color_alt_bg",
QBrushSelectorDataConverter(self))

QPropertySettingsBinder(
self.lv_example_model,
self.bt_odd_fg.clicked,
"odd_fg",
"ui/table-row-color-fg",
"ui/table_row_color_fg",
QBrushSelectorDataConverter(self))

QPropertySettingsBinder(
self.lv_example_model,
self.bt_evn_fg.clicked,
"evn_fg",
"ui/table-row-color-alt-fg",
"ui/table_row_color_alt_fg",
QBrushSelectorDataConverter(self))

# pdf sheet
QPropertySettingsBinder(
self.ck_skills_on_first_page,
self.ck_skills_on_first_page.stateChanged,
"checked", "pcexport/first-page-skills")
"checked", "pcexport/first_page_skills")


def test():
Expand Down

0 comments on commit 64d13b8

Please sign in to comment.