Page 1 of 3

plugin to (re)open file as hex/binary

Posted: 19.06.2020 13:52
by tmsg
I'm trying to write a py function to open a file as binary.

Code: Select all

def openBinary(self):
		fn=_get_filename(ed)
		file_open(fn,-1,'/view-hex')
doesn't work, probably because the file is open already. Hm...

Code: Select all

def openBinary(self):
		fn=_get_filename(ed)
		ed.cmd(cmds.cmd_FileClose)
		file_open(fn,-1,'/view-hex')
would not be optimal because the file is closed and reopened but it doesn't work in the first place. Any idea?

Additionally, is there a way if a file is view-hex-opened to have more than 32 bytes per row?

Posted: 19.06.2020 19:05
by Alexey
>Additionally, is there a way if a file is view-hex-opened to have more than 32 bytes per row?
I have added it now- ed.get_prop/set_prop with PROP_V_WIDTH_HEX, PROP_V_WIDTH_UHEX.
must think how to reopen file...

Posted: 19.06.2020 19:26
by Alexey
Also changed the API so setting ed.set_prop(PROP_V_MODE,...) switches editor to viewer.

BTW, "def openBinary" is Java style, pls don't use it, write like "def open_binary"

Posted: 19.06.2020 20:13
by Alexey
Beta with new api- http://uvviewsoft.com/c/

Posted: 20.06.2020 08:57
by tmsg
@Alexey Thanks for those changes, appreciated.
Alexey wrote:BTW, "def openBinary" is Java style, pls don't use it, write like "def open_binary"
I've not written a single line of Java in my whole life :D and I've written my first Pascal programs some 12 years before Java was even invented... so I'd rather think it's MY style.

As to style matters and Python in general... probably best not to get me started :evil:

Posted: 20.06.2020 09:38
by tmsg
Toggling to Hex now works almost perfect, the only small problem is that

Code: Select all

ed.set_prop(PROP_V_WIDTH_HEX,32)
doesn't work first time round.

However, toggling back to edit mode seems not possible...? Perhaps there's an API for that but if so I don't know which.

Also, while playing with this... wouldn't it not great if I could do something like this:

Code: Select all

fn='x:\\somepath\\somefile.txt'
file_open((fn,fn), group=-1, options="/edit /view-hex")
Not saying this is the best way to do that but this would make it possible to open a file in a tab with two different views: left as a full editor and right as hex. Sounds super cool. 8-)

Posted: 20.06.2020 16:15
by Alexey
>ed.set_prop(PROP_V_WIDTH_HEX,32)
It works here (after I open file in VMODE_HEX). maybe you didnt update cudatext.py?

Posted: 20.06.2020 16:18
by Alexey
Current app structure don't allow to show viewer (hex) with editor, both.
So cannot do it.
Also it's terrible to sync memory buffers - editor has one list of data, viewer- another one

Posted: 20.06.2020 16:44
by tmsg
Alexey wrote:>ed.set_prop(PROP_V_WIDTH_HEX,32)
It works here (after I open file in VMODE_HEX). maybe you didnt update cudatext.py?
I was setting the width BEFORE switching. Now it works.

EDIT: I assume switching back to Editor mode doesn't work either?

Posted: 20.06.2020 19:44
by Alexey
Now it works!
see new beta (same URL)
wiki
https://wiki.freepascal.org/index.php?t ... did=137204