PB Form 2 IceDesign

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

PB Form 2 IceDesign

Post by ChrisR »

Export an Interface from a Purebasic source (*.pbf, *.pb) and convert it To IceDesign format (*.icef)
This is done at Runtime (see how To use below) by enumerating all PB Window And Object And building the Container-Child hierarchy.
The Attributes, Constants,... are then retrieved (See Inventories below)
And the List is then saved, Window by Window, to IceDesign format (*.icef)

You can now Design your PB Interface in IceDesign :)

Inventories:
  • The Window(s) are recovered with their Sizes, Titles, BackColor, Constants and a Flag If there is a Menu.
  • The Gadget(s) are recovered with their Positions And Sizes.
  • The following attributes are retrieved:
  • The Text of Buttons, CheckBox,... Minimum, Maximum, InnerWidth, InnerHeight, ColumnWidth, ScrollStep And PageLength
  • Fonts, FrontColor, BackColor And ToolTip
  • Status Disabled, Hidden
  • And a large part of the Constants. See the List in the source file.
  • ToolBar, StatusBar And Images are Not recovered.
  • The Splitter is listed to browse the hierarchy. As it is Not supported by IceDesign, it is then removed and both child gadgets inherit the splitter's level and parent.

How To use:
  • Include PBForm2IceDesign.pbi at the Beginning of your Source Code:
    XIncludeFile "PBForm2IceDesign.pbi"
  • After loading the Window(s) With Their Gadgets and Before the Event Loop, Call the Function:
    PBForm2IceDesign() Or PBForm2IceDesign(#Window)
  • Compile/Run (F5)
  • Optional, Customize your IceDesign Form With the Following Constants:
    • #UseShortNames = #True ; #True: Use Short Name for Controls (ex: #Btn) | #False: Use Long Name for Controls (ex: #Button)
    • #RenameControlNames = #True ; Auto Rename the Controls Name Using the Caption Name. For Button, CheckBox and Option (ex: #Btn_CaptionName)
    • #SetHiddenFlag = #False ; #False: No Gadgets are hidden | #True: it uses the same status (0/1) as in your Window
    • #SetDisabledFlag = #False ; #False: No Gadgets are Disabled | #True: it uses the same status (0/1) as in your Window

Source Example:

Code: Select all

EnableExplicit

XIncludeFile "PBForm2IceDesign.pbi"   ; <== Include PBForm2IceDesign.pbi source code
 
Enumeration Window
  #Window_0
EndEnumeration

Enumeration Gadgets
  #Button_1
EndEnumeration

Procedure Open_Window_0(X = 0, Y = 0, Width = 240, Height = 90)
  If OpenWindow(#Window_0, X, Y, Width, Height, "Title", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(#Button_1, 20, 20, 200, 50, "Button_1")
  EndIf
EndProcedure

Open_Window_0()
PBForm2IceDesign()     ; <== Call the function PBForm2IceDesign() After Loading the Window(s) and Gadget(s) and Before the Event Loop

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow

I was able to get the IceDesign interface saved in its own format 8)

Image


PBForm2IceDesign.pbi source is available in IceDesign Github
Copy-Paste Raw PBForm2IceDesign.pbi
.
Last edited by ChrisR on Mon May 23, 2022 3:30 pm, edited 1 time in total.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: PB Form 2 IceDesign

Post by Bitblazer »

Great work, thanks :D
webpage - discord chat links -> purebasic GPT4All
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB Form 2 IceDesign

Post by ChrisR »

Thanks Bitblazer :)

For information, I preferred to do it at Runtime rather than reading the PB source to be able to get as much info as possible.
It would be difficult to get the positions when they are based on variables, as in this example:

Code: Select all

ButtonGadget(#Button,     10, y, DesktopScaledX(200), ReqHeight_Button,   "Button")   : y + ReqHeight_Button
CheckBoxGadget(#CheckBox, 10, y + 3, DesktopScaledX(200), ReqHeight_Checkbox, "CheckBox") : y + ReqHeight_Checkbox
ShadowStorm
Enthusiast
Enthusiast
Posts: 237
Joined: Tue Feb 14, 2017 12:07 pm

Re: PB Form 2 IceDesign

Post by ShadowStorm »

Hello:

[20 :10 :20] [COMPILER] Ligne 239: Fichier introuvable: Save_JSON.pbi).
I am French, I do not speak English.
My apologies for the mistakes.

I have sometimes problems of expression
I am sometimes quite clumsy, please excuse me and let me know.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB Form 2 IceDesign

Post by ChrisR »

Hi Shadow,
Oops, I forgot to comment the line before publishing :oops:
You can put the line 239 in comment.

Code: Select all

;XIncludeFile "Save_JSON.pbi"

The module is optional, to arrange the fields and just for aesthetic purposes.
Otherwise, you can put Little John's module next to it: Save JSON data with object members well-arranged
I updated it on Github and on Gumroad, with the line in comment.
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB Form 2 IceDesign

Post by ChrisR »

I answered without testing for the line in comment, sorry :oops:
So the error was further, on: CompilerIf Defined(JSave::Save, #PB_Procedure), module not found.

It's fixed now and in addition, fonts are now supported in PBForm2IceDesign.pbi
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB Form 2 IceDesign

Post by ChrisR »

Typos corrections, some extracted constants were badly written with double bracket. ex:
Constants = ReplaceString(Constants, "String_ReadOnly", "String_ReadOnly(x))", #PB_String_NoCase)
Constants = ReplaceString(Constants, "Text_Border", "Text_Border(x))", #PB_String_NoCase)
==>
Constants = ReplaceString(Constants, "String_ReadOnly", "String_ReadOnly(x)", #PB_String_NoCase)
Constants = ReplaceString(Constants, "Text_Border", "Text_Border(x)", #PB_String_NoCase)
it was not blocking when opening or importing the form in IceDesign, but with errors then in preview when compiling the code.
Thanks Marcus for reporting the bug, this afternoon.
Same link on 1st post.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PB Form 2 IceDesign

Post by Caronte3D »

Hi, ChrisR, first time using this...

PBForm2IceDesign do a great job, but is a pain to go throug all the code an change all the gadget variables, because none is the same as the original.

Could be possible to generate an include with the same variables, gadgetnames, etc.. so it directly work without code modification?
User avatar
ChrisR
Addict
Addict
Posts: 1127
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: PB Form 2 IceDesign

Post by ChrisR »

Hi Caronte3D,
This is done at runtime by enumerating all PB objects and not by reading the source.
I have the gadget number at that time to find the different attributes but unfortunately I have no way to get their constant or variable names.
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PB Form 2 IceDesign

Post by Caronte3D »

I understand... :cry:
Maybe a mix of read the source code and enumerate at runtime to know what is for what... I don't know 🤷‍♂️
Nice candidate for your ToDo list :wink:
Post Reply