Skip to content

Commit

Permalink
forgot to add the module
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Dec 7, 2023
1 parent 9152e3f commit 8f72bb1
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions xpra/gtk/configure/encodings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# This file is part of Xpra.
# Copyright (C) 2023 Antoine Martin <[email protected]>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.gtk.dialogs.base_gui_window import BaseGUIWindow
from xpra.gtk.configure.common import update_config_attribute, with_config
from xpra.gtk.widget import label
from xpra.os_util import gi_import
from xpra.log import Logger

Gtk = gi_import("Gtk")
GLib = gi_import("GLib")

log = Logger("util")


def adj1_100(value: int) -> Gtk.Adjustment:
return Gtk.Adjustment(value=value, lower=1, upper=100, step_increment=5, page_increment=0, page_size=0)


def make_scale(adjust, marks: dict) -> Gtk.Scale:
scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adjust)
for value, text in marks.items():
scale.add_mark(value=value, position=Gtk.PositionType.TOP, markup=text)
scale.set_digits(0)
scale.set_draw_value(True)
scale.set_has_origin(True)
return scale


class ConfigureGUI(BaseGUIWindow):

def __init__(self, parent: Gtk.Window | None = None):
self.subsystem_switch = {}
super().__init__(
"Configure Xpra's Picture Compression",
"encoding.png",
wm_class=("xpra-configure-encodings-gui", "Xpra Configure Encodings GUI"),
default_size=(640, 500),
header_bar=(True, False),
parent=parent,
)

def populate(self):
with_config(self.do_populate)

def do_populate(self, config):
self.clear_vbox()
self.add_widget(label("Configure Xpra's Picture Compression", font="sans 20"))
url = "https://github.com/Xpra-org/xpra/blob/master/docs/Usage/Encodings.md#tuning"
lines = (
f"Please read <a href='{url}'>the documentation</a>.",
)
text = "\n".join(lines)
lbl = label(text, font="Sans 14")
lbl.set_line_wrap(True)
lbl.set_use_markup(True)
self.add_widget(lbl)
self.add_widget(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
self.add_widget(label("Minimum Speed (percentage)"))
scale = make_scale(adj1_100(config.min_speed), {
1 : "Lowest",
50 : "Average",
100 : "Highest",
})
scale.connect("value-changed", self.speed_changed)
self.add_widget(scale)
self.add_widget(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
self.add_widget(label("Minimum Quality (percentage)"))
scale = make_scale(adj1_100(config.min_quality), {
1 : "Lowest",
50 : "Average",
100 : "Highest",
})
scale.connect("value-changed", self.quality_changed)
self.add_widget(scale)
self.add_widget(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
self.add_widget(label("Auto Refresh Delay (milliseconds)"))
adjust = Gtk.Adjustment(value=config.auto_refresh_delay, lower=0, upper=1000,
step_increment=50, page_increment=0, page_size=0)
scale = make_scale(adjust, {
0 : "Disabled",
50 : "Fast",
500 : "Average",
1000: "Slow",
})
scale.connect("value-changed", self.ar_changed)
self.add_widget(scale)
self.add_widget(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
grid = Gtk.Grid()
grid.set_margin_start(40)
grid.set_margin_end(40)
grid.set_row_homogeneous(True)
grid.set_column_homogeneous(False)
self.add_widget(grid)
switch = Gtk.Switch()
switch.set_state(config.encoding == "grayscale")
switch.connect("state-set", self.toggle_grayscale)
lbl = label("Grayscale Mode")
lbl.set_hexpand(True)
grid.attach(lbl, 0, 0, 1, 1)
grid.attach(switch, 1, 0, 1, 1)
self.show_all()

@staticmethod
def speed_changed(widget):
update_config_attribute("min-speed", int(widget.get_value()))

@staticmethod
def quality_changed(widget):
update_config_attribute("min-quality", int(widget.get_value()))

@staticmethod
def ar_changed(widget):
update_config_attribute("auto-refresh-delay", int(widget.get_value())/1000)

@staticmethod
def toggle_grayscale(_widget, state):
update_config_attribute("encoding", "grayscale" if state else "auto")


def main(_args) -> int:
from xpra.gtk.configure.main import run_gui
return run_gui(ConfigureGUI)


if __name__ == "__main__":
import sys
sys.exit(main(sys.argv[1:]))

0 comments on commit 8f72bb1

Please sign in to comment.