• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

guiBasic

mag

Active member
3rd Party Module Dev
3rd Party Tool Dev
Joined
Mar 5, 2018
Messages
261
ezgif-5-09c2c4b2b0.gif


Hi,
For those who need GUI you can try guiBasic. GuiBasic previously known as MyGui was created by Christopher Challenger in 2012. It was converted from MonkeyX to CerberusX by Memzen in 2019. Now, I add support for regular CerberusX font.

You can download this version here on GitHub.
 
This looks great. Seems to work well on Windows but I am having trouble with the file dialogs on Linux and Mac. On both the directory separator is / not \ so I changed all occurences of \ to / in the gbFileOperations file. The problem I am seeing is that when you first call a file load the RenewList function lists the directories and files(well those with the specified extension - would be great to see all files and I need to look at this further). If I change down a dir the files are listed however if I change up a dir the directory/file list remains blank. It is as though the RenewList function is not working. The RenewList calls LoadDir from the os module. I inserted some code to check what was happening

Function RenewList() Print "Enter Renew List: " + Gui.FileOperations.File_CurrentPath Local FileList:String[] = LoadDir(Gui.FileOperations.File_CurrentPath) For Local temp:String = Eachin FileList Print temp next
The first print shows that the correct directory is being accessed. Nothing is printed after the second "Print temp". The second print does work the first time RenewList is called. Does the LoadDir function need resetting? Is anyone using this module on Linux or Mac?
Thanks for any help.
I did see at the top of the os module the word deprecating and to use brl.filesystem and brl.filepath instead however neither has a CurrentDir function used in gbFileOperations.
 
I did see at the top of the os module the word deprecating and to use brl.filesystem and brl.filepath instead however neither has a CurrentDir function used in gbFileOperations.
Use brl.process, it has a CurrentDir function. Don't ask me why it is in that module. I simply don't know.
 
Well it would have paid me to search a little further. There is a brl.requesters module that seems to do what the gbFileOperations would do so I should not need to use that part of guiBasic at all - do you ever have one of those doh! moments?
:rolleyes:
 
Plenty.
Anyway, your problem withLoadDir still exists? If yes, could you please create a small example and attach it to a bug post so we can test it easily?
 
Thanks for the reply. I tried adding the brl.process to the gbFileOperations and removing reference to module os. Project ten compiled OK however the same problem persisted witht the RenewList working the first time but not thereafter. In the end I did not pursue this further and used the RequestFile function from brl.requesters. This worked fine so no need to chase the problem any further.
 
I guess I have to come up with something myself. Nevermind.if the problem is in the gui module you are using, then you are on your own anyway. I will just check if LoadDir has any problem.
 
Tried on Mint Linux.

Also tried on Win11 64. Strange behavour there too. First time through the list is printed multiple times (lost count after 25). After "UP" key is pressed the directory changes but contents again listed multiple times and the "<Dir>" tag is not added to directories. System too fast?? and picking up spurious signals?
Anyway as I noted this is not a game breaker as the brl.requesters mod works fine. Perhaps LoadDir does not like being called multiple times?

Cerberus:
Import brl.filesystem
Import brl.filepath
Import brl.process
Import mojo

Function Main:Int()
    New MyGame()
    Return 0
End function

Class MyGame Extends App
    Field curDir:= CurrentDir()

    Method OnCreate()

    End Method

 

    Method OnUpdate()
        Local dirList:String[] = LoadDir(curDir)
        For Local item:=Eachin dirList
            If FileType(item) = FILETYPE_DIR
                Print(item + " <Dir>")
            Else
                Print(item)
            End If
        Next

        'now try changing directory up

        If KeyHit(KEY_UP)
            Local L:String[] = curDir.Split("/")
                If L.Length < 2 Then Return 0
                Local NewPath:String
                For Local i = 0 To L.Length - 2
                    If NewPath = "" Then
                        NewPath = L[i]
                    Else
                        NewPath = NewPath + "/" + L[i]
                    End If
                Next
                curDir = NewPath
                Print curDir
        End if
    End Method

End Class

Ok. Figured out why the multiple listings. It’s because the siting is in OnUpdate and gets called every frame?. I’ll try to look at this again later.
 
Last edited:
It’s because the siting is in OnUpdate and gets called every frame
Yes, it is called basically at the set framerate. See mojo.app.SetUpdateRate to see its effects. Default is set to 60 frames per second.
 
Fixed the code to list dir once when changed. Note that the check on directory still fails after the first time RenewList is called - that is the <Dir> is not added to the listing. Apart from that seems that LoadDir is working OK on windows - I have yet to check this code on Mac or Linux.

(The extra blank lines in the code seem to get inserted when I change the pasted text with the code blocks from the menu)





Code:
Import brl.filesystem

Import brl.filepath

Import brl.process

Import mojo



Function Main:Int()

    New MyGame()

    Return 0

End function



