1
0
Fork 0
mirror of https://github.com/aclist/dztui.git synced 2024-12-29 13:52:03 +01:00

fix: handle floats

This commit is contained in:
aclist 2024-01-13 04:58:18 +09:00
parent 43087b44d4
commit d214d40ad5
2 changed files with 52 additions and 30 deletions

View file

@ -291,7 +291,7 @@ list_mods(){
name=$(awk -F\" '/name/ {print $2}' "${dir}/meta.cpp") name=$(awk -F\" '/name/ {print $2}' "${dir}/meta.cpp")
base_dir=$(basename $(readlink -f $game_dir/$symlink)) base_dir=$(basename $(readlink -f $game_dir/$symlink))
size=$(du -s "$(readlink -f "$game_dir/$symlink")" | awk '{print $1}') size=$(du -s "$(readlink -f "$game_dir/$symlink")" | awk '{print $1}')
size=$(echo "scale=4; ($size / 1024) + .005" | bc) size=$(python3 -c "n=($size/1024) +.005; print(round(n,4))")
printf "%s$sep%s$sep%s$sep%3.3f\n" "$name" "$symlink" "$base_dir" "$size" printf "%s$sep%s$sep%s$sep%3.3f\n" "$name" "$symlink" "$base_dir" "$size"
done | sort -k1 done | sort -k1
fi fi

View file

@ -118,9 +118,9 @@ filters = {
"Night": True, "Night": True,
"Empty": False, "Empty": False,
"Full": False, "Full": False,
"Low population": True, "Low pop": True,
"Non-ASCII": False, "Non-ASCII": False,
"Duplicate names": False "Duplicate": False
} }
side_buttons = [ side_buttons = [
"Connect", "Connect",
@ -441,6 +441,7 @@ class OuterWindow(Gtk.Window):
self.connect("delete-event", self.halt_proc_and_quit) self.connect("delete-event", self.halt_proc_and_quit)
# Deprecated in GTK 4.0 # Deprecated in GTK 4.0
self.set_border_width(10) self.set_border_width(10)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
""" """
app > win > grid > scrollable > treeview [row/server/mod store] app > win > grid > scrollable > treeview [row/server/mod store]
@ -462,31 +463,39 @@ class OuterWindow(Gtk.Window):
class ScrollableTree(Gtk.ScrolledWindow): class ScrollableTree(Gtk.ScrolledWindow):
def __init__(self): def __init__(self, is_steam_deck):
super().__init__() super().__init__()
#self.set_propagate_natural_height(False)
self.set_vexpand(False) self.set_vexpand(False)
self.treeview = TreeView() self.treeview = TreeView(is_steam_deck)
self.add(self.treeview) self.add(self.treeview)
class RightPanel(Gtk.Box): class RightPanel(Gtk.Box):
def __init__(self): def __init__(self, is_steam_deck):
super().__init__(spacing=6) super().__init__(spacing=6)
self.set_orientation(Gtk.Orientation.VERTICAL) self.set_orientation(Gtk.Orientation.VERTICAL)
self.button_vbox = ButtonBox() self.button_vbox = ButtonBox(is_steam_deck)
self.filters_vbox = FilterPanel() self.filters_vbox = FilterPanel()
toggle_signal(self.filters_vbox, self.filters_vbox.maps_combo, '_on_map_changed', False) toggle_signal(self.filters_vbox, self.filters_vbox.maps_combo, '_on_map_changed', False)
self.pack_start(self.button_vbox, False, False, 0) self.pack_start(self.button_vbox, False, False, 0)
self.pack_start(self.filters_vbox, False, False, 0) self.pack_start(self.filters_vbox, False, False, 0)
self.question_label = Gtk.Label(label="Type ? for keybindings") self.question_button = Gtk.Button(label="?")
self.question_label.set_ellipsize(Pango.EllipsizeMode.END) #TODO: too big on top
self.question_label.set_margin_top(100) self.question_button.set_margin_top(10)
self.question_label.set_margin_start(10) self.question_button.set_margin_start(50)
self.pack_start(self.question_label, False, True, 0) self.question_button.set_margin_end(50)
# set_surrounding_margins(self.question_label, 50)
self.pack_start(self.question_button, False, True, 0)
self.question_button.connect("clicked", self._on_button_clicked)
def _on_button_clicked(self, button):
grid = self.get_parent()
grid.scrollable_treelist.treeview.spawn_keys_dialog(button)
def set_filter_visibility(self, bool): def set_filter_visibility(self, bool):
self.filters_vbox.set_visible(bool) self.filters_vbox.set_visible(bool)
@ -499,7 +508,7 @@ class RightPanel(Gtk.Box):
class ButtonBox(Gtk.Box): class ButtonBox(Gtk.Box):
def __init__(self): def __init__(self, is_steam_deck):
super().__init__(spacing=6) super().__init__(spacing=6)
self.set_orientation(Gtk.Orientation.VERTICAL) self.set_orientation(Gtk.Orientation.VERTICAL)
set_surrounding_margins(self, 10) set_surrounding_margins(self, 10)
@ -507,7 +516,7 @@ class ButtonBox(Gtk.Box):
self.buttons = list() self.buttons = list()
for side_button in side_buttons: for side_button in side_buttons:
button = Gtk.Button(label=side_button) button = Gtk.Button(label=side_button)
button.set_size_request(100, 100) button.set_size_request(50, 50)
button.set_opacity(0.6) button.set_opacity(0.6)
self.buttons.append(button) self.buttons.append(button)
button.connect("clicked", self._on_selection_button_clicked) button.connect("clicked", self._on_selection_button_clicked)
@ -556,7 +565,7 @@ class ButtonBox(Gtk.Box):
if context == "Exit": if context == "Exit":
logger.info("Normal user exit") logger.info("Normal user exit")
sys.exit(1) Gtk.main_quit()
cols = treeview.get_columns() cols = treeview.get_columns()
if len(cols) > 1: if len(cols) > 1:
@ -609,7 +618,7 @@ class CalcDist(multiprocessing.Process):
class TreeView(Gtk.TreeView): class TreeView(Gtk.TreeView):
__gsignals__ = {"on_distcalc_started": (GObject.SignalFlags.RUN_FIRST, None, ())} __gsignals__ = {"on_distcalc_started": (GObject.SignalFlags.RUN_FIRST, None, ())}
def __init__(self): def __init__(self, is_steam_deck):
super().__init__() super().__init__()
self.queue = multiprocessing.Queue() self.queue = multiprocessing.Queue()
@ -631,7 +640,8 @@ class TreeView(Gtk.TreeView):
column = Gtk.TreeViewColumn(column_title, renderer, text=i) column = Gtk.TreeViewColumn(column_title, renderer, text=i)
self.append_column(column) self.append_column(column)
# TODO: change font size on the fly # TODO: change font size on the fly
# renderer.set_property("size-points", 20) if is_steam_deck is True:
renderer.set_property("size-points", 20)
self.connect("row-activated", self._on_row_activated) self.connect("row-activated", self._on_row_activated)
self.connect("key-press-event", self._on_keypress) self.connect("key-press-event", self._on_keypress)
@ -788,6 +798,12 @@ class TreeView(Gtk.TreeView):
tooltip = format_metadata(row_sel) tooltip = format_metadata(row_sel)
grid.update_statusbar(tooltip) grid.update_statusbar(tooltip)
def spawn_keys_dialog(self, widget):
diag = KeysDialog(self.get_outer_window(), '', "Keybindings")
diag.run()
diag.destroy()
self.grab_focus()
def _on_keypress_main_menu(self, treeview, event): def _on_keypress_main_menu(self, treeview, event):
window = self.get_outer_window() window = self.get_outer_window()
grid = self.get_outer_grid() grid = self.get_outer_grid()
@ -796,9 +812,7 @@ class TreeView(Gtk.TreeView):
grid.right_panel.focus_button_box() grid.right_panel.focus_button_box()
case Gdk.KEY_question: case Gdk.KEY_question:
if event.state is Gdk.ModifierType.SHIFT_MASK: if event.state is Gdk.ModifierType.SHIFT_MASK:
diag = KeysDialog(window, '', "Keybindings") self.spawn_keys_dialog(None)
diag.run()
diag.destroy()
case Gdk.KEY_f: case Gdk.KEY_f:
if event.state is Gdk.ModifierType.CONTROL_MASK: if event.state is Gdk.ModifierType.CONTROL_MASK:
return True return True
@ -902,11 +916,11 @@ class TreeView(Gtk.TreeView):
renderer = Gtk.CellRendererText() renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(column_title, renderer, text=i) column = Gtk.TreeViewColumn(column_title, renderer, text=i)
column.set_sort_column_id(i) column.set_sort_column_id(i)
"""Prevent columns from auto-adjusting""" #"""Prevent columns from auto-adjusting"""
if ("Name" in column_title): if ("Name" in column_title):
column.set_fixed_width(800) column.set_fixed_width(800)
if (column_title == "Map"): #if (column_title == "Map"):
column.set_fixed_width(300) # column.set_fixed_width(300)
self.append_column(column) self.append_column(column)
self.update_first_col(mode) self.update_first_col(mode)
@ -962,8 +976,8 @@ class TreeView(Gtk.TreeView):
if i == 3: if i == 3:
column.set_cell_data_func(renderer, self._format_float, func_data=None) column.set_cell_data_func(renderer, self._format_float, func_data=None)
column.set_sort_column_id(i) column.set_sort_column_id(i)
if (column_title == "Name"): #if (column_title == "Name"):
column.set_fixed_width(600) # column.set_fixed_width(600)
self.append_column(column) self.append_column(column)
if mode == "List installed mods": if mode == "List installed mods":
@ -1380,17 +1394,24 @@ class Grid(Gtk.Grid):
self.set_column_homogeneous(True) self.set_column_homogeneous(True)
#self.set_row_homogeneous(True) #self.set_row_homogeneous(True)
self.scrollable_treelist = ScrollableTree()
self.scrollable_treelist.set_vexpand(True)
self.right_panel = RightPanel()
_news = sys.argv[2] _news = sys.argv[2]
_isd = sys.argv[3]
self._version = "%s %s" %(app_name, sys.argv[3]) self._version = "%s %s" %(app_name, sys.argv[3])
if _isd == 1:
is_steam_deck = True
else:
is_steam_deck = False
if _news != "null": if _news != "null":
self.news = NewsHeader(_news) self.news = NewsHeader(_news)
self.attach(self.news, 0, -1, 8, 10) self.attach(self.news, 0, -1, 8, 10)
self.scrollable_treelist = ScrollableTree(is_steam_deck)
self.scrollable_treelist.set_vexpand(True)
self.right_panel = RightPanel(is_steam_deck)
self.bar = Gtk.Statusbar() self.bar = Gtk.Statusbar()
self.scrollable_treelist.treeview.connect("on_distcalc_started", self._on_calclat_started) self.scrollable_treelist.treeview.connect("on_distcalc_started", self._on_calclat_started)
@ -1464,7 +1485,8 @@ class App(Gtk.Application):
# TODO: steam deck # TODO: steam deck
# self.win.set_size_request(1280,800) # self.win.set_size_request(1280,800)
self.win.fullscreen() #self.win.fullscreen()
self.win.set_keep_below(True)
accel = Gtk.AccelGroup() accel = Gtk.AccelGroup()
accel.connect(Gdk.KEY_q, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE, self._halt_window_subprocess) accel.connect(Gdk.KEY_q, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE, self._halt_window_subprocess)