Page 1 of 1

How to access PBEditor`s internal variables

Posted: Wed Apr 04, 2012 6:05 pm
by Zebuddi123
How to access PBEditor`s internal variables ie for word under the cursor etc. I`m looking to write a tool any pointers to more info articles example code much appreciated.


Thank`s
Zebuddi

Re: How to access PBEditor`s internal variables

Posted: Wed Apr 04, 2012 8:27 pm
by STARGÅTE
if you run your code, as a child process from PB-IDE (add it as tool), you can use:

Code: Select all

ScintillaID.i = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
to get the ID from the Editor-(Scintilla)-Gadget or

Code: Select all

GetEnvironmentVariable("PB_TOOL_Cursor")
to get the cursor.

Code: Select all

Enumeration
	#Window
	#Gadget
EndEnumeration


OpenWindow(#Window, 0, 0, 800, 600, "EnvironmentVariables", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
	EditorGadget(#Gadget, 0, 0, 800, 600)
	
	If ExamineEnvironmentVariables()
		While NextEnvironmentVariable()
			AddGadgetItem(#Gadget, #PB_Default, EnvironmentVariableName()+" = "+EnvironmentVariableValue())
		Wend
	EndIf
	
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
ALLUSERSPROFILE = C:\Dokumente und Einstellungen\All Users
APPDATA = C:\Dokumente und Einstellungen\***\Anwendungsdaten
CLIENTNAME = Console
CommonProgramFiles = C:\Programme\Gemeinsame Dateien
COMPUTERNAME = MARTIN
[...]
PB_TOOL_Compiler = D:\Programme\PureBasic\Compilers\PBCompiler.exe
PB_TOOL_Cursor = 3x9
PB_TOOL_Debugger = 1
[...]
PB_TOOL_Scintilla = 1180554
PB_TOOL_Selection = 3x9x3x9
PB_TOOL_SubSystem =
PB_TOOL_Thread = 0
PB_TOOL_Unicode = 0
PB_TOOL_Word =
PB_TOOL_XPSkin = 1
[...]

Re: How to access PBEditor`s internal variables

Posted: Wed Apr 04, 2012 11:21 pm
by Zebuddi123
Thanks STARGÅTE :D

All though initially i had a problem in that pb 4.61 b1 32bit doesnt spit out the PB_TOOL_* details :o running w7 x64 ultimate
ie
ALLUSERSPROFILE = C:\ProgramData
APPDATA = C:\Users\zebuddi\AppData\Roaming
CommonProgramFiles = C:\Program Files (x86)\Common Files
CommonProgramFiles(x86) = C:\Program Files (x86)\Common Files
CommonProgramW6432 = C:\Program Files\Common Files
COMPUTERNAME = ZEBUDDIQUAD-PC
ComSpec = C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK = NO
HOMEDRIVE = C:
HOMEPATH = \Users\zebuddi
LOCALAPPDATA = C:\Users\zebuddi\AppData\Local
LOGONSERVER = \\ZEBUDDIQUAD-PC
MOZ_PLUGIN_PATH = C:\Program Files (x86)\Foxit Software\Foxit Reader\plugins\
NUMBER_OF_PROCESSORS = 4
OS = Windows_NT
Path = C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Calibre2\
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE = x86
PROCESSOR_ARCHITEW6432 = AMD64
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 15 Stepping 7, GenuineIntel
PROCESSOR_LEVEL = 6
PROCESSOR_REVISION = 0f07
ProgramData = C:\ProgramData
ProgramFiles = C:\Program Files (x86)
ProgramFiles(x86) = C:\Program Files (x86)
ProgramW6432 = C:\Program Files
PSModulePath = C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC = C:\Users\Public
PUREBASIC_HOME = C:\Program Files (x86)\PureBasic\
SystemDrive = C:
SystemRoot = C:\Windows
TEMP = C:\Users\zebuddi\AppData\Local\Temp
TMP = C:\Users\zebuddi\AppData\Local\Temp
USERDOMAIN = ZEBUDDIQUAD-PC
USERNAME = zebuddi
USERPROFILE = C:\Users\zebuddi
windir = C:\Windows
__COMPAT_LAYER = ElevateCreateProcess

where japbe latest update does

FP_NO_HOST_CHECK = NO
HOMEDRIVE = C:
HOMEPATH = \Users\zebuddi
LOCALAPPDATA = C:\Users\zebuddi\AppData\Local
LOGONSERVER = \\ZEBUDDIQUAD-PC
MOZ_PLUGIN_PATH = C:\Program Files (x86)\Foxit Software\Foxit Reader\plugins\
NUMBER_OF_PROCESSORS = 4
OS = Windows_NT
Path = C:\PROGRAM FILES (X86)\NVIDIA CORPORATION\PHYSX\COMMON;C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\PROGRAM FILES (X86)\CALIBRE2\;C:\PROGRAM FILES (X86)\PUREBASIC\EXAMPLES\;C:\PROGRAM FILES (X86)\PUREBASIC\COMPILERS\
PATHEXT = .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PB_TOOL_Compiler = C:\Program Files (x86)\PureBasic\Compilers\PBCompiler.exe
PB_TOOL_Cursor = 9x50
PB_TOOL_Debugger = 0
PB_TOOL_Executable = C:\Users\zebuddi\AppData\Local\Temp\PB_EditorOutput.pb
PB_TOOL_FileList = C:\Program Files (x86)\japbe\Sources\Plugin\Example.pb
C:\Program Files (x86)\japbe\Sources\Plugin\CUT.Example.pb
PB_TOOL_IDE = C:\Program Files (x86)\japbe\jaPBe.exe
PB_TOOL_InlineASM = 0
PB_TOOL_Language = English
PB_TOOL_MainWindow = 460378
PB_TOOL_OnError = 0
PB_TOOL_Scintilla = 722098
PB_TOOL_Selection = 9x50x9x50
PB_TOOL_Thread = 0
PB_TOOL_Unicode = 0
PB_TOOL_Word = fromjapbe
PB_TOOL_XPSkin = 0
PROCESSOR_ARCHITECTURE = x86
PROCESSOR_ARCHITEW6432 = AMD64
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 15 Stepping 7, GenuineIntel
PROCESSOR_LEVEL = 6
PROCESSOR_REVISION = 0f07
ProgramData = C:\ProgramData
ProgramFiles = C:\Program Files (x86)
ProgramFiles(x86) = C:\Program Files (x86)
ProgramW6432 = C:\Program Files
PSModulePath = C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC = C:\Users\Public
SystemDrive = C:
SystemRoot = C:\Windows
TEMP = C:\Users\zebuddi\AppData\Local\Temp
TMP = C:\Users\zebuddi\AppData\Local\Temp
USERDOMAIN = ZEBUDDIQUAD-PC
USERNAME = zebuddi
USERPROFILE = C:\Users\zebuddi
windir = C:\Windows
__COMPAT_LAYER = RunAsAdmin

