Skip to content

Commit

Permalink
#4023 convert to grid
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Oct 6, 2023
1 parent 2bd6c2a commit 91860c9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
8 changes: 5 additions & 3 deletions xpra/gtk/dialogs/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ def populate(self):
self.ib("Shadow", "server-connected.png", tooltip, self.shadow, sensitive=has_shadow)
tooltip = "Start a new %sxpra session" % (" remote" if (WIN32 or OSX) else "")
self.ib("Start", "windows.png", tooltip, self.start)
table = Gtk.Table(n_rows=2, n_columns=2, homogeneous=True)
grid = Gtk.Grid()
grid.set_row_homogeneous(True)
grid.set_column_homogeneous(True)
for i, widget in enumerate(self.widgets):
table.attach(widget, i%2, i%2+1, i//2, i//2+1, xpadding=10, ypadding=10)
self.vbox.add(table)
grid.attach(widget, i%2, i//2, 1, 1)
self.vbox.add(grid)

def add_widget(self, widget):
self.widgets.append(widget)
Expand Down
32 changes: 19 additions & 13 deletions xpra/gtk/dialogs/show_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,31 @@ def window_deleted(*_args):
icon = get_icon_pixbuf("keyboard.png")
if icon:
self.set_icon(icon)
label = lal("Help: shortcuts", "sans 18")
vbox.pack_start(label, True, True, 10)
label = lal("Prefix: %s" % ("+".join(shortcut_modifiers)))
vbox.pack_start(label, True, True, 0)
def vlabel(text, font="", padding=0):
vbox.pack_start(lal(text, font), True, True, padding)

vlabel("Help: shortcuts", "sans 18", 10)
vlabel("Prefix: %s" % ("+".join(shortcut_modifiers)), padding=0)
#each key may have multiple shortcuts, count them all:
total = 0
for keyname in shortcuts:
total += len(shortcuts[keyname])
label = lal("%i Shortcuts:" % (total, ), "sans 16")
vbox.pack_start(label, True, True, 20)
table = Gtk.Table(n_rows=total+1, n_columns=2, homogeneous=True)
vlabel("%i Shortcuts:" % (total, ), "sans 16", 20)

grid = Gtk.Grid()
grid.set_row_homogeneous(True)
grid.set_column_homogeneous(True)

row = 0
def attach(s, x=0, font=""):
al = Gtk.Alignment(xalign=0, yalign=0.5, xscale=0.0, yscale=0.0)
l = label(s, font=font)
l.set_margin_start(5)
l.set_margin_top(2)
l.set_margin_end(5)
l.set_margin_bottom(2)
al.add(l)
table.attach(al, x, x+1, row, row+1,
xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL,
xpadding=10, ypadding=0)
grid.attach(al, x, row, 1, 1)
attach("Keys", 0, "sans bold 12")
attach("Action", 1, "sans bold 12")
row += 1
Expand All @@ -76,11 +82,11 @@ def attach(s, x=0, font=""):
attach(keys, 0)
attach(action, 1)
row += 1
vbox.pack_start(table, False, True, 0)
vbox.pack_start(grid, False, True, 0)
vbox.set_margin_top(20)
vbox.set_margin_bottom(20)
vbox.set_margin_left(20)
vbox.set_margin_right(20)
vbox.set_margin_start(20)
vbox.set_margin_end(20)
self.add(vbox)


Expand Down
39 changes: 22 additions & 17 deletions xpra/gtk/examples/initiate_moveresize.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from xpra.common import MoveResize, MOVERESIZE_DIRECTION_STRING
from xpra.gtk.gtk_util import add_close_accel
from xpra.gtk.widget import IgnoreWarningsContext
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.platform import program_context

Expand All @@ -29,8 +30,7 @@ def make_window():
def get_root_window():
return window.get_window().get_screen().get_root_window()

def initiate(x_root, y_root, direction, button, source_indication):
#print("initiate%s" % str((x_root, y_root, direction, button, source_indication)))
def initiate(x_root : float, y_root : float, direction : MoveResize, button : int, source_indication : int):
from xpra.x11.gtk3.display_source import init_gdk_display_source
init_gdk_display_source()
from xpra.x11.bindings.core import X11CoreBindings #@UnresolvedImport
Expand All @@ -46,35 +46,40 @@ def initiate(x_root, y_root, direction, button, source_indication):

def cancel():
initiate(0, 0, MoveResize.CANCEL, 0, 1)
def expand(widget):
widget.set_hexpand(True)
widget.set_vexpand(True)
return widget

grid = Gtk.Grid()
grid.set_row_homogeneous(True)
grid.set_column_homogeneous(True)

table = Gtk.Table(n_rows=3, n_columns=3, homogeneous=True)

FILL = Gtk.AttachOptions.FILL
EXPAND = Gtk.AttachOptions.EXPAND
btn = Gtk.Button(label="initiate move")
table.attach(btn, 1, 2, 1, 2, xoptions=FILL, yoptions=FILL)
grid.attach(expand(btn), 2, 2, 1, 1)
def initiate_move(*_args):
cancel()
pos = get_root_window().get_pointer()
with IgnoreWarningsContext():
pos = get_root_window().get_pointer()
source_indication = 1 #normal
button = 1
direction = MoveResize.MOVE
initiate(pos.x, pos.y, direction, button, source_indication)
initiate(pos.x, pos.y, MoveResize.MOVE, button, source_indication)
GLib.timeout_add(5*1000, cancel)
btn.connect('button-press-event', initiate_move)

def btn_callback(_btn, _event, direction):
def btn_callback(_btn, _event, direction:MoveResize):
cancel()
x, y = get_root_window().get_pointer()[1:3]
with IgnoreWarningsContext():
pos = get_root_window().get_pointer()
source_indication = 1 #normal
button = 1
initiate(x, y, direction, button, source_indication)
initiate(pos.x, pos.y, direction, button, source_indication)
GLib.timeout_add(5*1000, cancel)
def add_button(x, y, direction):

def add_button(x:int, y:int, direction:MoveResize):
btn = Gtk.Button(label=MOVERESIZE_DIRECTION_STRING[direction])
table.attach(btn, x, x+1, y, y+1, xoptions=EXPAND|FILL, yoptions=EXPAND|FILL)
btn.connect('button-press-event', btn_callback, direction)
grid.attach(expand(btn), x, y, 1, 1)

for x,y,direction in (
(0, 0, MoveResize.SIZE_TOPLEFT),
Expand All @@ -88,8 +93,8 @@ def add_button(x, y, direction):
(2, 2, MoveResize.SIZE_BOTTOMRIGHT),
):
add_button(x, y, direction)
table.show_all()
window.add(table)
grid.show_all()
window.add(grid)
window.set_size_request(width, height)
return window

Expand Down
14 changes: 11 additions & 3 deletions xpra/gtk/examples/window_geometry_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,17 @@ def __init__(self, args=()):
if icon:
self.set_icon(icon)

t = Gtk.Table(n_rows=9, n_columns=3, homogeneous=True)
grid = Gtk.Grid()
grid.set_row_homogeneous(True)
grid.set_column_homogeneous(True)

def expand(widget):
widget.set_hexpand(True)
widget.set_vexpand(True)
return widget

def attach(widget, col, row):
t.attach(widget, col, col+1, row, row+1, Gtk.AttachOptions.EXPAND, Gtk.AttachOptions.FILL, 0, 0)
grid.attach(expand(widget), col, row, 1, 1)
def l(s): # noqa: E743
return label(s)
def line(row, *widgets):
Expand Down Expand Up @@ -111,7 +119,7 @@ def e():
btn.set_label("Create")
btn.connect("clicked", self.create)
line(8, l(""), btn)
self.add(t)
self.add(grid)
for i, entry in enumerate((
self.requested_width, self.requested_height,
self.min_width, self.min_height,
Expand Down

0 comments on commit 91860c9

Please sign in to comment.