diff --git a/src/kde_material_you_colors/config.py b/src/kde_material_you_colors/config.py index 946fbf9..8de67ac 100644 --- a/src/kde_material_you_colors/config.py +++ b/src/kde_material_you_colors/config.py @@ -176,6 +176,8 @@ def defaults(self): "chroma_multiplier": [args.chroma_multiplier, 1, 2], "tone_multiplier": [args.tone_multiplier, 1, 2], "qdbus_executable": [args.qdbus_executable, None, 3], + "manual_fetch": [args.manual_fetch, False, 0], + "fetch_colors": [None, False, 0], } def parse_conf(self): diff --git a/src/kde_material_you_colors/data/sample_config.conf b/src/kde_material_you_colors/data/sample_config.conf index 9c6b68a..1e3dfda 100644 --- a/src/kde_material_you_colors/data/sample_config.conf +++ b/src/kde_material_you_colors/data/sample_config.conf @@ -147,6 +147,7 @@ ncolor = 0 # of detections for those cases to save power. # NOTE: # Should be bigger than main_loop_delay (will take main_loop_delay otherwise) +# Ignored if manual color fetch is enabled # Default is 900 seconds (15 minutes) # Commented by default #screenshot_delay = 900 @@ -196,3 +197,9 @@ tone_multiplier = 1 # Default is qdbus6 # Deprecated, no longer needed as of version 1.10.0. Switched to gdbus command from glib2 # qdbus_executable = qdbus6 + +# Manual fetch +# Disables the automatic color fetching and +# scheduled screenshot take in screenshot mode +# Default is False +manual_fetch = False \ No newline at end of file diff --git a/src/kde_material_you_colors/main.py b/src/kde_material_you_colors/main.py index 028c2d9..8c1df89 100755 --- a/src/kde_material_you_colors/main.py +++ b/src/kde_material_you_colors/main.py @@ -341,6 +341,12 @@ def main(): default=None, metavar="", ) + parser.add_argument( + "--manual-fetch", + action="store_true", + help="Dissables automatic color fetching", + default=None, + ) # Get commandline arguments args = parser.parse_args() @@ -388,12 +394,17 @@ def main(): plugin_watcher = utils.Watcher(wallpaper.plugin) source_watcher = utils.Watcher(wallpaper.source) pause_watcher = utils.Watcher(config.read("pause_mode")) + manual_fetch_watcher = utils.Watcher(config.read("manual_fetch")) + fetch_watcher = utils.Watcher(config.read("fetch_colors")) if pause_watcher.value: msg = "Pause mode enabled" if pause_watcher.value else "Pause mode disabled" logging.warning(msg) if wallpaper.type == "screenshot": head = "Screenshot mode enabled" - cont = f"Waiting {config.read('screenshot_delay')}s between updates" + if config.read("manual_fetch"): + cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot" + else: + cont = f"Waiting {config.read('screenshot_delay')}s between updates" notify.send_notification(head, cont) logging.warning("%s, %s", head, cont) if wallpaper.error: @@ -429,10 +440,21 @@ def main(): # # # - # - # update wallpaper - wallpaper.update(config, skip_screenshot=counter != 0) - wallpaper_watcher.set_value(wallpaper.current) + # update wallpaper, only if manual_fetch is false + manual_fetch_watcher.set_value(config.read("manual_fetch")) + + if manual_fetch_watcher.has_changed(): + msg = "Manual color fetch enabled." if manual_fetch_watcher.value else "Manual color fetch disabled." + logging.info(msg) + + fetch_watcher.set_value(config.read("fetch_colors")) + if fetch_watcher.has_changed() and fetch_watcher.value: + logging.info("Fetching colors in current wallpaper...") + counter = 0 + + if not config.read("manual_fetch") or (fetch_watcher.has_changed() and fetch_watcher.value): + wallpaper.update(config, skip_screenshot=counter != 0) + wallpaper_watcher.set_value(wallpaper.current) target_cycles = config.read("screenshot_delay") / ( config.read("main_loop_delay") or 1 @@ -470,6 +492,7 @@ def main(): logging.info(f"{wallpaper}") apply_themes.apply(config, wallpaper, light_mode_watcher.value) apply = False + counter += 1 if group1: if wallpaper.error: @@ -479,7 +502,10 @@ def main(): logging.error(f"Could not get wallpaper {str(wallpaper.error)}") if plugin_watcher.changed and wallpaper.type == "screenshot": head = "Screenshot mode enabled" - cont = f"Waiting {config.read('screenshot_delay')}s between updates" + if config.read("manual_fetch"): + cont = "Manual color fetch enabled, press 'Fetch colors' in the widget to take a new screenshot" + else: + cont = f"Waiting {config.read('screenshot_delay')}s between updates" notify.send_notification(head, cont) logging.warning("%s, %s", head, cont) if wallpaper.source: @@ -492,7 +518,7 @@ def main(): apply_themes.apply(config, wallpaper, light_mode_watcher.value) counter = 0 - if wallpaper.is_screenshot(): + if wallpaper.is_screenshot() and not config.read("manual_fetch"): if target_cycles > counter: counter += 1 else: diff --git a/src/plasmoid/package/contents/ui/FullRepresentation.qml b/src/plasmoid/package/contents/ui/FullRepresentation.qml index 8dfbae6..c9fdd8a 100644 --- a/src/plasmoid/package/contents/ui/FullRepresentation.qml +++ b/src/plasmoid/package/contents/ui/FullRepresentation.qml @@ -59,8 +59,12 @@ ColumnLayout { property bool pauseMode: false + property bool manual_fetch: false + + signal savePauseMode() + property Item parentMain KCoreAddons.KUser { @@ -83,7 +87,6 @@ ColumnLayout { } } - // Get a list of installed icon themes as id,name // - discard hidden themes // - discard cursor themes @@ -331,7 +334,6 @@ ColumnLayout { level: 1 text: Plasmoid.metaData.name } - PlasmaComponents3.ToolButton { display: PlasmaComponents3.AbstractButton.IconOnly visible: !onDesktop @@ -346,7 +348,6 @@ ColumnLayout { text: parent.text } } - PlasmaComponents3.ToolButton { display: PlasmaComponents3.AbstractButton.IconOnly checkable: false @@ -452,14 +453,12 @@ ColumnLayout { } } } - Connections { target: fullRepresentation function onSavePauseMode() { settings.pause_mode = fullRepresentation.pauseMode } } - onMaterialYouDataChanged: { if (materialYouData!=null && materialYouDataString!=null) { if (JSON.stringify(materialYouData) !== materialYouDataString) { @@ -544,6 +543,8 @@ ColumnLayout { property int screenshot_delay: 900; \ property bool once_after_change: false; \ property bool pause_mode: false; \ + property bool manual_fetch: false; \ + property bool fetch_colors: false; \ property bool screenshot_only_mode: false; \ property int scheme_variant: 5; \ property real chroma_multiplier: 1.0; \ @@ -812,17 +813,37 @@ ColumnLayout { // Color selection RowLayout { Layout.preferredWidth: mainLayout.width - - PlasmaComponents3.Label { - text: "Select color" - id:selectColorLabel - Layout.fillWidth: settings.color!=="" + RowLayout { + id: selectColorLayout + PlasmaComponents3.Label { + text: "Select color" + id:selectColorLabel + } + // Button to manually fetch the colors on screen // + Timer { + id: fetchTimer + interval: settings.main_loop_delay * 1000; running: false; repeat: false; + onTriggered: settings.fetch_colors = false + } + RowLayout { + PlasmaComponents3.Button { + text: "Fetch colors" + icon.name: 'refreshstructure' + onClicked: { + settings.fetch_colors = true + fetchTimer.start() + } + PlasmaComponents3.ToolTip { + text: "Manually fetch the colors on the current wallpaper" + } + } + } } // Single color picker when color is not empty Components.CustomColorButton { // Components.Custom id: colorButton - Layout.alignment: Qt.AlignHCenter + Layout.alignment : Qt.AlignRight visible: settings.color!=="" showAlphaChannel: false dialogTitle: "Choose source color" @@ -840,7 +861,7 @@ ColumnLayout { GridLayout { //PlasmaComponents3.ScrollView property var gridSpacing: Kirigami.Units.mediumSpacing visible: settings.color==="" - columns: Math.floor((mainLayout.width - selectColorLabel.width) / ( + columns: Math.floor((mainLayout.width - selectColorLayout.width) / ( controlHeight * .75 + gridSpacing)) rowSpacing: gridSpacing columnSpacing: gridSpacing @@ -1919,6 +1940,36 @@ ColumnLayout { } } } + RowLayout { + PlasmaComponents3.Label { + text: "Manual color fetch only" + Layout.alignment: Qt.AlignLeft + } + + PlasmaComponents3.CheckBox { + checked: settings.manual_fetch + + onCheckedChanged: { + settings.manual_fetch = checked + fullRepresentation.manual_fetch = checked + } + } + + PlasmaComponents3.ToolButton { + icon.name: "help-contents" + + hoverEnabled: true + onClicked: manualFetchPopup.open() + + PlasmaComponents3.ToolTip { + id: manualFetchPopup + x: parent.width / 2 + y: parent.height + text: "The backend won't fetch the colors in the delay times, instead, it will fetch only when the 'Fetch colors' button is pressed by the user. Useful when using dynamic wallpapers." + } + } + } + RowLayout { PlasmaComponents3.Label {