Skip to content

Commit

Permalink
Merge pull request elfmz#2589 from m32/master
Browse files Browse the repository at this point in the history
python - fixes and new examples
  • Loading branch information
elfmz authored Dec 22, 2024
2 parents d85cab7 + a61d541 commit aa6298b
Show file tree
Hide file tree
Showing 11 changed files with 947 additions and 547 deletions.
42 changes: 35 additions & 7 deletions python/configs/plug/far2l/fardialogbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, varname, text, **kwargs):
self.text = text

def get_best_size(self):
return (len(self.text), 1)
return (len(self.text.replace('&','')), 1)

def makeItem(self, dlg):
self.data = dlg.s2f(self.text)
Expand All @@ -84,10 +84,15 @@ class EDIT(Element):
dit = "DI_EDIT"

def __init__(self, varname, width, mask=None, height=1, **kwargs):
if "history" in kwargs:
history = kwargs.pop("history")
else:
history = None
super().__init__(varname, **kwargs)
self.width = width
self.height = height
self.mask = None
self.history = history

def get_best_size(self):
return (self.width, self.height)
Expand All @@ -97,6 +102,9 @@ def makeItem(self, dlg):
if self.mask is not None:
self.param = {"Mask": dlg.s2f(self.mask)}
self.flags = dlg.ffic.DIF_MASKEDIT
elif self.history is not None:
self.param = {"History": dlg.s2f(self.history)}
self.flags = dlg.ffic.DIF_HISTORY
super().makeItem(dlg)


Expand Down Expand Up @@ -127,7 +135,7 @@ def __init__(self, varname, text, **kwargs):

def get_best_size(self):
# [ text ]
return (4 + len(self.text), 1)
return (4 + len(self.text.replace('&','')), 1)

def makeItem(self, dlg):
self.data = dlg.s2f(self.text)
Expand All @@ -145,7 +153,7 @@ def __init__(self, varname, text, checked=0, **kwargs):

def get_best_size(self):
# [?] text
return (4 + len(self.text), 1)
return (4 + len(self.text.replace('&','')), 1)

def makeItem(self, dlg):
self.data = dlg.s2f(self.text)
Expand All @@ -162,7 +170,7 @@ def __init__(self, varname, text, selected=0, **kwargs):

def get_best_size(self):
# (?) text
return (4 + len(self.text), 1)
return (4 + len(self.text.replace('&','')), 1)

def makeItem(self, dlg):
self.data = dlg.s2f(self.text)
Expand All @@ -173,10 +181,14 @@ class COMBOBOX(Element):
dit = "DI_COMBOBOX"

def __init__(self, varname, selected, *items, **kwargs):
if "width" in kwargs:
width = kwargs.pop("width")
else:
width = max([len(s) for s in items])
super().__init__(varname, **kwargs)
self.selected = selected
self.items = items
self.width = max([len(s) for s in items])
self.width = width

def get_best_size(self):
return (2 + self.width, 1)
Expand Down Expand Up @@ -247,8 +259,8 @@ class USERCONTROL(Element):

def __init__(self, varname, width, height, **kwargs):
super().__init__(varname, **kwargs)
self.width
self.height
self.width = width
self.height = height

def get_best_size(self):
return (self.width, self.height)
Expand Down Expand Up @@ -320,6 +332,22 @@ def makeItem(self, dlg):
control.makeItem(dlg)


class FlowSizer(sizer.FlowSizer):
def __init__(self, cols, *controls, border=(0, 0, 0, 0)):
super().__init__(cols)
self.controls = controls
for control in controls:
self.add(control, border)

def makeID(self, dlg):
for control in self.controls:
control.makeID(dlg)

def makeItem(self, dlg):
for control in self.controls:
control.makeItem(dlg)


class DialogBuilder(sizer.HSizer):
def __init__(
self, plugin, dialogProc, title, helptopic, flags, contents, border=(2, 1, 2, 1)
Expand Down
54 changes: 53 additions & 1 deletion python/configs/plug/far2l/fardialogsizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ["Window", "HSizer", "VSizer"]
__all__ = ["Window", "Spacer", "HSizer", "VSizer", "GridSizer"]


class Orientation:
Expand All @@ -19,6 +19,10 @@ def get_best_size(self):
raise NotImplementedError("Window.get_best_size")


class Spacer(Window):
def get_best_size(self):
return self.size

class Box:
def __init__(self, window, border):
self.window = window
Expand Down Expand Up @@ -88,3 +92,51 @@ class HSizer(Sizer):

class VSizer(Sizer):
orientation = Orientation.vertical


class FlowSizer(Sizer):
def __init__(self, cols, border=(0, 0, 0, 0)):
self.boxes = [[]]
self.cols = cols
self.border = border
self.sizes = None
self.col_widths = None
self.row_heights = None

def add(self, w, border=(0, 0, 1, 0)):
box = self.boxes[-1]
if len(box) == self.cols:
box = []
self.boxes.append(box)
box.append(Box(w, border))

def move(self, x, y, w, h):
self.size(x, y, w, h)

def size(self, l, t, r, b):
l += self.border[0]
t += self.border[1]
r -= self.border[2]
b -= self.border[3]
cy = 0
for row in range(len(self.boxes)):
cx = 0
for col in range(len(self.boxes[row])):
box = self.boxes[row][col]
bx, by = box.get_best_size()
box.size(l+cx, t+cy, l+cx+self.col_widths[col], t+cy+by)
cx += self.col_widths[col]
cy += self.row_heights[row]

def get_best_size(self):
while len(self.boxes[-1])%self.cols:
self.add(Spacer())
sizes = [[col.get_best_size() for col in row] for row in self.boxes]
col_widths = [max(sizes[row_nr][col_nr][0] for row_nr in range(len(sizes))) for col_nr in range(len(sizes[0]))]
row_heights = [max(col[1] for col in row) for row in sizes]
self.sizes = sizes
self.col_widths = col_widths
self.row_heights = row_heights
w = sum(col_widths)
h = sum(row_heights)
return w, h
Loading

0 comments on commit aa6298b

Please sign in to comment.