Compile And Run : Replace a Linux terminal or Geany with a Gui tool

User projects written in or related to FreeBASIC.
Post Reply
enform
Posts: 185
Joined: Apr 24, 2011 12:57
Location: France

Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by enform »

Hello ,
I have the pleasure to propose this tool that replaces Geany or a terminal for compilation and launching binaries in my Xubuntu .

The tool has been coded with window9.bi , it works like in FbEdit with :

the choice of 1 or more fbc stored in a combo ( for Linux only 1 fbc AFAIK ) .
the choice of several command lines in a combo ,
the choice of the bas file to compile and you can store it in a combo
these commands and file names are stored in a file ini.txt . You can save to this file and reload it if needed .
the result of the compilation is displayed in a listbox , you can copy it or save it in a file
Run : 3 choices ,you can launch the bin alone , with Open Pipe or in a terminal .

Please report any problem , I use it for weeks and it's ooookayyyy !

the code below is the Linux version .

CompileAndRunLin4.bas

Code: Select all

    ' CompileAndRunLin4
   ' code  by enform  2021/06
    
#Include Once "window9.bi"
		
Type w0
	As HWND hw0
	Declare Function OpenWindow_0() As HWND
	Declare Sub DoLoop()
	Declare Sub FindFbc()
	Declare Sub FindBas()
	Declare Sub AddToCombo()
	Declare Sub DeleteInCombo()
	Declare Sub LoadIni()
	Declare Sub SaveIni()
	Declare Sub Copycb()  '  Button  : Copy results  to Clipbd
End Type
 
 
	Dim Shared win0 As w0
	'Dim Shared pwin0 As w0 Ptr = @win0
	
	#ifdef __FB_LINUX__
		#Define crlf Chr(10)
	#Else
		#Define crlf Chr(13,10)
	#EndIf 

Function w0.OpenWindow_0() As HWND
	hw0 = OpenWindow("CompileAndRunLinux4 by enform 2021/06",0,10,525,550)
	WindowColor(hw0,BGR(245,245,190))
	SetGadgetFont(,CInt(LoadFont("Courier New",10)))
	WindowBounds(hw0,525,550,525,550)
 
	ButtonGadget(1,10,5,80,20,"Find fbc")
 
	ButtonGadget(12,100,5,80,20,"Load ini")
	
	ButtonGadget(14,190,5,80,20,"Save ini")
	
	ComboBoxGadget(11,325,5,185,27)   ' command line 
	SetGadgetColor(11,BGR(240,240,240),BGR(0,0,0),3)
	'SetGadgetFont(11,CInt(LoadFont("Tahoma",9)))
 
	ComboBoxGadget(2,10,40,500,27)  '  fbc

	ButtonGadget(10,10,80,120,20,"Find bas file")
	GadgetToolTip(10, "then Add to combo")
 
	StringGadget(9,10,115,500,20,"bas file here")
 
	ButtonGadget(6,10,150,120,20,"AddToCombo")
 
	ButtonGadget(7,140,150,70,20,"Delete")
   
   ComboBoxGadget(8,10,190,500,27)  ' bas file
 
	ButtonGadget(3,10,235,70,20,"Compile")
	GadgetToolTip(3, "Compile the selected bas file")
 
	ButtonGadget(4,90,235,70,20,"Run bin")
	'GadgetToolTip(4, "Run the compiled bas")
 
	ButtonGadget(19,170,235,90,20,"Open Pipe")
	'GadgetToolTip(19, "Run the compiled bas")
 
	ButtonGadget(20,270,235,150,20,"Run in a terminal")

	ButtonGadget(5,450,280,60,20,"Quit")
 
	TextGadget(18,10,265,500,2,"") ' Horiz line
	
	ButtonGadget(16,10,280,50,20,"Copy")
	
	ButtonGadget(17,80,280,50,20,"Clear")

	EditorGadget(15,10,310,500,200)
	SetGadgetColor(15,BGR(210,220,220),0,1)
	SetGadgetFont(15,CInt(LoadFont("Tahoma",9)))
	
	Return hw0
End Function
  
 win0.hw0 = win0.OpenWindow_0()

Sub w0.LoadIni() '  Button 
	Var hdlini = Read_File(Exepath+"/CompileAndRun.ini")
	If hdlini <> Cast(Any Ptr,-1) Then
 	
		ResetAllComboBox(2)
		ResetAllComboBox(8)
		ResetAllComboBox(11)
		Var sData = ""
		
		While E_O_F(hdlini) = 0
			sData = Read_String(hdlini)
			If sData = "[FbcPath]" Then 
				Do
					sData = Read_String(hdlini)
					If sData = "[CommandLine]" Then Exit Do 
					AddComboBoxItem(2,sData,-1)
				Loop
				Do
					sData = Read_String(hdlini)
					If sData = "[BasFiles]" Then Exit Do 
					AddComboBoxItem(11,sData,-1)
				Loop
				Do
					sData = Read_String(hdlini)
					If sData = "[End]" Then Exit Do 
					AddComboBoxItem(8,sData,-1)
				Loop
			EndIf
		Wend
		Close_File(hdlini)
		SetItemComboBox(2,0)
		SetItemComboBox(8,0)
		SetItemComboBox(11,0)
		SetGadgetText(9,GetComboBoxText(8,0))
	Else
		MessBox("","ini file not found")
	EndIf