Class MyGame Extends App



    Field curDir:= CurrentDir()

    Field dirList:String[]

    Field dirChanged:Bool



    Method OnCreate()

        RenewList()

        dirChanged=False

    End Method



    Method OnUpdate()

        If dirChanged

            RenewList()

            dirChanged = False

        End If

       



        'now try changing directory up



        If KeyHit(KEY_UP)

          Local L:String[] = curDir.Split("/")

                If L.Length < 2 Then Return 0

                Local NewPath:String

                For Local i = 0 To L.Length - 2

                    If NewPath = "" Then

                        NewPath = L[i]

                    Else

                        NewPath = NewPath + "/" + L[i]

                    End If

                Next



                curDir = NewPath

                dirChanged = True

                Print curDir

        End if

    End Method



    Method RenewList()

        dirList = LoadDir(curDir)

        For Local item:=Eachin dirList

            If FileType(item) = FILETYPE_DIR

                Print(item + " <Dir>")

            Else

                Print(item)

            End If

        Next

    End Method



End Class
 
I'm not following what this code is supposed to do more than it should read directory.

I tried it on the latest macos tonight. This is the output: (It contines two steps more (username and the directly "users")

1.png


2.png
 
if this is correct and you want the results for linux to I might have the possibility to do so tomorrow!
 
This was just a test for the LoadDir command for Mike. Your Mac test and, I have now tried on Linux, show the same result. The first time RenewList is called the printout is correct. When you change up a directory only the current directory path is printed. The current directory contents should also be printed but are not. On Windows the directory contents are printed each time however the "<Dir>" tag is not added to directories after going up a directory. I just created this test to show Mike what I thought was an anomaly between platforms. Unless my coding is wrong there is something strange happening woth the LoadDir command on or the FileType command. As I noted not a big deal - just wanted to save some investigative work by Mike. Thanks for testing.
 
Thanks @matty47 for the example. I will check myself on these 2 targets. Just create a new virtual machine for Linux and update my Mac.
 
Its a bug. Definitely.

Please replace the LoadDir function in modules/brl/filesystem.cxs with this code:

Cerberus:
Function LoadDir:String[]( path:String,recursive:Bool=False,hidden:Bool=False )
    Local dirs:=New StringDeque
    Local files:=New StringStack

    If Not path.EndsWith( "/" ) path+="/"
#If HOST<>"winnt"   
    If Not ( path.StartsWith( "/" ) Or path.StartsWith( "." )) Then path="/"+path
#End
    dirs.PushLast ""
    
    While Not dirs.IsEmpty()       

        Local dir:String=dirs.PopFirst()
        For Local f:String=Eachin _LoadDir( path+dir )   
            If Not hidden And f.StartsWith(".") Continue
            
            Local p:=dir+f
            
            files.Push p
            
            If recursive And FileType( path+p )=FILETYPE_DIR dirs.PushLast p+"/"
        Next
    Wend

    Return files.ToArray()
End
 
Thanks Mike. That worked fine. Directories and files are now listed as you traverse up. One problem remains in that after the first time the FileType() command is not returning the correct filetype. Added a bit of code to illustrate. On traversing up the FileType command returns 0 whereas on the first run it returned 1 or 2. (Hope this is not putting too much strain on you)
Code:
Import brl.filesystem
Import brl.filepath
Import brl.process
Import mojo

Function Main:Int()
    New MyGame()
    Return 0
End function



Class MyGame Extends App

    Field curDir:= CurrentDir()
    Field dirList:String[]
    Field dirChanged:Bool

    Method OnCreate()
        RenewList()
        dirChanged=False
    End Method

    Method OnUpdate()
        If dirChanged
            RenewList()
            dirChanged = False
        End If   



        'now try changing directory up

        If KeyHit(KEY_UP)
          Local L:String[] = curDir.Split("/")
                If L.Length < 2 Then Return 0
                Local NewPath:String
                For Local i = 0 To L.Length - 2
                    If NewPath = "" Then
                        NewPath = L[i]
                    Else
                        NewPath = NewPath + "/" + L[i]
                    End If
                Next

                curDir = NewPath
                dirChanged = True
                Print curDir
        End if
    End Method

    Method RenewList()
        dirList = LoadDir(curDir)
        For Local item:=Eachin dirList
        
            Print (FileType(item))        'added this**********
            
            If FileType(item) = FILETYPE_DIR
                Print(item + " <Dir>")
            Else
                Print(item)
            End If
        Next
    End Method
End Class
 
Ok, now that I have slept a night over it, I have to take my statement "It's a bug" back.

1) LoadDir was just working fine. The problem is your code logic. You split your path with the Slash. But on Linux and Macos, this is the first character in your path. When you reconstruct your path, you are not adding that first slash in the front. That is why LoadDir was not working then. What I had added to LoadDir was a workaround to cover such invalid path. I will remove that.

2) With FileType you have to either specify the full path to a file, or ChangeDir to that path upfront. When you initially asked for Filetype, the app is in its directory. So FileType was able to find the files/directories.
Then you traverse the path upwards, but just in code logic. Your CurrentDir is still the app directory and there it can't find files/directories with these item names. That is the reason for FileType returning 0.
 
Thanks for the clarifications and I am glad that it is my bad coding not a bug. Thanks for your hard work!!
 
No problem. Sometimes it’s not obvious right away. And of course, like any software, there can be still bugs in CX
 
Whoever is maintaining guiBasic now, can you update it to support scaling the gui components for higher resolutions?
 
Back
Top Bottom