This is exactly the same question for ChatGPT4:
Me : show me a simple example of purebasic GUI app
ChatGPT (4):
Here's a simple example of creating a graphical user interface (GUI) application in PureBasic. This example demonstrates how to create a window that lists file properties within a specified directory. It makes use of several GUI elements such as windows, text gadgets, and list icon gadgets to display the file information. The application also includes an event loop to handle user interactions, such as closing the window.
Code: Select all
; Define the structure for file information
Structure FILEITEM
Name.s
Attributes.i
Size.q
DateCreated.i
DateAccessed.i
DateModified.i
EndStructure
; Constants to identify the window and controls
Enumeration
#WindowFiles
EndEnumeration
Enumeration
#Folder
#Files
EndEnumeration
; Define a list of files using the structure
NewList Files.FILEITEM()
; Define variables for GUI event handling
Define .s Access, Attrib, Create, Folder, Modify, Msg, Num, Size
Define .l Result, Flags
Define .l Event, EventWindow, EventGadget, EventType, EventMenu
; Get the home directory for the logged on user
Folder = GetHomeDirectory()
; Open the directory to enumerate its contents
Result = ExamineDirectory(0, Folder, "*.*")
; Begin enumeration of entries if successful
If Result
While NextDirectoryEntry(0)
If DirectoryEntryType(0) = #PB_DirectoryEntry_File
AddElement(Files())
Files()\Name = DirectoryEntryName(0)
Files()\Size = DirectoryEntrySize(0)
Files()\Attributes = DirectoryEntryAttributes(0)
Files()\DateCreated = DirectoryEntryDate(0, #PB_Date_Created)
Files()\DateAccessed = DirectoryEntryDate(0, #PB_Date_Accessed)
Files()\DateModified = DirectoryEntryDate(0, #PB_Date_Modified)
EndIf
Wend
FinishDirectory(0)
EndIf
; Sort the list into ascending alphabetical order of file name
SortStructuredList(Files(), #PB_Sort_Ascending, OffsetOf(FILEITEM\Name), #PB_String)
; Define flags for the window attributes
Flags = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar
; Open a GUI window
OpenWindow(#WindowFiles, 50, 50, 450, 400, "File Properties", Flags)
; Create a text gadget to show the name of the folder
TextGadget(#Folder, 5, 40, 440, 25, Folder)
; Create a list icon gadget to hold the file list and properties
ListIconGadget(#Files, 5, 70, 440, 326, "#", 35)
; Add columns to the ListIconGadget for each property
AddGadgetColumn(#Files, 1, "Name", 200)
AddGadgetColumn(#Files, 2, "Created", 100)
AddGadgetColumn(#Files, 3, "Accessed", 100)
AddGadgetColumn(#Files, 4, "Modified", 100)
AddGadgetColumn(#Files, 5, "Attributes", 150)
AddGadgetColumn(#Files, 6, "Size", 100)
; Load the files into the list view
ForEach Files()
Num = StrU(ListIndex(Files()) + 1)
Create = FormatDate("%dd/%mm/%yyyy", Files()\DateCreated)
Access = FormatDate("%dd/%mm/%yyyy", Files()\DateAccessed)
Modify = FormatDate("%dd/%mm/%yyyy", Files()\DateModified)
Size = StrU(Files()\Size)
Attrib = StrU(Files()\Attributes)
Msg = Num + Chr(10) + Files()\Name + Chr(10) + Create + Chr(10) + Access + Chr(10) + Modify + Chr(10) + Attrib + Chr(10) + Size
AddGadgetItem(#Files, -1, Msg)
Next Files()
; Event loop to handle user interactions
Repeat
Event = WaitWindowEvent()
EventWindow = EventWindow()
EventGadget = EventGadget()
EventType = EventType()
Select Event
Case #PB_Event_Gadget
If EventGadget = #Folder Or EventGadget = #Files
; Handle gadget events here
EndIf
Case #PB_Event_CloseWindow
If EventWindow = #WindowFiles
CloseWindow(#WindowFiles)
Break
EndIf
EndSelect
ForEver
This code sets up a basic GUI application structure, defining a window with gadgets to display a list of file properties such as name, size, and dates related to creation, access, and modification. It demonstrates how to use structures, lists, and various GUI elements in PureBasic to create an interactive application.
=====================================================================================================================
Extra info : I have created a GPT with the Purebasic manual in PDF and the following instructions:
Code: Select all
Purebasic Code Navigator is an expert in Purebasic programming and Azure AD, offering technical assistance with a focus on correct Purebasic syntax and Azure AD support. It provides guidance on Purebasic code structure and syntax, such as using '.s' for string-returning procedures, and detailed advice on Azure AD. The GPT adopts a professional, technical approach, using appropriate jargon. When users request code examples, it always proposes Purebasic code, drawing from the official Purebasic website (https://www.purebasic.fr/english/) and its extensive knowledge source, including a comprehensive Purebasic guide. This ensures that the provided code examples are relevant and accurate. The GPT aims to resolve complex queries with precise and relevant information.