configuration.change_theme

  1from dictionary.vars import (
  2    absolute_app_path,
  3    dark_theme,
  4    server_config,
  5    light_theme,
  6    fonts_dictionary
  7)
  8from screens.homepage import Home
  9from time import sleep
 10import streamlit as st
 11
 12
 13class ChangeTheme:
 14    """
 15    Classe com métodos para a mudança da aparência da aplicação,
 16    (fontes e tema).
 17    """
 18
 19    def search_theme_image(self, color_theme: str, font_option: str):
 20        """
 21        Realiza a busca da imagem demonstrativa do tema,
 22        cor e fonte selecionado pelo usuário.
 23
 24        Parameters
 25        ----------
 26        color_theme : str
 27            O esquema de cores selecionado.
 28        font_option : str
 29            A fonte selecionada.
 30
 31        Returns
 32        -------
 33        theme_image : str
 34            O caminho da imagem do tema.
 35        """
 36        color_dict = {
 37            "Escuro": "dark",
 38            "Claro": "light"
 39        }
 40        font_option = font_option.replace(" ", "_")
 41
 42        theme_image = "{}/reference/images/themes/{}/{}_{}.png".format(
 43            absolute_app_path, color_dict[color_theme],
 44            color_dict[color_theme],
 45            font_option)
 46        return theme_image
 47
 48    def change_theme(self, theme_option: str, font_option: str):
 49        """
 50        Realiza a troca do tema e fonte da aplicação.
 51
 52        Parameters
 53        ----------
 54        theme_option : str
 55            O tema selecionado pelo usuário.
 56        font_option : str
 57            A fonte selecionada pelo usuário.
 58        """
 59        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
 60        style_archive: str = absolute_app_path + "/dictionary/style.py"
 61
 62        if theme_option == "Escuro":
 63            with open(config_archive, "w") as archive:
 64                archive.write(dark_theme)
 65                if font_option == "Selecione uma opção":
 66                    pass
 67                else:
 68                    archive.write("\n")
 69                    archive.write('font = "{}"'.format(font_option))
 70                archive.write("\n")
 71                archive.write(server_config)
 72
 73        elif theme_option == "Claro":
 74            with open(config_archive, "w") as archive:
 75                archive.write(light_theme)
 76                if font_option == "Selecione uma opção":
 77                    pass
 78                else:
 79                    archive.write("\n")
 80                    archive.write('font = "{}"'.format(font_option))
 81                archive.write("\n")
 82                archive.write(server_config)
 83
 84        if font_option != "Selecione uma opção":
 85            font_archive = fonts_dictionary[font_option]
 86            with open(style_archive, "w") as new_style_archive:
 87                new_style_archive.write(
 88                    'system_font = "{}"'.format(font_archive)
 89                )
 90
 91    def main_menu(self):
 92        """
 93        Menu principal.
 94        """
 95        themes_options = {
 96            "Claro": ["sans serif", "serif", "monospace"],
 97            "Escuro": ["sans serif", "serif", "monospace"]
 98        }
 99
