Example #1
0
    def run(self):
        while True:

            if terminate:
                config.update("running", False)
                break

            if not config.is_scheduled():
                config.update("running", False)
                break

            editable = config.get_config()

            theme = config.get("theme")

            if should_be_light():
                if theme == "light":
                    time.sleep(30)
                    continue
                else:
                    switch_to_light()
            else:
                if theme == "dark":
                    time.sleep(30)
                    continue
                else:
                    switch_to_dark()

            time.sleep(30)
Example #2
0
def main():
    # using ArgumentParser for parsing arguments
    parser = ArgumentParser()
    parser.add_argument("-t", "--toggle",
                        help="toggles Yin-Yang",
                        action="store_true")
    parser.add_argument("-s", "--schedule",
                        help="schedule theme toggl, starts daemon in bg",
                        action="store_true")
    args = parser.parse_args()

    # checks wether $ yin-yang is ran without args
    if len(sys.argv) == 1 and not args.toggle:
        # load GUI
        app = QtWidgets.QApplication(sys.argv)
        window = gui.MainWindow()
        window.show()
        sys.exit(app.exec_())

    # checks wether the script should be ran as a daemon
    if args.schedule:
        config.update("running", False)
        print("START thread listener")
        if config.get("schedule"):
            yin_yang.startDaemon()
        else:
            print("looks like you did not specified a time")
            print("You can use the gui with yin-yang -gui")
            print("Or edit the config found in ~/.config/yin_yang/yin_yang.json")
            print("You need to set schedule to True and edit the time to toggles")

    # gui is set as parameter
    if args.toggle:
        toggle_theme()
Example #3
0
 def time_changed(self):
     # update config if time has changed
     l_hour, l_minute = str(self.ui.light_time.time().hour()), str(
         self.ui.light_time.time().minute())
     d_hour, d_minute = str(self.ui.dark_time.time().hour()), str(
         self.ui.dark_time.time().minute())
     config.update("switchToLight", l_hour + ":" + l_minute)
     config.update("switchToDark", d_hour + ":" + d_minute)
Example #4
0
 def toggle_schedule_cliked(self):
     checked = self.ui.schedule_radio.isChecked()
     config.update("schedule", checked)
     if checked:
         self.ui.dark_time.setEnabled(True)
         self.ui.light_time.setEnabled(True)
     else:
         self.ui.dark_time.setEnabled(False)
         self.ui.light_time.setEnabled(False)
Example #5
0
    def enabled(self, value: bool):
        # needs to be copied because super().setter does not work
        # for more information see:
        # https://stackoverflow.com/questions/10810369/python-super-and-setting-parent-class-property
        config.update(str(self) + 'Enabled', value)

        if value:
            print(
                'Please remember to install the Yin-Yang plugin in Firefox.\n'
                +
                'You can get it here: https://addons.mozilla.org/de/firefox/addon/yin-yang-linux/'
            )
Example #6
0
 def get_kde_themes(self):
     if config.get("desktop") == "kde":
         if (self.ui.kde_combo_light.count() == 0
                 and self.ui.kde_combo_dark.count() == 0):
             # asks the system what themes are available
             ugly_themes = subprocess.check_output(
                 ["lookandfeeltool", "-l"], universal_newlines=True)
             pretty_themes = ugly_themes.splitlines()
             for theme in pretty_themes:
                 self.ui.kde_combo_light.addItem(theme)
                 self.ui.kde_combo_dark.addItem(theme)
     else:
         self.ui.kde_combo_light.setEnabled(False)
         self.ui.kde_combo_dark.setEnabled(False)
         self.ui.kde_checkbox.setChecked(False)
         config.update("codeEnabled", False)
Example #7
0
    def get_kde_themes(self):
        """
        Sends the kde themes to the ui.
        """
        if config.get("desktop") == "kde":
            if (self.ui.kde_combo_light.count() == 0 and self.ui.kde_combo_dark.count() == 0):
                kde_themes = self.get_kde_theme_names()

                for name, theme in kde_themes.items():
                    self.ui.kde_combo_light.addItem(name)
                    self.ui.kde_combo_dark.addItem(name)
        else:
            self.ui.kde_combo_light.setEnabled(False)
            self.ui.kde_combo_dark.setEnabled(False)
            self.ui.kde_checkbox.setChecked(False)
            config.update("codeEnabled", False)
