Return to repo list

opet

Oblivion Proton .esp Tool
Return to HMagellan.com

commit 8c78a7c5d7e1a3322ba47b9f622efd61a69afd39
parent 6409d7c0267753f00575c8ac204a5fa39fc4d4ed
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  9 Jan 2021 15:06:36 -0600

very basic method of setting order

Diffstat:
Msrc/datas.py | 4+++-
Msrc/opet.py | 36++++++++++++++++++++++++++++--------
Msrc/wxcustom.py | 13+++++++++++--
3 files changed, 42 insertions(+), 11 deletions(-)

diff --git a/src/datas.py b/src/datas.py @@ -25,8 +25,10 @@ class OrderList(object): self.init_comments = comments self.data = [] + ind = 0 for e in order: - self.data.append({ "name" : e, "enabled" : True if e in enabled else False, "comments" : comments[e] if e in comments.keys() else "" }) + self.data.append({ "name" : e, "order" : ind, "enabled" : True if e in enabled else False, "comments" : comments[e] if e in comments.keys() else "" }) + ind += 1 def get_data(self): return self.data diff --git a/src/opet.py b/src/opet.py @@ -110,14 +110,8 @@ class OPETFrame(wx.Frame): self.esp_list_sizer = wx.BoxSizer(wx.VERTICAL) self.esp_list_panel.SetSizer(self.esp_list_sizer) self.esp_list_ctrl = wxcustom.ESPListCtrl(self.esp_list_panel, size = (500, 400)) - index = 0 - esp_data = self.manager.esp_data.get_data() - for e in esp_data: - entry = ["", index, e["name"], e["comments"]] - self.esp_list_ctrl.Append(entry) - if e["enabled"]: - self.esp_list_ctrl.CheckItem(index, True) - index += 1 + self.esp_list_ctrl.Bind(wx.EVT_LIST_END_LABEL_EDIT, self.OnEndLabelEdit) + self.update_esp_list(self.manager.esp_data.get_data()) self.esp_buttons_panel = wx.Panel(self.sub_panel) self.esp_buttons_panel_sizer = wx.BoxSizer(wx.HORIZONTAL) self.esp_buttons_panel.SetSizer(self.esp_buttons_panel_sizer) @@ -126,9 +120,35 @@ class OPETFrame(wx.Frame): self.esp_list_panel.SetSize(4, 4, 550, 450) self.esp_buttons_panel.SetSize(4, 430, 550, 200) + def update_esp_list(self, data): + self.esp_list_ctrl.DeleteAllItems() + for e in data: + entry = ["", e["order"], e["name"], e["comments"]] + self.esp_list_ctrl.Append(entry) + if e["enabled"]: + self.esp_list_ctrl.CheckItem(int(e["order"]), True) + + def sort_esp_data_by_order(self, data): + return sorted(data, key=lambda k: k["order"]) + # 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() + data = [] + for row in range(count): + 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} + data.append(dd) + self.update_esp_list(self.sort_esp_data_by_order(data)) + event.Veto() def on_new_profile(self, event): pass diff --git a/src/wxcustom.py b/src/wxcustom.py @@ -29,6 +29,9 @@ class ESPListCtrl(wx.ListCtrl, listctrl.TextEditMixin, listctrl.ListCtrlAutoWidt # Set values self.EnableCheckBoxes(True) + # Dynamics + self.last_order_value = None + # Columns self.InsertColumn(0, "Enabled") self.InsertColumn(1, "Order") @@ -39,14 +42,20 @@ class ESPListCtrl(wx.ListCtrl, listctrl.TextEditMixin, listctrl.ListCtrlAutoWidt self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit) def OnBeginLabelEdit(self, event): - if event.GetColumn() == 0: + col = event.GetColumn() + 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()) + event.Skip() + elif col == 2: + event.Veto() else: event.Skip() - + class ESPApplyButton(wx.Button): """ The ESPApplyButton is used to apply