100        col4, col5, col6 = st.columns(3)
101
102        with col4:
103            st.subheader(body=":page_with_curl: Opções")
104            with st.expander(label="Aparência", expanded=True):
105                selected_theme = st.radio(
106                    label="Tema", options=themes_options.keys())
107                font_option = st.selectbox(
108                    label="Fonte", options=themes_options[selected_theme])
109            theme_confirm_option = st.checkbox(label="Confirmar opção")
110
111        if theme_confirm_option:
112            with col5:
113                with st.spinner(text="Aguarde..."):
114                    sleep(1.5)
115                theme_image = self.search_theme_image(
116                    selected_theme, font_option)
117                st.subheader(body=":camera: Prévia do Tema")
118                with st.expander(label="Visualização", expanded=True):
119                    st.image(theme_image)
120
121            with col6:
122                with st.spinner(text="Aguarde..."):
123                    sleep(1.5)
124                st.subheader(body=":white_check_mark: Confirmação")
125                with st.expander(label="Votação", expanded=True):
126                    st.write("Confirmar a mudança de tema?")
127                    selected_option = st.radio(
128                        label="Opções", options=["Sim", "Não"])
129
130                confirm_vote = st.button(
131                    label=":floppy_disk: Confirmar mudança de tema")
132
133                if confirm_vote:
134                    if selected_option == "Sim":
135                        self.change_theme(selected_theme, font_option)
136                        sleep(1.5)
137                        st.rerun()
138                        sleep(1.5)
139                        Home().main_menu()
140                    elif selected_option == "Não":
141                        pass
class ChangeTheme:
 14class ChangeTheme:
 15    """
 16    Classe com métodos para a mudança da aparência da aplicação,
 17    (fontes e tema).
 18    """
 19
 20    def search_theme_image(self, color_theme: str, font_option: str):
 21        """
 22        Realiza a busca da imagem demonstrativa do tema,
 23        cor e fonte selecionado pelo usuário.
 24
 25        Parameters
 26        ----------
 27        color_theme : str
 28            O esquema de cores selecionado.
 29        font_option : str
 30            A fonte selecionada.
 31
 32        Returns
 33        -------
 34        theme_image : str
 35            O caminho da imagem do tema.
 36        """
 37        color_dict = {
 38            "Escuro": "dark",
 39            "Claro": "light"
 40        }
 41        font_option = font_option.replace(" ", "_")
 42
 43        theme_image = "{}/reference/images/themes/{}/{}_{}.png".format(
 44            absolute_app_path, color_dict[color_theme],
 45            color_dict[color_theme],
 46            font_option)
 47        return theme_image
 48
 49    def change_theme(self, theme_option: str, font_option: str):
 50        """
 51        Realiza a troca do tema e fonte da aplicação.
 52
 53        Parameters
 54        ----------
 55        theme_option : str
 56            O tema selecionado pelo usuário.
 57        font_option : str
 58            A fonte selecionada pelo usuário.
 59        """
 60        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
 61        style_archive: str = absolute_app_path + "/dictionary/style.py"
 62
 63        if theme_option == "Escuro":
 64            with open(config_archive, "w") as archive:
 65                archive.write(dark_theme)
 66                if font_option == "Selecione uma opção":
 67                    pass
 68                else:
 69                    archive.write("\n")
 70                    archive.write('font = "{}"'.format(font_option))
 71                archive.write("\n")
 72                archive.write(server_config)
 73
 74        elif theme_option == "Claro":
 75            with open(config_archive, "w") as archive:
 76                archive.write(light_theme)
 77                if font_option == "Selecione uma opção":
 78                    pass
 79                else:
 80                    archive.write("\n")
 81                    archive.write('font = "{}"'.format(font_option))
 82                archive.write("\n")
 83                archive.write(server_config)
 84
 85        if font_option != "Selecione uma opção":
 86            font_archive = fonts_dictionary[font_option]
 87            with open(style_archive, "w") as new_style_archive:
 88                new_style_archive.write(
 89                    'system_font = "{}"'.format(font_archive)
 90                )
 91
 92    def main_menu(self):
 93        """
 94        Menu principal.
 95        """
 96        themes_options = {
 97            "Claro": ["sans serif", "serif", "monospace"],
 98            "Escuro": ["sans serif", "serif", "monospace"]
 99        }
100
101        col4, col5, col6 = st.columns(3)
102
103        with col4:
104            st.subheader(body=":page_with_curl: Opções")
105            with st.expander(label="Aparência", expanded=True):
106                selected_theme = st.radio(
107                    label="Tema", options=themes_options.keys())
108                font_option = st.selectbox(
109                    label="Fonte", options=themes_options[selected_theme])
110            theme_confirm_option = st.checkbox(label="Confirmar opção")
111
112        if theme_confirm_option:
113            with col5:
114                with st.spinner(text="Aguarde..."):
115                    sleep(1.5)
116                theme_image = self.search_theme_image(
117                    selected_theme, font_option)
118                st.subheader(body=":camera: Prévia do Tema")
119                with st.expander(label="Visualização", expanded=True):
120                    st.image(theme_image)
121
122            with col6:
123                with st.spinner(text="Aguarde..."):
124                    sleep(1.5)
125                st.subheader(body=":white_check_mark: Confirmação")
126                with st.expander(label="Votação", expanded=True):
127                    st.write("Confirmar a mudança de tema?")
128                    selected_option = st.radio(
129                        label="Opções", options=["Sim", "Não"])
130
131                confirm_vote = st.button(
132                    label=":floppy_disk: Confirmar mudança de tema")
133
134                if confirm_vote:
135                    if selected_option == "Sim":
136                        self.change_theme(selected_theme, font_option)
137                        sleep(1.5)
138                        st.rerun()
139                        sleep(1.5)
140                        Home().main_menu()
141                    elif selected_option == "Não":
142                        pass

Classe com métodos para a mudança da aparência da aplicação, (fontes e tema).