Example #8
0
def main():
    # using ArgumentParser for parsing arguments
    parser = ArgumentParser()
    parser.add_argument("-t",
                        "--toggle",
                        help="toggles Yin-Yang",
                        action="store_true")
    parser.add_argument("-s",
                        "--schedule",
                        help="schedule theme toggle, starts daemon in bg",
                        action="store_true")
    args = parser.parse_args()

    # checks whether $ yin-yang is ran without args
    if len(sys.argv) == 1 and not args.toggle:
        # load GUI
        app = QtWidgets.QApplication(sys.argv)
        window = gui.MainWindow()
        window.show()
        sys.exit(app.exec_())

    # checks whether the script should be ran as a daemon
    if args.schedule:
        config.update("running", False)
        logger.debug("START thread listener")

        if config.get("followSun"):
            # calculate time if needed
            config.set_sun_time()

        if config.get("schedule"):
            yin_yang.start_daemon()
        else:
            logger.warning(
                "Tried to start scheduler, but schedule was not enabled.")
            print(
                "Looks like you have not specified a time."
                "You can use the GUI by running Yin & Yang or "
                "edit the config found in ~/.config/yin_yang/yin_yang.json."
                "You need to set schedule to true and edit the time to toggles."
            )

    if args.toggle:
        # terminate any running instances
        config.update("running", False)
        config.update("followSun", False)
        config.update("schedule", False)
        toggle_theme()
Example #9
0
    def save_and_exit(self):
        print("saving options")

        kde_light_short = self.ui.kde_combo_light.currentText()
        kde_dark_short = self.ui.kde_combo_dark.currentText()

        config.update("kdeLightTheme",
                      self.get_kde_theme_long(kde_light_short))
        config.update("kdeDarkTheme", self.get_kde_theme_long(kde_dark_short))
        config.update("kdeEnabled", self.ui.kde_checkbox.isChecked())

        config.update("codeLightTheme", self.ui.code_line_light.text())
        config.update("codeDarkTheme", self.ui.code_line_dark.text())
        config.update("codeEnabled", self.ui.code_checkbox.isChecked())

        config.update("gtkLightTheme", self.ui.gtk_line_light.text())
        config.update("gtkDarkTheme", self.ui.gtk_line_dark.text())
        config.update("gtkEnabled", self.ui.gtk_checkbox.isChecked())

        config.update("kvantumLightTheme", self.ui.kvantum_line_light.text())
        config.update("kvantumDarkTheme", self.ui.kvantum_line_dark.text())
        config.update("kvantumEnabled", self.ui.kvantum_checkbox.isChecked())

        config.update("atomLightTheme", self.ui.atom_line_light.text())
        config.update("atomDarkTheme", self.ui.atom_line_dark.text())
        config.update("atomEnabled", self.ui.atom_checkbox.isChecked())

        # showing the main window and hiding the current one
        self.hide()
        self.window = MainWindow()
        self.window.show()
Example #10
0
 def toggle_sound(self):
     config.update("soundEnabled", self.ui.sound_checkBox.isChecked())
     self.sync_with_config()
Example #11
0
 def toggle_gtk_fields(self):
     checked = self.ui.gtk_checkbox.isChecked()
     self.ui.gtk_line_light.setEnabled(checked)
     self.ui.gtk_line_dark.setEnabled(checked)
     config.update("gtkEnabled", checked)
Example #12
0
 def toggle_kvantum_fields(self):
     checked = self.ui.kvantum_checkbox.isChecked()
     self.ui.kvantum_line_light.setEnabled(checked)
     self.ui.kvantum_line_dark.setEnabled(checked)
     config.update("kvantumEnabled", checked)
Example #13
0
 def toggle_wallpaper_buttons(self):
     checked = self.ui.wallpaper_checkbox.isChecked()
     self.ui.wallpaper_button_light.setEnabled(checked)
     self.ui.wallpaper_button_dark.setEnabled(checked)
     config.update("wallpaperEnabled", checked)
