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 8, 2023
1 parent 647d46e commit fa5646a
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 136 deletions.
9 changes: 4 additions & 5 deletions xpra/client/gtk3/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@

from xpra.gtk.signals import register_os_signals
from xpra.scripts.config import read_config, make_defaults_struct, validate_config, save_config
from xpra.gtk.gtk_util import (
add_close_accel, color_parse, )
from xpra.gtk.widget import scaled_image, imagebutton, label, choose_file
from xpra.gtk.gtk_util import add_close_accel, color_parse
from xpra.gtk.widget import scaled_image, imagebutton, label, choose_file, modify_fg
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.util.str_fn import csv, repr_ellipsized
from xpra.os_util import WIN32, OSX
Expand Down Expand Up @@ -441,7 +440,7 @@ def close_mdns():
self.info = label()
self.info.set_line_wrap(True)
self.info.set_size_request(360, -1)
self.info.modify_fg(Gtk.StateType.NORMAL, red)
modify_fg(self.info, red)
vbox.pack_start(self.info)

# Buttons:
Expand Down Expand Up @@ -938,7 +937,7 @@ def set_widget_bg_color(self, widget, is_error=False):
widget.modify_base(Gtk.StateType.NORMAL, red if is_error else white)

def set_widget_fg_color(self, widget, is_error=False):
widget.modify_fg(Gtk.StateType.NORMAL, red if is_error else black)
modify_fg(widget, red if is_error else black)


def update_options_from_gui(self):
Expand Down
5 changes: 2 additions & 3 deletions xpra/gtk/dialogs/confirm_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from xpra.gtk.signals import register_os_signals
from xpra.gtk.gtk_util import add_close_accel, color_parse
from xpra.gtk.widget import label
from xpra.gtk.widget import label, modify_fg
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.platform.gui import force_focus
from xpra.os_util import get_util_logger
Expand Down Expand Up @@ -43,8 +43,7 @@ def __init__(self, title="Title", prompt="", info=(), icon="", buttons=()):
def al(text, font="sans 14", xalign=0.0):
l = label(text, font=font)
if label.startswith("WARNING"):
red = color_parse("red")
l.modify_fg(Gtk.StateType.NORMAL, red)
modify_fg(l, color_parse("red"))
al = Gtk.Alignment(xalign=xalign, yalign=0.5, xscale=0.0, yscale=0)
al.add(l)
al.show_all()
Expand Down
72 changes: 38 additions & 34 deletions xpra/gtk/dialogs/open_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from xpra.net.file_transfer import ACCEPT, OPEN, DENY
from xpra.util.stats import std_unit, std_unit_dec
from xpra.gtk.gtk_util import add_close_accel
from xpra.gtk.widget import scaled_image, label, TableBuilder
from xpra.gtk.widget import scaled_image, label
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.platform.gui import set_window_progress
from xpra.platform.paths import get_download_dir
Expand Down Expand Up @@ -49,7 +49,7 @@ def __init__(self, show_file_upload_cb=None, cancel_download=None):
self.show_file_upload_cb = show_file_upload_cb
self.cancel_download = cancel_download
self.populate_timer = 0
self.table = None
self.contents = None
self.requests = []
self.expire_labels = {}
self.progress_bars = {}
Expand Down Expand Up @@ -126,44 +126,48 @@ def update_expires_label(self) -> bool:
return False

def populate_table(self):
if self.table:
self.alignment.remove(self.table)
if self.contents:
self.alignment.remove(self.contents)
#remove expired requests:
now = monotonic()
self.requests = [x for x in self.requests if x[-1]>now]
if not self.requests:
self.contents = label("No requests pending", font="sans 18")
self.alignment.add(self.contents)
self.contents.show()
return
self.expire_labels = {}
tb = TableBuilder(rows=1, columns=4, row_spacings=15)
#generate a new table:
self.table = tb.get_table()
grid = Gtk.Grid()
def l(s=""): # noqa: E743
return label(s)
if not self.requests:
tb.add_row(l("No requests pending"))
else:
headers = [l("URL / Filename"), l(), l("Expires in"), l("Action")]
tb.add_row(*headers)
for cb_answer, send_id, dtype, url, filesize, printit, openit, expires in self.requests:
details = ""
if dtype=="file" and filesize>0:
details = "%sB" % std_unit_dec(filesize)
expires_label = l()
self.expire_labels[send_id] = (expires_label, expires)
buttons = self.action_buttons(cb_answer, send_id, dtype, printit, openit)
s = bytestostr(url)
main_label = l(s)
if dtype=="url" and s.find("?")>0 and len(s)>48:
parts = s.split("?", 1)
main_label.set_label(parts[0]+"?..")
main_label.set_tooltip_text(s)
main_label.set_line_wrap(True)
main_label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) # @UndefinedVariable
main_label.set_size_request(URI_MAX_WIDTH, -1)
main_label.set_selectable(True)
items = (main_label, l(details), expires_label, buttons)
tb.add_row(*items)
self.update_expires_label()
self.alignment.add(self.table)
self.table.show_all()
for i, text in enumerate(("URL / Filename", "", "Expires in", "Action")):
grid.attach(l(text), i, 0, 1, 1)
row = 1
for cb_answer, send_id, dtype, url, filesize, printit, openit, expires in self.requests:
details = ""
if dtype=="file" and filesize>0:
details = "%sB" % std_unit_dec(filesize)
expires_label = l()
self.expire_labels[send_id] = (expires_label, expires)
buttons = self.action_buttons(cb_answer, send_id, dtype, printit, openit)
s = bytestostr(url)
main_label = l(s)
if dtype=="url" and s.find("?")>0 and len(s)>48:
parts = s.split("?", 1)
main_label.set_label(parts[0]+"?..")
main_label.set_tooltip_text(s)
main_label.set_line_wrap(True)
main_label.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR) # @UndefinedVariable
main_label.set_size_request(URI_MAX_WIDTH, -1)
main_label.set_selectable(True)
items = (main_label, l(details), expires_label, buttons)
for i, widget in enumerate(items):
grid.attach(widget, i, row, 1, 1)
row += 1
self.update_expires_label()
self.alignment.add(grid)
grid.show_all()
self.contents = grid

