Return to repo list

opet

Oblivion Proton .esp Tool
Return to HMagellan.com

commit 4a4602aacd147d8638d8c4438209fc4c0e10eaca
parent 03ec778ae15a7921d4714b3a8626a1bc838fee26
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sat,  9 Jan 2021 17:25:11 -0600

now applies enable changes

Diffstat:
Msrc/datas.py | 2+-
Msrc/opet.py | 33++++++++++++++++++++++++++++++---
Msrc/tools.py | 10++++++++++
Msrc/wxcustom.py | 19-------------------
4 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/src/datas.py b/src/datas.py @@ -27,7 +27,7 @@ class OrderList(object): self.data = [] ind = 0 for e in order: - self.data.append({ "name" : e, "order" : ind, "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 "", "just_changed" : False }) ind += 1 def get_data(self): diff --git a/src/opet.py b/src/opet.py @@ -110,6 +110,7 @@ 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)) + self.esp_list_ctrl.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit) 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) @@ -130,6 +131,7 @@ class OPETFrame(wx.Frame): self.manager.esp_data.set_data(data) def sort_esp_data_by_order(self, data): + # TODO: This is terrible and inefficient simsor = sorted(data, key=lambda k: k["order"]) j = None for i in simsor: @@ -150,7 +152,32 @@ class OPETFrame(wx.Frame): # TODO: Cross-object binding issues indicate larger program construction problems??? def OnApplyChanges(self, event): + data = [] + 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, "just_changed" : False } + data.append(dd) + self.update_esp_list(self.sort_esp_data_by_order(data)) self.manager.esp_tool.assign_load_order(self.manager.esp_data.get_data(), self.manager.environment) + self.manager.esp_tool.enable_esps(self.manager.esp_data.get_data(), self.manager.environment) + def OnBeginLabelEdit(self, event): + col = event.GetColumn() + fi = self.esp_list_ctrl.GetFocusedItem() + if col == 0: + event.Veto() + if fi != -1: + self.esp_list_ctrl.CheckItem(fi, not self.esp_list_ctrl.IsItemChecked(fi)) + elif col == 1: + if fi != -1: + self.last_order_value = int(self.esp_list_ctrl.GetItem(fi, 1).GetText()) + event.Skip() + elif col == 2: + event.Veto() + else: + event.Skip() def OnEndLabelEdit(self, event): if event.GetColumn() == 1: try: @@ -159,7 +186,7 @@ class OPETFrame(wx.Frame): 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: + if self.esp_list_ctrl.last_order_value != None and 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() @@ -169,8 +196,8 @@ class OPETFrame(wx.Frame): 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() - j = True if n == entry else False - dd = {"name" : n, "order" : o, "enabled" : e, "comments" : c, "just_changed" : j} + 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/tools.py b/src/tools.py @@ -43,3 +43,13 @@ class DataPackTool(object): for e in orderlist: os.utime(os.path.join(os.path.expanduser(environment["OblivionDataPath"]), e["name"])) time.sleep(0.01) + + def enable_esps(self, enablelist, environment): + """ + Enable the given ESPs. + """ + with open(os.path.join(os.path.expanduser(environment["OblivionPrefixAppdata"]), "Plugins.txt"), "w") as f: + for e in enablelist: + if e["enabled"]: + f.write(e["name"] + '\n') + diff --git a/src/wxcustom.py b/src/wxcustom.py @@ -38,25 +38,6 @@ class ESPListCtrl(wx.ListCtrl, listctrl.TextEditMixin, listctrl.ListCtrlAutoWidt self.InsertColumn(2, "File") self.InsertColumn(3, "Comment") - # Binds - self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginLabelEdit) - - def OnBeginLabelEdit(self, event): - col = event.GetColumn() - fi = self.GetFocusedItem() - if col == 0: - event.Veto() - if fi != -1: - self.CheckItem(fi, not self.IsItemChecked(fi)) - elif col == 1: - if fi != -1: - self.last_order_value = int(self.GetItem(fi, 1).GetText()) - event.Skip() - elif col == 2: - event.Veto() - else: - event.Skip() - class ESPApplyButton(wx.Button): """ The ESPApplyButton is used to apply