Skip to content

Commit

Permalink
python fixes and new plugin (from far2l PR)
Browse files Browse the repository at this point in the history
  • Loading branch information
shmuz committed Jan 28, 2025
1 parent 0bba1eb commit 0807fbf
Show file tree
Hide file tree
Showing 13 changed files with 750 additions and 55 deletions.
47 changes: 40 additions & 7 deletions python/configs/plug/far2l/fardialogbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class Element(sizer.Window):
def __init__(
self, varname=None, focus=0, param=None, flags=0, default=0, maxlength=0
):
Element.no += 1
self.no = Element.no
self.varname = varname
self.focus = focus
self.param = param or {"Selected": 0}
Expand All @@ -26,6 +24,8 @@ def __init__(
self.data = None

def makeID(self, dlg):
self.no = Element.no
Element.no += 1
if self.varname is not None:
setattr(dlg, "ID_" + self.varname, self.no)

Expand Down Expand Up @@ -54,11 +54,13 @@ def makeItem(self, dlg):
class Spacer(Element):
def __init__(self, width=1, height=1):
super().__init__()
# non countable ID
Element.no -= 1
self.width = width
self.height = height

def makeID(self, dlg):
# non countable ID
pass

def get_best_size(self):
return (self.width, self.height)

Expand Down Expand Up @@ -362,8 +364,6 @@ def __init__(
self.add(contents, border)

def build(self, x, y):
# for building dlg.ID_<varname>
Element.no = 0

dlg = Dialog(self.plugin)

Expand All @@ -373,10 +373,12 @@ def build(self, x, y):
dlg.width = w
dlg.height = h

# for building dlg.ID_<varname>
Element.no = 1
self.contents.makeID(dlg)
self.size(3, 1, w, h)

dlg.dialogItems.append(
dlg.dialogItems.insert(0,
(
dlg.ffic.DI_DOUBLEBOX,
3,
Expand Down Expand Up @@ -412,3 +414,34 @@ def build(self, x, y):
0,
)
return dlg

def build_nobox(self, x, y, w, h):

dlg = Dialog(self.plugin)

dlg.width = w
dlg.height = h

# for building dlg.ID_<varname>
Element.no = 0
self.contents.makeID(dlg)
self.size(0, 0, w, h)

self.contents.makeItem(dlg)

dlg.fdi = dlg.ffi.new("struct FarDialogItem []", dlg.dialogItems)
dlg.hDlg = dlg.info.DialogInit(
dlg.info.ModuleNumber,
x,
y,
w,
h,
dlg.s2f(self.helptopic),
dlg.fdi,
len(dlg.fdi),
0,
self.flags,
self.dialogProc,
0,
)
return dlg
16 changes: 14 additions & 2 deletions python/configs/plug/plugins/read-en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ a) the plugins are loaded with the command "py:load filename" for example py:loa
b) unloading the plugin is done with the command "py:unload filename" for example py:unload ucharmap

D. Examples
a) ucharmap.py - an example plugin showing part of the UTF-8 character set
a) ucharmap.py - an example plugin showing whole UTF-8 character set
F11 + "Python Character Map" - display its dialog
after pressing Enter/OK selected character is coppied into clipboard
Offset - position in the character set
Goto - change position - decimal or hexadecimal number or 1 character is allowed, valid range is <0x0000-0xffff>
Keys:
Home = goto first visible offset
PgUp = prevoius page
PgDn = next page
Left = prevoius character in row
Right = next character in row
Up = prevoius row
Down = next row
ENTER/OK = copy character at aooset into clipboard
Mouse:
Click - select character at pointer position
b) udialog.py - plugin with two examples, dialog and command line extensions "py:dialog" and "py:exec python.script.goes.here"
F11 + "Python udialog" - will display the first dialog
py:dialog - will display a second dialog with one input element
Expand Down
4 changes: 3 additions & 1 deletion python/configs/plug/plugins/read-pl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ a) zaladowanie wtyczki odbywa się komendą "py:load nazwa-pliku" na przykład p
b) odładowanie wtyczki odbywa się komendą "py:unload nazwa-pliku" na przykład py:unload ucharmap

D. Przykłady
a) ucharmap.py - przykładowa wtyczka pokazująca część zestawu znakow UTF-8
a) ucharmap.py - przykładowa wtyczka pokazująca zestawu znakow UTF-8
F11 + "Python Character Map" wyświetli dialog
wybranie OK lub naciśnięcie Enter skopiuje podświetlony znak do schowka
Offset - położenie w zestawie znaków
Goto - zmiana położenia - dopuszczalna jest liczba dziesiętna lub szsnatkowa lub znak
b) udialog.py - wtyczka z dwoma przykładami, dialog i rozszerzenie wiersza poleceń o komendy "py:dialog" oraz "py:exec polecenia.pythona.do.wykonania"
F11 + "Python udialog" - wyświetli pierwszy dialog
py:dialog - wyświetli druki dialog
Expand Down
54 changes: 36 additions & 18 deletions python/configs/plug/plugins/ucharmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def OpenPlugin(self, OpenFrom):
log.exception('run')

