Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering issue #30

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/objdictgen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def list_od(
"""Generator for producing the output for odg list"""

# Get the indexes to print and determine the order
keys = od.GetAllIndices(sort=not opts.no_sort)
keys = od.GetAllIndices(sort=opts.sort)
if opts.index:
indexp = [jsonod.str_to_int(i) for i in opts.index]
keys = [k for k in keys if k in indexp]
Expand Down Expand Up @@ -259,7 +259,7 @@ def main(debugopts: DebugOpts, args: Sequence[str]|None = None):
subp.add_argument('-i', '--index', action="append", help="Specify parameter index to show")
subp.add_argument('--all', action="store_true",
help="Show all subindexes, including subindex 0")
subp.add_argument('--no-sort', action="store_true", help="Do not sort output")
subp.add_argument('--sort', action="store_true", help="Sort output")
subp.add_argument('--compact', action="store_true", help="Compact listing")
subp.add_argument('--raw', action="store_true", help="Show raw parameter values")
subp.add_argument('--short', action="store_true", help="Do not list sub-index")
Expand Down
8 changes: 5 additions & 3 deletions src/objdictgen/ui/objdictedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ def OnSaveAsMenu(self, event): # pylint: disable=unused-argument

def Save(self):
try:
result = self.Manager.SaveCurrentInFile()
# Sort only applies if saving JSON file
result = self.Manager.SaveCurrentInFile(sort=True)
if not result:
self.SaveAs()
else:
Expand Down Expand Up @@ -487,8 +488,9 @@ def SaveAs(self):
display_error_dialog(self, f"'{os.path.dirname(filepath)}' is not a valid folder!")
else:
try:
# Try and save the file and then update the filepath if successfull
if self.Manager.SaveCurrentInFile(filepath):
# Try and save the file and then update the filepath if successful
# Sort only applies if saving JSON file
if self.Manager.SaveCurrentInFile(filepath, sort=True):
self.Manager.SetCurrentFilePath(filepath)
self.RefreshBufferState()
except Exception: # pylint: disable=broad-except
Expand Down
6 changes: 3 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def test_main_list_od(odpath, file):

import argparse
ns = argparse.Namespace(
no_sort=False, index=[], compact=False, short=False, unused=True,
sort=True, index=[], compact=False, short=False, unused=True,
all=True, raw=False
)

lines = list(__main__.list_od(od, file, ns))

ns = argparse.Namespace(
no_sort=False, index=[0x1000], compact=False, short=False, unused=True,
sort=True, index=[0x1000], compact=False, short=False, unused=True,
all=True, raw=False
)

lines = list(__main__.list_od(od, file, ns))

ns = argparse.Namespace(
no_sort=False, index=[0x5000], compact=False, short=False, unused=True,
sort=True, index=[0x5000], compact=False, short=False, unused=True,
all=True, raw=False
)

Expand Down