def remove_entry(self, send_id, can_close=True):
self.expire_labels.pop(send_id, None)
Expand Down
39 changes: 21 additions & 18 deletions xpra/gtk/dialogs/server_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from xpra.gtk.signals import register_os_signals
from xpra.util.types import typedict, AdHocStruct
from xpra.gtk.gtk_util import add_close_accel
from xpra.gtk.widget import scaled_image, label, TableBuilder
from xpra.gtk.widget import scaled_image, label
from xpra.gtk.pixbuf import get_icon_pixbuf, get_pixbuf_from_data
from xpra.log import Logger, enable_debug_for

Expand All @@ -33,7 +33,7 @@ def __init__(self, client):
self.client = client
self.populate_timer = 0
self.commands_info = {}
self.table = None
self.contents = None
self.window = Gtk.Window()
self.window.set_border_width(20)
self.window.connect("delete-event", self.close)
Expand Down Expand Up @@ -82,17 +82,20 @@ def populate_table(self):
if self.commands_info!=commands_info and commands_info:
log("populate_table() new commands_info=%s", commands_info)
self.commands_info = commands_info
if self.table:
self.alignment.remove(self.table)
tb = TableBuilder(rows=1, columns=2, row_spacings=15)
self.table = tb.get_table()
if self.contents:
self.alignment.remove(self.contents)
grid = Gtk.Grid()
def l(s=""): # noqa: E743
return label(s)
headers = [l(), l("PID"), l("Command"), l("Exit Code")]
widget = label(s)
widget.set_margin_start(5)
widget.set_margin_end(5)
return widget
headers = ["", "PID", "Command", "Exit Code"]
if self.client.server_commands_signals:
headers.append(l("Send Signal"))
tb.add_row(*headers)
for procinfo in self.commands_info.values():
headers.append("Send Signal")
for i, text in enumerate(headers):
grid.attach(l(text), i, 0, 1, 1)
for row, procinfo in enumerate(self.commands_info.values()):
if not isinstance(procinfo, dict):
continue
#some records aren't procinfos:
Expand Down Expand Up @@ -128,15 +131,15 @@ def l(s=""): # noqa: E743
icon.set_from_pixbuf(pixbuf)
except Exception:
log("failed to get window icon", exc_info=True)
items = [icon, l(f"{pid}"), l(cmd_str), l(rstr)]
widgets = [icon, l(f"{pid}"), l(cmd_str), l(rstr)]
if self.client.server_commands_signals:
if returncode is None:
items.append(self.signal_button(pid))
else:
items.append(l())
tb.add_row(*items)
self.alignment.add(self.table)
self.table.show_all()
widgets.append(self.signal_button(pid))
for i, widget in enumerate(widgets):
grid.attach(widget, i, 1+row, 1, 1)
self.alignment.add(grid)
grid.show_all()
self.contents = grid
self.client.send_info_request()
return True

Expand Down
6 changes: 3 additions & 3 deletions xpra/gtk/dialogs/session_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
from xpra.util.str_fn import csv
from xpra.util.env import envint
from xpra.common import noop
from xpra.gtk.graph import make_graph_imagesurface
from xpra.util.stats import values_to_scaled_values, values_to_diff_scaled_values, to_std_unit, std_unit_dec, std_unit
from xpra.client.gui import features
from xpra.client.base.gobject_client import InfoTimerClient
from xpra.gtk.gtk_util import add_close_accel
from xpra.gtk.widget import imagebutton, label, TableBuilder
from xpra.gtk.graph import make_graph_imagesurface
from xpra.gtk.widget import imagebutton, label, TableBuilder, modify_fg
from xpra.gtk.pixbuf import get_icon_pixbuf
from xpra.log import Logger

Expand All @@ -49,7 +49,7 @@ def make_datetime(date, time):
def title_box(label_str):
eb = Gtk.EventBox()
l = label(label_str)
l.modify_fg(Gtk.StateType.NORMAL, Gdk.Color(red=48*256, green=0, blue=0))
modify_fg(l, Gdk.Color(red=48*256, green=0, blue=0))
al = Gtk.Alignment(xalign=0.0, yalign=0.5, xscale=0.0, yscale=0.0)
al.set_padding(0, 0, 10, 10)
al.add(l)
Expand Down
Loading

0 comments on commit fa5646a

Please sign in to comment.