Commit 835c07ea authored by Roman Alifanov's avatar Roman Alifanov

new widget - NumStepper

parent 84da74a8
......@@ -27,12 +27,23 @@ class Setting:
if self.type == 'choice':
# Дефолтная карта для выборов
map = {}
range = self._get_backend_range()
range = self._get_backend_range()[1]
for var in range:
print(var)
map[var[0].upper() + var[1:]] = var
return map
if self.type == 'number':
map = {}
range = self._get_backend_range()[1]
map["upper"] = range[1]
map["lower"] = range[0]
# Кол-во после запятой
map["digits"] = len(str(range[0]).split('.')[-1]) if '.' in str(range[0]) else 0
# Минимальное число с этим количеством
map["step"] = 10 ** -map["digits"] if map["digits"] > 0 else 0
return map
return {}
def create_row(self):
......
......@@ -31,7 +31,7 @@ class GSettingsBackend(Backend):
print(f"[DEBUG] Получение значения: schema={schema_name}, key={key_name}, gtype={gtype}")
try:
value = schema.get_range(key_name)
return value.unpack()[1]
return value.unpack()
except Exception as e:
print(f"[ERROR] Ошибка при получении значения {key}: {e}")
return None
......
from docutils.nodes import subtitle
from gi.repository import Adw, Gtk
from .BaseWidget import BaseWidget
class NumStepper(BaseWidget):
def create_row(self):
map = self.setting.map
map_keys = list(self.setting.map.keys())
row = Adw.SpinRow(
title=self.setting.name, subtitle=self.setting.help
)
adjustment = Gtk.Adjustment(
value=self.setting._get_backend_value(),
lower=map["lower"], upper=map["upper"],
step_increment=map["step"],
)
row.set_adjustment(adjustment)
if "digits" in map_keys:
row.set_digits(map["digits"])
adjustment.connect("value_changed", self._on_num_changed)
return row
def _on_num_changed(self, adj):
selected_value = adj.get_value()
self.setting._set_backend_value(selected_value)
from .BooleanWidget import BooleanWidget
from .ChoiceWidget import ChoiceWidget
from .EntryWidget import EntryWidget
from .NumStepper import NumStepper
class WidgetFactory:
widget_map = {
'choice': ChoiceWidget,
'boolean': BooleanWidget,
'entry': EntryWidget
'entry': EntryWidget,
'number': NumStepper,
}
@staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment