diff --git a/gui/header.py b/gui/header.py index e771b9646..b03b61efb 100644 --- a/gui/header.py +++ b/gui/header.py @@ -33,12 +33,22 @@ def __init__(self, app): bottom = QHBoxLayout() self.scan = _create_button(app, top, tr('main.top_menu.scan'), 100, app.on_scan) - _create_button(app, top, tr('main.top_menu.organize'), 200, app.on_organize) - self.pull = _create_button(app, top, tr('main.top_menu.pull'), 100, app.on_pull) + if Config.allow_organize: + _create_button(app, top, tr('main.top_menu.organize'), 200, app.on_organize) + + if Config.allow_pull: + self.pull = _create_button(app, top, tr('main.top_menu.pull'), 100, app.on_pull) + self.titledb = _create_button(app, top, tr('main.top_menu.update_titledb'), 200, app.on_titledb) - _create_button(app, top, tr('main.top_menu.decompress_nsz'), 200, app.on_decompress) - _create_button(app, top, tr('main.top_menu.compress_nsp'), 200, app.on_compress) - self.gdrive = _create_button(app, top, tr('main.top_menu.setup_gdrive'), 200, app.on_gdrive) + + if Config.allow_decompress: + _create_button(app, top, tr('main.top_menu.decompress_nsz'), 200, app.on_decompress) + + if Config.allow_compress: + _create_button(app, top, tr('main.top_menu.compress_nsp'), 200, app.on_compress) + + if Config.allow_gdrive: + self.gdrive = _create_button(app, top, tr('main.top_menu.setup_gdrive'), 200, app.on_gdrive) top.addStretch() diff --git a/gui/panes/options.py b/gui/panes/options.py index d5d656981..e5354cd21 100644 --- a/gui/panes/options.py +++ b/gui/panes/options.py @@ -1,14 +1,16 @@ # -*- coding: utf-8 -*- -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFormLayout, QLabel, QHBoxLayout, QSlider, QGroupBox +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QFormLayout, QLabel, QHBoxLayout, QSlider, QGroupBox, QCheckBox from PyQt5.QtCore import Qt from nut import Config + def _init_slider(slider, min_value, max_value, value): slider.setMinimum(min_value) slider.setMaximum(max_value) slider.setValue(value) slider.valueChanged.connect(slider.save) + class Threads(QSlider): def __init__(self, parent): super().__init__(Qt.Horizontal) @@ -22,6 +24,7 @@ def save(self): if self.parent: self.parent.save() + class Compress(QSlider): def __init__(self, parent): super().__init__(Qt.Horizontal) @@ -35,6 +38,7 @@ def save(self): if self.parent: self.parent.save() + class SliderControl(QWidget): def __init__(self, _type): super().__init__() @@ -48,6 +52,25 @@ def save(self): self.label.setText(str(self.slider.value())) +class ConfCheckbox(QCheckBox): + """ConfCheckbox + """ + + def __init__(self, text, conf): + super().__init__(text) + self.conf = conf + value = getattr(Config, text) + self.setChecked(value) + self.setText(text.upper().replace('_', ' ')) + self.stateChanged.connect(self.onStateChanged) + + def onStateChanged(self, state): + print(f"ConfCheckbox state changed: {state}") + cleaned_text = self.text().lower().replace(' ', '_') + setattr(Config, cleaned_text, self.isChecked()) + Config.save() + + class Options(QWidget): def __init__(self): super().__init__() @@ -68,4 +91,13 @@ def __init__(self): groupLayout.addWidget(SliderControl(_type=Compress)) layout.addWidget(group) + group = QGroupBox('OTHERS - Must restart to take affect') + groupLayout = QHBoxLayout(group) + groupLayout.addWidget(ConfCheckbox('allow_organize', Config.allow_organize)) + groupLayout.addWidget(ConfCheckbox('allow_pull', Config.allow_pull)) + groupLayout.addWidget(ConfCheckbox('allow_decompress', Config.allow_decompress)) + groupLayout.addWidget(ConfCheckbox('allow_compress', Config.allow_compress)) + groupLayout.addWidget(ConfCheckbox('allow_gdrive', Config.allow_gdrive)) + layout.addWidget(group) + layout.addStretch() diff --git a/nut/Config.py b/nut/Config.py index eaf809f81..bb3c8a287 100644 --- a/nut/Config.py +++ b/nut/Config.py @@ -24,6 +24,11 @@ region = None autolaunchBrowser = True +allow_organize = True +allow_pull = True +allow_decompress = True +allow_compress = True +allow_gdrive = True titleBlacklist = [] titleWhitelist = [] @@ -266,6 +271,7 @@ def getTitleDemoUpdate(self, nsx, name): f = self.titleDemoUpdate return f + def getPath(path, name, default): if not path: path = os.path.splitext(default)[0] + name[-4:] @@ -274,9 +280,11 @@ def getPath(path, name, default): path = os.path.join(path, base) return path + def forceExt(path, ext): return os.path.splitext(path)[0] + ext + def jset(json_, paths_, value): # pylint: disable=redefined-builtin last = paths_.pop() for path in paths_: @@ -285,6 +293,7 @@ def jset(json_, paths_, value): # pylint: disable=redefined-builtin json_ = json_[path] json_[last] = value + def save(confFile='conf/nut.conf'): Print.debug("saving config") os.makedirs(os.path.dirname(confFile), exist_ok=True) @@ -306,6 +315,11 @@ def save(confFile='conf/nut.conf'): jset(j, ['autolaunchBrowser'], autolaunchBrowser) jset(j, ['autoUpdateTitleDb'], autoUpdateTitleDb) jset(j, ['allowNoMetadata'], allowNoMetadata) + jset(j, ['allow_organize'], allow_organize) + jset(j, ['allow_pull'], allow_pull) + jset(j, ['allow_decompress'], allow_decompress) + jset(j, ['allow_compress'], allow_compress) + jset(j, ['allow_gdrive'], allow_gdrive) with open(confFile, 'w', encoding='utf-8') as f: Print.debug("writing config to filesystem") @@ -323,6 +337,12 @@ def load(confFile): # pylint: disable=too-many-branches,too-many-statements global autoUpdateTitleDb # pylint: disable=global-statement global original # pylint: disable=global-statement global allowNoMetadata # pylint: disable=global-statement + global allow_organize + global allow_pull + global allow_decompress + global allow_compress + global allow_gdrive + with open(confFile, encoding='utf8') as f: try: @@ -332,6 +352,30 @@ def load(confFile): # pylint: disable=too-many-branches,too-many-statements print(f"Failed to load config file: {confFile}") # use normal print because of initialization order of Status / Print raise + try: + allow_organize = j['allow_organize'] + except BaseException: # pylint: disable=broad-except + pass + + try: + allow_pull = j['allow_pull'] + except BaseException: # pylint: disable=broad-except + pass + + try: + allow_decompress = j['allow_decompress'] + except BaseException: # pylint: disable=broad-except + pass + + try: + allow_compress = j['allow_decompress'] + except BaseException: # pylint: disable=broad-except + pass + + try: + allow_gdrive = j['allow_gdrive'] + except BaseException: # pylint: disable=broad-except + pass try: region = j['region'] except BaseException: # pylint: disable=broad-except