def GetCursorPos(self, hDlg, ID):
cpos = self.ffi.new("COORD *", dict(X=0, Y=0))
cpos = self.ffi.new("COORD *")
self.info.SendDlgMessage(hDlg, self.ffic.DM_GETCURSORPOS, ID, self.ffi.cast("LONG_PTR", cpos))
return (cpos.X, cpos.Y)

Expand All @@ -39,13 +39,25 @@ def _OpenPlugin(self, OpenFrom):
import debugpy
debugpy.breakpoint()

def GetColor(no):
data = self.ffi.new("DWORD *")
rc = self.info.AdvControl(
self.info.ModuleNumber,
self.ffic.ACTL_GETCOLOR,
self.ffi.cast("VOID *", no),
self.ffi.cast("VOID *", data)
)
return data[0]

self.offset = 0
self.max_col = 64
self.max_row = 20
self.text = ''
self.charbuf = self.ffi.new("CHAR_INFO []", self.max_col*self.max_row)
attrNormal = 0x170
attrSelected = 0x1c
attrNormal = GetColor(self.ffic.COL_EDITORTEXT)
attrSelected = GetColor(self.ffic.COL_EDITORSELECTEDTEXT)
#attrNormal = 0x170
#attrSelected = 0x1c

def setVBuf(hDlg):
self.info.SendDlgMessage(hDlg, self.ffic.DM_ENABLEREDRAW, 0, 0)
Expand Down Expand Up @@ -73,28 +85,34 @@ def _DialogProc(hDlg, Msg, Param1, Param2):
self.SetCursorPos(hDlg, dlg.ID_hex, 0, 0)
setColor(0, 0, attrSelected)
updateOffset(0)
self.info.SendDlgMessage(hDlg, self.ffic.DM_SETCURSORSIZE, dlg.ID_hex, 1|(100<<32))
self.info.SendDlgMessage(hDlg, self.ffic.DM_SETCURSORSIZE, dlg.ID_hex, 0|(0<<16))
dlg.SetFocus(dlg.ID_hex)
return self.info.DefDlgProc(hDlg, Msg, Param1, Param2)
elif Msg == self.ffic.DN_BTNCLICK:
#log.debug(f"btn DialogProc({Param1}, {Param2})")
if Param1 == dlg.ID_vgoto:
v = dlg.GetText(dlg.ID_vgotovalue).strip()
if not v:
v = '0'
try:
offset = int(v, 16 if v[:2] == '0x' else 10)
self.offset = offset
setVBuf(hDlg)
except:
if len(v) == 1:
self.offset = ord(v)
setVBuf(hDlg)
else:
log.exception('goto')
dlg.SetFocus(dlg.ID_hex)
self.SetCursorPos(hDlg, dlg.ID_hex, 0, 0)
if v:
try:
offset = int(v, 16 if v[:2] == '0x' else 10)
if offset > 0xffff:
offset = 0
dlg.SetText(dlg.ID_vgotovalue, '0')
self.offset = offset
except:
if len(v) == 1:
self.offset = ord(v)
setVBuf(hDlg)
else:
dlg.SetText(dlg.ID_vgotovalue, '')
log.exception('goto')
setVBuf(hDlg)
updateOffset(self.offset)
col, row = self.GetCursorPos(hDlg, dlg.ID_hex)
setColor(col, row, attrNormal)
setColor(0, 0, attrSelected)
self.SetCursorPos(hDlg, dlg.ID_hex, 0, 0)
dlg.SetFocus(dlg.ID_hex)
return 1
elif Param1 == dlg.ID_vok:
col, row = self.GetCursorPos(hDlg, dlg.ID_hex)
Expand Down
2 changes: 1 addition & 1 deletion python/configs/plug/plugins/ucharmapold.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def Rebuild(self, hDlg):
def OpenPlugin(self, OpenFrom):
if 0:
import debugpy

debugpy.breakpoint()

symbols = []
for i in range(256):
symbols.append(chr(i))
Expand Down
2 changes: 0 additions & 2 deletions python/configs/plug/plugins/uedindent.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from far2l.plugin import PluginBase
import far2lc

import debugpy


log = logging.getLogger(__name__)

Expand Down
3 changes: 0 additions & 3 deletions python/configs/plug/plugins/uedsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from far2l.plugin import PluginBase
import far2lc

import debugpy


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,7 +71,6 @@ def Perform(self):


def OpenPlugin(self, OpenFrom):
# debugpy.breakpoint()
if OpenFrom == 5:
# EDITOR
self.Perform()
Expand Down
3 changes: 0 additions & 3 deletions python/configs/plug/plugins/ueduniq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from far2l.plugin import PluginBase
import far2lc

import debugpy


log = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,7 +73,6 @@ def Perform(self):


def OpenPlugin(self, OpenFrom):
# debugpy.breakpoint()
if OpenFrom == 5:
# EDITOR
self.Perform()
Expand Down
Loading

0 comments on commit 0807fbf

Please sign in to comment.