Example #14
0
 def toggle_code_fields(self):
     checked = self.ui.code_checkbox.isChecked()
     self.ui.code_line_light.setEnabled(checked)
     self.ui.code_line_dark.setEnabled(checked)
     config.update("codeEnabled", checked)
Example #15
0
 def theme_dark(self, theme: str):
     config.update(str(self) + 'DarkTheme', theme)
Example #16
0
def switch_to_light():
    yang = Yang(1)
    yang.start()
    config.update("theme", "light")
    yang.join()
Example #17
0
 def open_wallpaper_light(self):
     file_name, _ = QFileDialog.getOpenFileName(
         self, "Open Wallpaper Light", "")
     subprocess.run(["notify-send", "Light Wallpaper set"])
     config.update("wallpaperLightTheme", file_name)
Example #18
0
 def open_wallpaper_dark(self):
     file_name, _ = QFileDialog.getOpenFileName(
         self, "Open Wallpaper Dark", "")
     subprocess.run(["notify-send", "Dark Wallpaper set"])
     config.update("wallpaperDarkTheme", file_name)
Example #19
0
 def theme_light(self, theme: str):
     config.update(str(self) + 'LightTheme', theme)
Example #20
0
def update_config():
    if not "soundEnabled" in config.config:
        config.config["soundEnabled"] = True

    config.update("version", assembly_version)
Example #21
0
def switch_to_dark():
    yin = Yin(2)
    yin.start()
    config.update("theme", "dark")
    yin.join()
Example #22
0
 def enabled(self, value: bool):
     config.update(str(self) + 'Enabled', value)
Example #23
0
 def toggle_kde_fields(self):
     self.get_kde_themes()
     checked = self.ui.kde_checkbox.isChecked()
     self.ui.kde_combo_light.setEnabled(checked)
     self.ui.kde_combo_dark.setEnabled(checked)
     config.update("codeEnabled", checked)
Example #24
0
 def time_changed(self):
     # update config if time has changed
     time_light = self.ui.light_time.time().toPyTime()
     time_dark = self.ui.dark_time.time().toPyTime()
     config.update("switchToLight", time_light.strftime("%H:%M"))
     config.update("switchToDark", time_dark.strftime("%H:%M"))
Example #25
0
def write_new_settings(theme: str, dark: bool):
    """
    Changes or creates the user.js file for every profile.

    :param theme: Firefox theme id
    :param dev_theme: developer theme [dark|light]
    """

    theme_old: str = config.get("firefoxActiveTheme")
    print('Changing "{theme_old}" to "{theme}"'.format(**locals()))

    fh, target_file_path = mkstemp()

    # change the theme for every profile
    for profile, profile_path in get_profiles().items():

        # create user.js if it doesn't exist
        if not os.path.isfile(profile_path + '/user.js'):
            file = open(profile_path + '/user.js', 'w+')
            file.close()

        print('Editing config for {profile}'.format(**locals()))

        # rewrite the user.js
        with open(profile_path + '/user.js',
                  'r') as user_js, open(target_file_path, 'w') as user_cp_js:

            dev_theme: str = ''
            dark_int: int = int(dark is True)

            if dark:
                dev_theme = 'dark'
            else:
                dev_theme = 'light'

            # dont write the settings for the theme in new file,
            # they will be added later
            for line in user_js:
                if 'devtools.theme' in line:
                    pass
                elif 'ui.systemUsesDarkTheme' in line:
                    pass
                elif 'browser.in-content.dark-mode' in line:
                    pass
                else:
                    user_cp_js.write(line)

            # for devtools-sidebar
            user_cp_js.write('user_pref("devtools.theme", "{dev_theme}");'.
                             format(**locals()) + '\n')
            # for extension and websides, like darkreader or about:config
            user_cp_js.write(
                'user_pref("ui.systemUsesDarkTheme", {dark_int});'.format(
                    **locals()) + '\n')
            # additional stuff like error pages
            user_cp_js.write(
                'user_pref("browser.in-content.dark-mode", {dark});'.format(
                    **locals()) + '\n')

        os.remove(profile_path + '/user.js')
        move(target_file_path, profile_path + '/user.js')

    # The actual ui theme can only be edited via the extension.
    # This is handled with communication.py
    config.update("firefoxActiveTheme", theme)