End Sub

Sub w0.SaveIni() '  Button 
	Var r = 0
	Var hdlini = Create_File(ExePath + "/CompileAndRun.ini")

	If hdlini <> Cast(Any Ptr,-1) Then
		Write_String(hdlini),"[FbcPath]" + Chr(13,10)
		For r = 0 To CountItemComboBox(2) -1
			Write_String(hdlini),GetComboBoxText(2,r) + Chr(13,10)
		Next
		Write_String(hdlini),"[CommandLine]" + Chr(13,10)
		For r = 0 To CountItemComboBox(11) -1
			Write_String(hdlini),GetComboBoxText(11,r) + Chr(13,10)
		Next
		Write_String(hdlini),"[BasFiles]" + Chr(13,10)
		For r = 0 To CountItemComboBox(8) -1
			Write_String(hdlini),GetComboBoxText(8,r) + Chr(13,10)
		Next
		Write_String(hdlini),"[End]" + Chr(13,10)
		Close_File(hdlini)
	Else
		MessBox("","ini file not created")
	EndIf
End Sub
 
Sub w0.FindBas() '  Button 
	Var filterL = "*(*.bas)"
	Var filterR = "*.bas"
	Var namebas = OpenFileRequester("","",filterL +Chr(0)+filterR ,0)

	If namebas <> "" Then
		SetGadgetText(9,namebas)
	EndIf
End Sub
 
Sub w0.FindFbc() '  Button 
	Var filterL = ""
	Var filterR = ""
	Var namefbc = OpenFileRequester("","",filterL +Chr(0)+filterR ,0)
	
	If namefbc <> "" Then
		AddComboBoxItem(2,namefbc,-1)
	EndIf
End Sub
 
Sub w0.AddToCombo() '  Button 
	AddComboBoxItem(8,GetGadgetText(9),-1)
End Sub
 
Sub w0.DeleteInCombo() '  Button 
	DeleteComboBoxItem(8,GetItemComboBox(8))
End Sub
'
Sub w0.Copycb()  '  Button  : Copy to Clipbd
	Var sLine = ""
	For r As Long = 0 To GetLineCountEditor(15)-1
		sLine += GetLineTextEditor(15,r) + crlf
	Next r
	SetClipBoardText(sLine)
End Sub 
 
 ' main DoLoop 
Sub w0.DoLoop()
	Dim As String CompileBas,ln,ln1,exefile,sPath,sBas
	Dim As Long event,ff,DotBas,Dot,lSlash
	
	Do
		event = WaitEvent
		Select Case event
			Case EventClose
				Exit Do     ' End
			Case EventGadget
				Select Case EventNumber
					Case 1
						FindFbc()
					Case 5
						Exit Do     ' End
					Case 6
						AddToCombo()
					Case 7
						DeleteInCombo()
					Case 8  ' combo sel changed ; copy to the string the bas file name
						SetGadgetText(9,GetComboBoxText(8,GetItemComboBox(8)))
					Case 10
						FindBas()
					Case 12
						LoadIni()
					Case 14
						SaveIni()
					Case 16
						Copycb()
					Case 17      ' clear results editor
						SetGadgetText(15,"")
					Case 3			' direct compile
						CompileBas = GetGadgetText(9)
						lSlash = InStrRev(CompileBas,"/") +1
						sBas = Mid(CompileBas,lSlash)
						SetGadgetText(15,"Compiling  " + sBas)  ' not visible !
						SetGadgetText(3,"Wait")
						DisableGadget(4,1) 
						DisableGadget(19,1) 
						DisableGadget(20,1) 
		
						UpdateInfoXserver()
						
						ff = FreeFile

						Open Pipe(Chr(34)+ GetComboBoxText(2,GetItemComboBox(2))+ Chr(34) _
							+ " " +  GetComboBoxText(11,GetItemComboBox(11)) + " " + CompileBas) _
							+ " "   For Input As #ff
								
						ln = ""
						DotBas = 0
						ln1 = "Result : " + crlf + crlf
			
						Do Until EOF(ff)
							Line Input #ff, ln  ' read the pipe

							DotBas = InStr(ln,".bas") ' after
							If DotBas Then 
								ln = Mid(ln,DotBas+4) ' don't display all the path 
							EndIf
							ln1 += ln + crlf
						Loop
						Close #ff
	
						ln1 += crlf + "Make done at  " + Time + crlf
						SetGadgetText(15,ln1)
						SetGadgetText(3,"Compile")
						DisableGadget(4,0) 
						DisableGadget(19,0) 
						DisableGadget(20,0) 
						
					Case 4   ' run exe
						CompileBas = GetGadgetText(9)
						Dot   = InStrRev(CompileBas,".") -1
					
						exefile = Left(CompileBas,Dot)' + ".exe"  ' for windows
					
						RunProgram(exefile)
						
					Case 19   ' Open Pipe
						CompileBas = GetGadgetText(9)
						Dot   = InStrRev(CompileBas,".") -1
						exefile = Left(CompileBas,Dot)' + ".exe"
				
						ff = FreeFile
						ln = ""
						ln1 = "Open Pipe  :" + crlf
				
						Open Pipe(Chr(34)+ exefile +Chr(34))+ " "  For Input As #ff	
						Do Until EOF(ff)
							Line Input #ff, ln
				
							ln1 += ln + crlf
						Loop
						Close #ff
						SetGadgetText(15,ln1)
			
					Case 20  '   Button  Run in a terminal
						CompileBas = GetGadgetText(9)
						sPath = GetPathPart(CompileBas) + "/"
						Dot = InStrRev(CompileBas,".") -1
						exefile = Left(CompileBas,Dot)' + ".exe"
						Shell ("xfce4-terminal" &" -H -e " &  chr(34) & exefile & chr(34))' & " &")
				End Select
		End Select
	Loop
