Return to repo list

opet

Oblivion Proton .esp Tool
Return to HMagellan.com

commit 03ec778ae15a7921d4714b3a8626a1bc838fee26
parent 8c78a7c5d7e1a3322ba47b9f622efd61a69afd39
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  9 Jan 2021 16:01:09 -0600

improved list ordering

Diffstat:
Msrc/datas.py | 2++
Msrc/opet.py | 37+++++++++++++++++++++++++++++++------
Msrc/wxcustom.py | 5+++--
3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/src/datas.py b/src/datas.py @@ -32,3 +32,5 @@ class OrderList(object): def get_data(self): return self.data + def set_data(self, data): + self.data = data diff --git a/src/opet.py b/src/opet.py @@ -127,25 +127,50 @@ class OPETFrame(wx.Frame): self.esp_list_ctrl.Append(entry) if e["enabled"]: self.esp_list_ctrl.CheckItem(int(e["order"]), True) + self.manager.esp_data.set_data(data) def sort_esp_data_by_order(self, data): - return sorted(data, key=lambda k: k["order"]) + simsor = sorted(data, key=lambda k: k["order"]) + j = None + for i in simsor: + if i["just_changed"]: + if j["order"] == i["order"]: + j["order"] += 1 + elif j != None and j["just_changed"]: + if i["order"] == j["order"]: + i["order"] -= 1 + j = i + simsor = sorted(data, key=lambda k: k["order"]) + oldor = -1 + for i in simsor: + if i["order"] != oldor + 1: + i["order"] = oldor + 1 + oldor = i["order"] + return simsor # TODO: Cross-object binding issues indicate larger program construction problems??? def OnApplyChanges(self, event): self.manager.esp_tool.assign_load_order(self.manager.esp_data.get_data(), self.manager.environment) def OnEndLabelEdit(self, event): if event.GetColumn() == 1: - if self.esp_list_ctrl.last_order_value != None and int(event.GetLabel()) != self.esp_list_ctrl.last_order_value: - self.esp_list_ctrl.SetItem(event.GetIndex(), event.GetColumn(), str(event.GetLabel())) - count = self.esp_list_ctrl.GetItemCount() + try: + lbint = int(event.GetLabel()) + except ValueError: + lbint = int(self.esp_list_ctrl.GetItem(event.GetItem(), event.GetColumn())) + if lbint < 0: + lbint = 0 + if self.esp_list_ctrl.last_order_value != None and int(lbint) != self.esp_list_ctrl.last_order_value: + self.esp_list_ctrl.SetItem(event.GetIndex(), event.GetColumn(), str(lbint)) + # TODO: This is a bit fragile and relies on file names... + entry = self.esp_list_ctrl.GetItem(event.GetIndex(), col = 2).GetText() data = [] - for row in range(count): + for row in range(self.esp_list_ctrl.GetItemCount()): n = self.esp_list_ctrl.GetItem(row, col = 2).GetText() o = int(self.esp_list_ctrl.GetItem(row, col = 1).GetText()) e = self.esp_list_ctrl.IsItemChecked(row) c = self.esp_list_ctrl.GetItem(row, col = 3).GetText() - dd = {"name" : n, "order" : o, "enabled" : e, "comments" : c} + j = True if n == entry else False + dd = {"name" : n, "order" : o, "enabled" : e, "comments" : c, "just_changed" : j} data.append(dd) self.update_esp_list(self.sort_esp_data_by_order(data)) event.Veto() diff --git a/src/wxcustom.py b/src/wxcustom.py @@ -43,13 +43,14 @@ class ESPListCtrl(wx.ListCtrl, listctrl.TextEditMixin, listctrl.ListCtrlAutoWidt def OnBeginLabelEdit(self, event): col = event.GetColumn() + fi = self.GetFocusedItem() if col == 0: event.Veto() - fi = self.GetFocusedItem() if fi != -1: self.CheckItem(fi, not self.IsItemChecked(fi)) elif col == 1: - self.last_order_value = int(self.GetItem(self.GetFocusedItem(), 1).GetText()) + if fi != -1: + self.last_order_value = int(self.GetItem(fi, 1).GetText()) event.Skip() elif col == 2: event.Veto()