would you have any idea why ?

As allways great community quick responces and allways helpfull

Zebuddi

Re: How to access PBEditor`s internal variables

Posted: Wed Apr 04, 2012 11:25 pm
by STARGÅTE
read my post:
if you run your code, as a child process from PB-IDE (add it as tool), you can use
you must create a exe, include it to PB-Tools and then run it from IDE, then you get the values

Re: How to access PBEditor`s internal variables

Posted: Wed Apr 04, 2012 11:31 pm
by Zebuddi123
Yes it does. thank you so much best wishes
Zebuddi :lol:

Re: How to access PBEditor`s internal variables

Posted: Thu Apr 05, 2012 12:05 am
by Zebuddi123
Hi STARGÅTE just playing see how things work. just put this into a thread() to see what happens

Code: Select all

Enumeration
	#Window
	#Gadget
EndEnumeration


Procedure do(x.b)
	Repeat
	Delay(2000)
	ClearGadgetItems(#Gadget)
	
	If ExamineEnvironmentVariables()
		While NextEnvironmentVariable()
			If FindString(EnvironmentVariableName(),"PB_TOOL")
				AddGadgetItem(#Gadget, #PB_Default, EnvironmentVariableName()+" = "+EnvironmentVariableValue())
			EndIf
			
		Wend
	EndIf
	ForEver
EndProcedure

OpenWindow(#Window, 0, 0, 800, 600, "EnvironmentVariables", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
EditorGadget(#Gadget, 0, 0, 800, 600)

;    If ExamineEnvironmentVariables()
;    	While NextEnvironmentVariable()
;    		If FindString(EnvironmentVariableName(),"PB_TOOL")
;    			AddGadgetItem(#Gadget, #PB_Default, EnvironmentVariableName()+" = "+EnvironmentVariableValue())
;    		EndIf
;    		
;       Wend
;    EndIf

x=CreateThread(@do(),0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
KillThread(x)
END
which should auto update every 2 secs clear the gadget and update with new values, it does not any advice would be welcome

Thanks :D
Zebuddi

Re: How to access PBEditor`s internal variables

Posted: Thu Apr 05, 2012 2:09 am
by STARGÅTE
this is no good way for your plan: "for word under the cursor etc".

the EnvironmentVariables are not dynamic, so you can only you the static ScintillaID.
With the scintilla-functions (SendMessage_) you can get any informations like this:

Code: Select all

Enumeration
	#Window
	#Timer
	#Gadget1
	#Gadget2
EndEnumeration

OpenWindow(#Window, 600, 100, 300, 100, "Cursor", #PB_Window_SystemMenu)
	AddWindowTimer(#Window, #Timer, 100)
	TextGadget(#Gadget1, 10, 10, 400, 20, "")
	TextGadget(#Gadget2, 10, 40, 400, 20, "")
StickyWindow(#Window, #True)

Define ScintillaID.i = Val(GetEnvironmentVariable("PB_TOOL_Scintilla"))
Define Position.i, Min.i, Max.i, Text.s

Repeat
	
	Select WaitWindowEvent()
			
		Case #PB_Event_CloseWindow
			End
		
		Case #PB_Event_Timer
			Select EventTimer()
				Case #Timer
					Position = SendMessage_(ScintillaID, #SCI_GETCURRENTPOS, #Null, #Null)
					SetGadgetText(#Gadget1, "Cursor position: "+Str(Position))
					Min = SendMessage_(ScintillaID, #SCI_WORDSTARTPOSITION, Position, #True)
					Max = SendMessage_(ScintillaID, #SCI_WORDENDPOSITION, Position, #True)
					If Min And Max
						Text = ""
						For Position = Min To Max-1
							Text + Chr(SendMessage_(ScintillaID, #SCI_GETCHARAT, Position, #Null))
						Next
					EndIf
					SetGadgetText(#Gadget2, "Current word under cursor: "+Text)
			EndSelect
			
	EndSelect
	
ForEver
Image

i hope this code will help you.

Re: How to access PBEditor`s internal variables

Posted: Thu Apr 05, 2012 7:41 pm
by Zebuddi123
Thanks STARGÅTE that brilliant :D

Re: How to access PBEditor`s internal variables

Posted: Fri Apr 06, 2012 8:31 am
by Kwai chang caine
Waoouuh splendid !!! :shock:
Even for me, your code works :mrgreen:
Thanks a lot for sharing 8)