B4J Question Best way to reinitialize CSS

ThRuST

Well-Known Member
Licensed User
Longtime User
What's the preffered way to reinitialize the application design when changing CSS file, without the need of restarting the application. I use multiple CSS designs in my project. Btw my app does not use CSSutils since it depends on multiple panes that uses separate CSS files if that makes sense! I tried this without luck

B4X:
Sub ReinitCSS
    Main.MainForm.Stylesheets.Add(File.GetUri(DesignPath, "theme.css"))
End Sub
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
From a quick test, the stylesheet takes effect when you change it, how are you changing the stylesheet.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Well I change it like in the Sub ReinitCSS, as this is used at startup. Then I tried to call it again after a new theme.css was loaded but that didn't affect the application until I restarted it.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
CSSutils might be able to reload a CSS file to reinitialize everything. I'll search the forum.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I presume you are talking about Athena. The version (0.51) I have does not have a ReinitCSS method. What does it do?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
CSSUtils won't help you with this.
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Basically it's when the user loads a new design in the manager. Here's a part of the relevant code

B4X:
If TabPaneManager.SelectedItem.Text == "Design" Then
           
        MP3play_Dialog.Stop
        MP3play_Dialog.Position = 0
        ' Play sound
        PlaySound.DialogSnd
           
        Dim res As Int = fx.Msgbox2(MainForm, "Do you want to install" & CRLF & lvDesign.SelectedItem & "?" & CRLF &  CRLF & "Warning! The current installed module will be overwritten.", "Athena", "Install", "", "Cancel", fx.MSGBOX_WARNING)
   
        If res = fx.DialogResponse.POSITIVE Then
           
            ' Copy unzipped files to application directory
            File.Copy(Inititialization.TmpFolder, "design.dat", Inititialization.DesignPath , "Design.dat")
            File.Copy(Inititialization.TmpFolder, "design.png", Inititialization.DesignPath , "Design.png")
            File.Copy(Inititialization.TmpFolder, "panel.png", Inititialization.DesignPath , "Panel.png")
            File.Copy(Inititialization.TmpFolder, "panel_docs.png", Inititialization.DesignPath , "Panel_Docs.png")
            File.Copy(Inititialization.TmpFolder, "panel_manager.png", Inititialization.DesignPath , "Panel_Manager.png")
            File.Copy(Inititialization.TmpFolder, "panel_menu.png", Inititialization.DesignPath , "Panel_Menu.png")
            File.Copy(Inititialization.TmpFolder, "theme.css", Inititialization.DesignPath , "Theme.css")
           
            Sleep(5000)
            Inititialization.InitSkinImage
            Inititialization.LoadSkinInfo
           
            ' Reset autotype
            AutoType.InitAutoType
           
            'SQLiteUtils.Init_SQLiteCM
            ' Display info message
            FXnotify.ShowNotification3("Athena", "Successfully installed", FXnotify.ICON_INFORMATION, MainForm, "CENTER", 3000)
           
            ' Reinitialize CSS
            'Inititialization.ReinitCSS
           
            Return
           
        End If
   
        If res = fx.DialogResponse.CANCEL Then
            ' Cancel
           
            MP3play_Click.Stop
            MP3play_Click.Position = 0
            ' Play sound
            PlaySound.ClickSnd
           
        End If
   
        If res = fx.DialogResponse.NEGATIVE Then
           
            MP3play_Click.Stop
            MP3play_Click.Position = 0
            ' Play sound
            PlaySound.ClickSnd
           
        End If
           
    End If
   
   
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
So you are copying new files over existing files, in this case the app doesn't know that the CSS file has changed so can't do anything about it.

If theme.css is Still attached to the MainForm try removing it and adding it again:

B4X:
Dim Pos As Int = MainForm.Stylesheets.IndexOf(File.GetUri(DesignPath,"theme.css"))
    If  Pos > -1 Then
        MainForm.Stylesheets.RemoveAt(Pos)
    End If
        MainForm.Stylesheets.Add(File.GetUri(DesignPath,"theme.css"))
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Try it just after the filecopy of the theme.css
 
Upvote 0

ThRuST

Well-Known Member
Licensed User
Longtime User
Hey that worked. I need to add some more changes then I'll drop you a message. Thanks Steve :)
 
Upvote 0
Top