End Sub
'
 
 win0.LoadIni()
 win0.DoLoop()

CompileAndRun.ini

Code: Select all

[FbcPath]
/usr/local/bin/fbc
[CommandLine]
-s gui
-w all -Wl --verbose
-w all
-s gui -exx
-s gui -g
-s gui -v
-s console
-s gui -gen gcc -O 2 -v
[BasFiles]
/home/hal/Prog-linux/Projects/CutTheLine/CutTheLineLin5h.bas
/home/hal/Prog-linux/Projects/CompileAndRun/CompileAndRunLin3.bas
/home/hal/Prog-linux/Projects/CompileAndRun/CompileAndRunLin4.bas
/home/hal/Prog-linux/Projects/Create_ImageA.bas
[End]

dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by dodicat »

I cannot find
"window9.bi"

OK I have it now.
enform
Posts: 185
Joined: Apr 24, 2011 12:57
Location: France

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by enform »

If you don't know

window9.bi or FbGui for windows 2 in Libraries , also at sourceforge.net

https://freebasic.net/forum/viewtopic.p ... 40#p282607
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by VANYA »

1) Doesn't work with spaces in the path
2) There is no option to install a terminal. For example, I have gnome-terminal
3) Dimensions of gadgets in height (described the problem here: viewtopic.php?p=284442#p284442)
enform
Posts: 185
Joined: Apr 24, 2011 12:57
Location: France

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by enform »

1) Doesn't work with spaces in the path
please , where ?
2) There is no option to install a terminal. For example, I have gnome-terminal
I will try from the ini file
3) Dimensions of gadgets in height
with the same font ? ( size 10 in the code )
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by VANYA »

1) The path to the file: /home/user/Рабочий стол/FBFILE.bas
compile result:
Result :

error 81: Invalid command-line option, "/home/user/Рабочий"

Make done at 06:26:51
3) It doesn't matter what the font size is. On ubuntu > 16.04, most themes use GTK3. Therefore, buttons and some other gadgets are best done with a height size >= 25. Otherwise, the text will not fit in height.
enform
Posts: 185
Joined: Apr 24, 2011 12:57
Location: France

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by enform »

about spaces in a path name , mmmhhh , you know , I am a specialist in ... nothing ! ha !
Isn't usual to get problems with spaces in a path name ?
and sending the same command directly from your terminal is ok ?
In the source code , we call the terminal , give it the path name as is , and ... what can we do ?
I expect you read the source code and you know the solution , dear good coder . :-) Do not hesitate to correct the bug .
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by VANYA »

For a path containing spaces, you need to escape the spaces with a backslash, like this:
fbc /home/user/Рабочий\ стол/FBFILE.bas
enform
Posts: 185
Joined: Apr 24, 2011 12:57
Location: France

Re: Compile And Run : Replace a Linux terminal or Geany with a Gui tool

Post by enform »

something like :

CompileBas = GetGadgetText(9)
If InStr(CompileBas," ") Then
' replace each space with "\ "
CompileBas = ReplaceString(CompileBas," ","\ ",1,1)
EndIf
Post Reply