configuration.change_theme

 1from dictionary.vars import absolute_app_path, dark_theme, server_config, light_theme
 2from time import sleep
 3import streamlit as st
 4
 5
 6class ChangeTheme:
 7    """
 8    Classe com métodos para a mudança de tema.
 9    """
10
11    def change_theme(self, theme_option: str):
12        """
13        Realiza a troca do tema com base na opção escolhida pelo usuário.
14
15        Parameters
16        ----------
17        theme_option : str
18            Tema escolhido pelo usuário.
19        """
20
21        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
22
23        if theme_option == "Escuro":
24            with open(config_archive, "w") as archive:
25                archive.write(dark_theme)
26                archive.write("\n")
27                archive.write(server_config)
28
29        elif theme_option == "Claro":
30            with open(config_archive, "w") as archive:
31                archive.write(light_theme)
32                archive.write("\n")
33                archive.write(server_config)
34
35    def main_menu(self):
36        """
37        Menu de troca de tema.
38        """
39
40        col4, col5 = st.columns(2)
41
42        with col4:
43
44            st.subheader(body=":computer: Opções")
45
46            with st.expander(label="Aparência", expanded=True):
47                selected_theme = st.radio(label="Tema", options=["Escuro", "Claro"])
48
49            theme_confirm_option = st.button(label=":white_check_mark: Confirmar opção")
50
51        if selected_theme != "" and theme_confirm_option:
52            with col5:
53                with st.spinner(text="Aguarde..."):
54                    sleep(2.5)
55                    self.change_theme(selected_theme)
56                sleep(2.5)
57                st.rerun()
class ChangeTheme:
 7class ChangeTheme:
 8    """
 9    Classe com métodos para a mudança de tema.
10    """
11
12    def change_theme(self, theme_option: str):
13        """
14        Realiza a troca do tema com base na opção escolhida pelo usuário.
15
16        Parameters
17        ----------
18        theme_option : str
19            Tema escolhido pelo usuário.
20        """
21
22        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
23
24        if theme_option == "Escuro":
25            with open(config_archive, "w") as archive:
26                archive.write(dark_theme)
27                archive.write("\n")
28                archive.write(server_config)
29
30        elif theme_option == "Claro":
31            with open(config_archive, "w") as archive:
32                archive.write(light_theme)
33                archive.write("\n")
34                archive.write(server_config)
35
36    def main_menu(self):
37        """
38        Menu de troca de tema.
39        """
40
41        col4, col5 = st.columns(2)
42
43        with col4:
44
45            st.subheader(body=":computer: Opções")
46
47            with st.expander(label="Aparência", expanded=True):
48                selected_theme = st.radio(label="Tema", options=["Escuro", "Claro"])
49
50            theme_confirm_option = st.button(label=":white_check_mark: Confirmar opção")
51
52        if selected_theme != "" and theme_confirm_option:
53            with col5:
54                with st.spinner(text="Aguarde..."):
55                    sleep(2.5)
56                    self.change_theme(selected_theme)
57                sleep(2.5)
58                st.rerun()

Classe com métodos para a mudança de tema.

def change_theme(self, theme_option: str):
12    def change_theme(self, theme_option: str):
13        """
14        Realiza a troca do tema com base na opção escolhida pelo usuário.
15
16        Parameters
17        ----------
18        theme_option : str
19            Tema escolhido pelo usuário.
20        """
21
22        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
23
24        if theme_option == "Escuro":
25            with open(config_archive, "w") as archive:
26                archive.write(dark_theme)
27                archive.write("\n")
28                archive.write(server_config)
29
30        elif theme_option == "Claro":
31            with open(config_archive, "w") as archive:
32                archive.write(light_theme)
33                archive.write("\n")
34                archive.write(server_config)

Realiza a troca do tema com base na opção escolhida pelo usuário.

Parameters
  • theme_option (str): Tema escolhido pelo usuário.
def main_menu(self):
36    def main_menu(self):
37        """
38        Menu de troca de tema.
39        """
40
41        col4, col5 = st.columns(2)
42
43        with col4:
44
45            st.subheader(body=":computer: Opções")
46
47            with st.expander(label="Aparência", expanded=True):
48                selected_theme = st.radio(label="Tema", options=["Escuro", "Claro"])
49
50            theme_confirm_option = st.button(label=":white_check_mark: Confirmar opção")
51
52        if selected_theme != "" and theme_confirm_option:
53            with col5:
54                with st.spinner(text="Aguarde..."):
55                    sleep(2.5)
56                    self.change_theme(selected_theme)
57                sleep(2.5)
58                st.rerun()

Menu de troca de tema.