Skip to content

Commit

Permalink
Fixed find/replace dialogs to work on int/hex/float
Browse files Browse the repository at this point in the history
  • Loading branch information
KyonkoYuuki committed Oct 29, 2020
1 parent 822a6ac commit 3c30a70
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ This tool is here to help out with creating and modifying BCMs. In addition to g
0.2.2 - Add automatic backup creation on saving
0.2.3 - Improved editing performance with very large BCM's, fixed child/sibling indexes cutting off at 32767
0.2.4 - Added primary activator conditions
0.2.5 - Fixed find/replace dialogs so it works with int/hex/float
```
2 changes: 1 addition & 1 deletion YaBCM Organizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from yabcm.dlg.replace import ReplaceDialog
from pyxenoverse.gui.file_drop_target import FileDropTarget

VERSION = '0.2.4'
VERSION = '0.2.5'


class MainWindow(wx.Frame):
Expand Down
26 changes: 15 additions & 11 deletions yabcm/dlg/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def find(self, selected, entry_type, find):
item = get_next_item(self.entry_list, selected)
while item != selected:
data = self.entry_list.GetItemData(item)
if data[entry_type] == find:
if find is None or data[entry_type] == find or (
isinstance(data[entry_type], float) and abs(data[entry_type] - find) < 0.000001):
self.select_found(item, entry_type)
break

Expand All @@ -113,18 +114,21 @@ def find(self, selected, entry_type, find):

def on_find(self, _):
entry_type = self.choices[self.entry.GetSelection()]
value = self.find_ctrl.GetValue()
if value:
try:
find = int(value, 0)
except ValueError:
self.status_bar.SetStatusText("Invalid Value")
return
else:
find = None
value = None
try:
value = self.get_value(self.find_ctrl)
except ValueError:
self.status_bar.SetStatusText("Invalid Value")
selected = self.entry_list.GetSelections()
if len(selected) == 1 and selected[0] != self.entry_list.GetRootItem():
selected = selected[0]
else:
selected = get_first_item(self.entry_list)[0]
self.find(selected, entry_type, find)
self.find(selected, entry_type, value)

@staticmethod
def get_value(ctrl):
value = ctrl.GetValue()
if value.startswith('0x'):
return int(value, 16)
return float(value)
11 changes: 6 additions & 5 deletions yabcm/dlg/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __init__(self, parent, entry_list, *args, **kw):
def on_replace(self, _):
entry_type = self.choices[self.entry.GetSelection()]
try:
find = int(self.find_ctrl.GetValue(), 0)
replace = int(self.replace_ctrl.GetValue(), 0)
find = self.get_value(self.find_ctrl)
replace = self.get_value(self.replace_ctrl)
except ValueError:
self.status_bar.SetStatusText("Invalid Value")
return None
Expand All @@ -52,16 +52,17 @@ def on_replace(self, _):
def on_replace_all(self, _):
entry_type = self.choices[self.entry.GetSelection()]
try:
find = int(self.find_ctrl.GetValue(), 0)
replace = int(self.replace_ctrl.GetValue(), 0)
find = self.get_value(self.find_ctrl)
replace = self.get_value(self.replace_ctrl)
except ValueError:
self.status_bar.SetStatusText("Invalid Value")
return None
count = 0
item = get_first_item(self.entry_list)[0]
while item.IsOk():
data = self.entry_list.GetItemData(item)
if data[entry_type] == find:
if data[entry_type] == find or (
isinstance(data[entry_type], float) and abs(data[entry_type] - find) < 0.000001):
data[entry_type] = replace
count += 1
item = get_next_item(self.entry_list, item)
Expand Down

0 comments on commit 3c30a70

Please sign in to comment.