def search_theme_image(self, color_theme: str, font_option: str):
20    def search_theme_image(self, color_theme: str, font_option: str):
21        """
22        Realiza a busca da imagem demonstrativa do tema,
23        cor e fonte selecionado pelo usuário.
24
25        Parameters
26        ----------
27        color_theme : str
28            O esquema de cores selecionado.
29        font_option : str
30            A fonte selecionada.
31
32        Returns
33        -------
34        theme_image : str
35            O caminho da imagem do tema.
36        """
37        color_dict = {
38            "Escuro": "dark",
39            "Claro": "light"
40        }
41        font_option = font_option.replace(" ", "_")
42
43        theme_image = "{}/reference/images/themes/{}/{}_{}.png".format(
44            absolute_app_path, color_dict[color_theme],
45            color_dict[color_theme],
46            font_option)
47        return theme_image

Realiza a busca da imagem demonstrativa do tema, cor e fonte selecionado pelo usuário.

Parameters
  • color_theme (str): O esquema de cores selecionado.
  • font_option (str): A fonte selecionada.
Returns
  • theme_image (str): O caminho da imagem do tema.
def change_theme(self, theme_option: str, font_option: str):
49    def change_theme(self, theme_option: str, font_option: str):
50        """
51        Realiza a troca do tema e fonte da aplicação.
52
53        Parameters
54        ----------
55        theme_option : str
56            O tema selecionado pelo usuário.
57        font_option : str
58            A fonte selecionada pelo usuário.
59        """
60        config_archive: str = absolute_app_path + "/.streamlit/config.toml"
61        style_archive: str = absolute_app_path + "/dictionary/style.py"
62
63        if theme_option == "Escuro":
64            with open(config_archive, "w") as archive:
65                archive.write(dark_theme)
66                if font_option == "Selecione uma opção":
67                    pass
68                else:
69                    archive.write("\n")
70                    archive.write('font = "{}"'.format(font_option))
71                archive.write("\n")
72                archive.write(server_config)
73
74        elif theme_option == "Claro":
75            with open(config_archive, "w") as archive:
76                archive.write(light_theme)
77                if font_option == "Selecione uma opção":
78                    pass
79                else:
80                    archive.write("\n")
81                    archive.write('font = "{}"'.format(font_option))
82                archive.write("\n")
83                archive.write(server_config)
84
85        if font_option != "Selecione uma opção":
86            font_archive = fonts_dictionary[font_option]
87            with open(style_archive, "w") as new_style_archive:
88                new_style_archive.write(
89                    'system_font = "{}"'.format(font_archive)
90                )

Realiza a troca do tema e fonte da aplicação.

Parameters
  • theme_option (str): O tema selecionado pelo usuário.
  • font_option (str): A fonte selecionada pelo usuário.
def main_menu(self):
 92    def main_menu(self):
 93        """
 94        Menu principal.
 95        """
 96        themes_options = {
 97            "Claro": ["sans serif", "serif", "monospace"],
 98            "Escuro": ["sans serif", "serif", "monospace"]
 99        }
100
101        col4, col5, col6 = st.columns(3)
102
103        with col4:
104            st.subheader(body=":page_with_curl: Opções")
105            with st.expander(label="Aparência", expanded=True):
106                selected_theme = st.radio(
107                    label="Tema", options=themes_options.keys())
108                font_option = st.selectbox(
109                    label="Fonte", options=themes_options[selected_theme])
110            theme_confirm_option = st.checkbox(label="Confirmar opção")
111
112        if theme_confirm_option:
113            with col5:
114                with st.spinner(text="Aguarde..."):
115                    sleep(1.5)
116                theme_image = self.search_theme_image(
117                    selected_theme, font_option)
118                st.subheader(body=":camera: Prévia do Tema")
119                with st.expander(label="Visualização", expanded=True):
120                    st.image(theme_image)
121
122            with col6:
123                with st.spinner(text="Aguarde..."):
124                    sleep(1.5)
125                st.subheader(body=":white_check_mark: Confirmação")
126                with st.expander(label="Votação", expanded=True):
127                    st.write("Confirmar a mudança de tema?")
128                    selected_option = st.radio(
129                        label="Opções", options=["Sim", "Não"])
130
131                confirm_vote = st.button(
132                    label=":floppy_disk: Confirmar mudança de tema")
133
134                if confirm_vote:
135                    if selected_option == "Sim":
136                        self.change_theme(selected_theme, font_option)
137                        sleep(1.5)
138                        st.rerun()
139                        sleep(1.5)
140                        Home().main_menu()
141                    elif selected_option == "Não":
142                        pass

Menu principal.