Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
434 commits
Select commit Hold shift + click to select a range
b7fd39a
Provide default group, and disable the option.
Aug 9, 2024
eba0ed5
Added a placeholder for the search box.
Aug 9, 2024
ddafdda
Simulate having preferred options.
Aug 9, 2024
60ee649
Allow double clicking to select a unit.
Aug 12, 2024
b392695
Have a dictionary for the files loaded.
Aug 12, 2024
6125d86
Get raw_csv based on filename.
Aug 12, 2024
c525e63
Added a filename chooser widget.
Aug 12, 2024
05a487b
Add an event for when the current file changes.
Aug 12, 2024
a83f084
Changed when guesses are attempted.
Aug 12, 2024
c426da3
Track rows is included seperately for each file.
Aug 12, 2024
3fc4350
New widget for unit preferences.
Aug 12, 2024
1e24088
Created a preference line widget.
Aug 12, 2024
e443e40
Add a line for each column.
Aug 12, 2024
50711f3
Forgot to set layout parent.
Aug 12, 2024
0ea0b8d
Again forgot parent :P
Aug 12, 2024
36cbb3e
Put the preferences in a scroll area.
Aug 12, 2024
77b1d8c
Turn off the horizontal scroll.
Aug 12, 2024
37003c8
Added a selection menu widget.
Aug 12, 2024
5fd75e0
Got the context menu to work.
Aug 13, 2024
0e57d9c
Set the checkbox first then update the rest.
Aug 13, 2024
54bf0e3
Use the new list in sasview rather than hardcoding
Aug 13, 2024
51a3423
Removed some unused imports.
Aug 13, 2024
7f21971
Don't enable the select button immediately.
Aug 13, 2024
4ddb385
Unpinned pyside6.
Aug 14, 2024
38deeb3
Fixed typo.
Sep 6, 2024
baf4bd5
Remvoed shabang.
Sep 6, 2024
ac75e4c
Fixed casing.
Sep 6, 2024
8dff30d
Unsplit line.
Sep 9, 2024
e62d67e
Split import into two lines.
Sep 9, 2024
e127495
Looks like a few names didn't change automatically
Sep 9, 2024
521d164
Double clicking a unit selects it.
Sep 9, 2024
e139150
Added an unload button.
Sep 9, 2024
00e6578
Use a horizontal layout.
Sep 9, 2024
18c384b
Handle case where there are no more files.
Sep 9, 2024
9cd1ac3
Disable table when there's no data.
Sep 9, 2024
b21d2de
Handle a unicode decode error.
Sep 9, 2024
4c9e490
Set filename label on update.
Sep 9, 2024
5f5958d
Reset the label back to original after unload.
Sep 9, 2024
03d34ab
For now, ignore the horizontal size hint.
Sep 9, 2024
409b4f6
Fixed error that sometimes happens when selecting.
Sep 9, 2024
f8e9f52
Disable the button when there's none to unload.
Sep 9, 2024
314de06
Set current filename to none when there is none.
Sep 10, 2024
d1f222b
Give a window title.
Sep 10, 2024
b355f0e
Added a done button.
Oct 21, 2024
4a5bfa8
Get the column tuple.
Oct 21, 2024
a028ad6
Make this a property.
Oct 21, 2024
a7ab5e8
Added exclude lines to match param in dataclass.
Oct 21, 2024
def0a6e
Fixed logic error.
Oct 21, 2024
43c22b7
Hook up the done button to an event.
Oct 21, 2024
c57d86b
Fixed slot connection.
Oct 21, 2024
13ab6d3
Ascii dialog is now a dialog not a widget.
Oct 21, 2024
ece282f
I don't think these comments are needed anymore.
Oct 21, 2024
cbca3af
Changed how the current unit is found.
Oct 21, 2024
a05c8fa
Include the selected unit in the options.
Oct 21, 2024
c308ee0
Accept when clicking the done button.
Oct 21, 2024
fcc9ae1
Need to call items in order to destructure.
Oct 21, 2024
bded22a
Just hard code the value.
Oct 21, 2024
4758ce5
Fix excluded_lines.
Oct 21, 2024
aaf1df4
Keep track of the full path.
Oct 21, 2024
a8fb897
Fix the params.
Oct 21, 2024
505e143
Load the data instead of printing params only.
Oct 21, 2024
a456692
Return the unit not the symbol.
Oct 22, 2024
d66f839
Send in an empty dict of metadata for now.
Oct 25, 2024
99ea5d4
Added an edit metadata button.
Oct 25, 2024
e79f2cc
Bring in the files for the metadata filename gui.
Oct 25, 2024
5510c05
Renamed file, and ade it a dialog.
Oct 25, 2024
6b4a19d
Forgot to commit new file.
Oct 25, 2024
5a5d6ce
Added save button.
Oct 25, 2024
8245d65
Hook up the save button to an event.
Oct 25, 2024
641e871
Print out the component metadata on success.
Oct 25, 2024
0ec32a8
Fixed imports.
Oct 25, 2024
c01413b
Add edit metadata button.
Oct 25, 2024
b3585b0
Fixed import.
Oct 25, 2024
f6d151b
Get filename from self.
Oct 25, 2024
598d96d
Created a property for the separator text.
Oct 25, 2024
2e174b4
Added a dict for separators.
Oct 25, 2024
daa8a1c
Take in initial values for these.
Oct 25, 2024
8b999dd
Set the separator field.
Oct 30, 2024
1329566
Pass in previous metadata, using defaults.
Nov 1, 2024
6917bc5
Selected components should persist.
Nov 1, 2024
2764215
Use the actual metadata.
Nov 1, 2024
972085c
Add widget for custom metadata entry.
Nov 1, 2024
be754d2
Changed name to be more consistent.
Nov 1, 2024
dbe0a04
Add a custom entry button to the layout.
Nov 1, 2024
1f1a2ee
Use a signal for when the custom button is pressed
Nov 1, 2024
a5de73e
Started with the selector widget.
Nov 6, 2024
de086fb
Hook up event handlers properly.
Nov 18, 2024
4706dfb
Use the generic selector widget.
Nov 21, 2024
91ced7b
Init the base class.
Nov 21, 2024
162ee2a
Forgot to pass self into layout.
Nov 21, 2024
fffac57
Handle when there is no new widget.
Nov 21, 2024
8f379b9
Use isinstance.
Nov 21, 2024
2763af0
Fixed event handling.
Nov 21, 2024
88e2985
Layout not inited properly.
Nov 21, 2024
6a59019
Need to delete, and reassign selector widget.
Nov 21, 2024
621b330
This line shouldn't be here.
Nov 21, 2024
3c509be
Set the title of the metadata dialog.
Nov 21, 2024
2d37744
Use separate functions for creating these widgets.
Nov 21, 2024
494040d
Use the new function.
Nov 21, 2024
84ca5c9
Removed comment that doesn't make sense anymore.
Nov 22, 2024
c2a4481
Handle value changes.
Nov 22, 2024
60f6c3f
Pass in the new args.
Nov 22, 2024
9740063
Fixed typos in comments.
Nov 22, 2024
5d7c340
Choose default widget based on current option.
Nov 22, 2024
ca46946
Set the field from the already set metadata.
Nov 22, 2024
be5de49
Wrong control.
Nov 22, 2024
24b9a41
Pass raw_metadata into params.
Nov 25, 2024
a95c46d
This should be a TODO comment.
Nov 25, 2024
9a19d02
Updated this map with a todo warning.
Nov 25, 2024
9ff4d5a
Gonna try a different approach.
Nov 25, 2024
09e0759
Fixed bug where not editing metadata wouldn't work
Nov 25, 2024
9f4d0de
Strip all of the lines.
Nov 26, 2024
f6e4214
First step towards a master metadata dictionary.
Nov 27, 2024
256d124
Pass along the master metadata dict.
Nov 28, 2024
4cc3a55
Pass in the master metadata.
Nov 28, 2024
ff2a170
Changed round a bunch of type hints.
Nov 28, 2024
1568867
Master metadata should be the same for all files.
Dec 2, 2024
13d82b7
Give the master metadata a default value.
Dec 2, 2024
17826bd
This should be type hinted.
Dec 2, 2024
3d0d9d2
Remove the metadata dict param.
Dec 2, 2024
2dd581e
I think these are the wrong way round.
Dec 2, 2024
67be830
Give the master metadata to metadata filename.
Dec 2, 2024
a8d6670
Create some classes for metadata.
Dec 2, 2024
9acab29
Remove unneeded import.
Dec 2, 2024
f67e460
Implemented get_metadata function.
Dec 2, 2024
0214d8f
Update metadata function.
Dec 2, 2024
a1eb9f4
Add defaults.
Dec 2, 2024
1a98295
Implemented add file function.
Dec 2, 2024
2b58b9f
Make default_categories not a method.
Dec 2, 2024
dc7ed0a
Changed the signature of get metadata.
Dec 2, 2024
2a8dea3
Start using the new internal metadata class.
Dec 2, 2024
51de209
Need to use factory for defaults.
Dec 2, 2024
7e48111
Add a separator field.
Dec 3, 2024
663b6ae
Don't need the separator argument anymore.
Dec 3, 2024
44e6a4f
Type hint to keep pyright happy.
Dec 3, 2024
559c4de
Some more argument fixes.
Dec 3, 2024
312e74d
Don't need the separator param.
Dec 3, 2024
6d5c3ad
Implemented clear_metadata function.
Dec 3, 2024
f9da54e
Component selector uses the new metadata class.
Dec 3, 2024
0843a99
Get the filename components in the class itself.
Dec 3, 2024
7a704ce
Replicate the behaviour of the old system.
Dec 3, 2024
f74aa3d
Updated the clear metadata function.
Dec 3, 2024
a7d6664
Update for internal metadata.
Dec 3, 2024
e7cbe2c
Use new params.
Dec 3, 2024
5fa54f6
Make sure a separator is initialised.
Dec 3, 2024
abf84e1
Use the name load file.
Dec 3, 2024
fc07e31
Need to add file to metadata when loaded.
Dec 3, 2024
a4496b6
Forgot to add these :P
Dec 3, 2024
5da7cef
Remove old draw options call.
Dec 3, 2024
9b8e4fb
Missing else.
Dec 3, 2024
3b55c2a
Pull out the new internal metadata.
Dec 3, 2024
5870223
Don't need this comment.
Dec 3, 2024
350e813
Take into account this is now a list.
Dec 4, 2024
4d8fd9a
Use the replaced class from sasdata.
Dec 4, 2024
d505517
Whoops forgot to save these files.
Dec 4, 2024
51dda75
Forgot to remove old import.
Dec 4, 2024
723e886
Use the new params.
Dec 4, 2024
bf25ae3
Send the full file path.
Dec 4, 2024
ea6765a
Should only split in metadata class.
Dec 4, 2024
d00cb5a
Default separator should be set in dialog.py
Dec 4, 2024
58b60b7
Load multiple files at the same time.
Dec 6, 2024
033d69f
Updated name to avoid conflict with QT function.
Dec 9, 2024
a0a9784
Added type hints.
Dec 9, 2024
0014226
Add unparasable lines to warning label.
Dec 9, 2024
83f30e5
Take into account the startpos.
Dec 9, 2024
3239f18
Update warning label is a function.
Dec 9, 2024
65e3e4a
Call new function when its needed.
Dec 9, 2024
2086a44
Forgot to save :P
Dec 9, 2024
5766718
Fixed how lines are counted.
Dec 9, 2024
1319bf0
Try an orange font for this.
Dec 9, 2024
cee9027
Type hint to stop pyright from complaining.
Dec 10, 2024
fd3953e
Don't pass the CSV if there isn't one.
Dec 10, 2024
a3870e2
Separate this into another file.
Dec 10, 2024
f74f96d
Fixed a crash when we have > 1000 rows.
Dec 10, 2024
5ff7533
Started implementing default units.
Dec 10, 2024
20516e8
Use the new preferred units.
Dec 10, 2024
76e378b
Add some radios for choosing what to separate on.
Dec 11, 2024
133ffb0
Default to using the character.
Dec 11, 2024
6fcfdee
Use a separate propety for the expression.
Dec 11, 2024
bbeb2da
Split on casing as well.
Dec 11, 2024
255cbc9
Use new constant for casing regex.
Dec 11, 2024
7cc1530
Try hooking up to this event.
Dec 11, 2024
8cd3b91
We should probably use our internal split function.
Dec 11, 2024
378e791
Fixed regex.
Dec 11, 2024
e6d713b
Was using the wrong event.
Dec 11, 2024
268ae43
Changed where options is generated.
Dec 11, 2024
c36b2fe
Need to set this earlier to stop the event firing
Dec 11, 2024
91dbcb5
This shouldn't be here anymore.
Dec 11, 2024
4f49df2
These functions aren't needed anymore.
Dec 11, 2024
dfbe18c
Update the separator before updating stuff.
Dec 11, 2024
e78c89d
Call purge unreachable on separator update.
Dec 12, 2024
3b50828
Disable the separator box if casing is enabled.
Dec 12, 2024
308fd0e
Return unformatted if we're using casing separation.
Dec 12, 2024
3450780
Fixed error when there are no capital letters.
Dec 12, 2024
8cb16c5
Use a property for starting pos.
Dec 12, 2024
f9857c4
Update warning on selection/deselection.
Dec 12, 2024
650b05f
Add a setter for the current unit.
Dec 12, 2024
f8fa870
Make sure units match on uncertanties.
Dec 12, 2024
b620a27
Trigger column changed when the unit changes.
Dec 12, 2024
6ff1421
Stop event triggering when unit is empty.
Dec 12, 2024
333ca8f
Make sure ALL the columns are numbers.
Dec 13, 2024
0eee5bf
Use the new init separator method for the metadata.
Dec 13, 2024
c4e3ee6
Add dev menu
lucas-wilkins Jul 30, 2024
cce2198
Make menu show when config setting made
lucas-wilkins Jul 30, 2024
f739db1
Should just be using split line from the reader.
Dec 18, 2024
d104f2c
Shouldn't be calling items here.
Dec 18, 2024
521c076
Convert to list to make the interpreter happy.
Dec 18, 2024
a527bbe
This isn't true anymore.
Dec 18, 2024
620e01f
Type hinting to stop linting from complaining.
Jan 8, 2025
91a2b42
Changed the params for the new order.
Jan 8, 2025
d8beb42
Updated order again.
Jan 8, 2025
4f1c916
Changed order yet again.
Jan 8, 2025
fade71b
Add logic from starting the ascii reader from dev.
jamescrake-merani Jan 15, 2025
5d34467
Don't use relative module paths.
jamescrake-merani Jan 15, 2025
df4ce6f
Got rid of filename label, and move edit metadata.
jamescrake-merani Jan 28, 2025
5a1506c
Rename load file to select file.
jamescrake-merani Jan 28, 2025
603ad77
Add a cancel button.
jamescrake-merani Jan 28, 2025
67a7c1d
Disbale units when column is ignored.
jamescrake-merani Jan 28, 2025
9765f47
Centre the checkbox and remove label.
jamescrake-merani Jan 28, 2025
af0a3ef
Try this for clearer.
jamescrake-merani Jan 28, 2025
4c528f6
Maybe lets just empty the message.
jamescrake-merani Jan 28, 2025
79c8b22
Implement set checked method as well.
jamescrake-merani Jan 28, 2025
29a8d3b
Didn't call method properly.
jamescrake-merani Jan 28, 2025
c1346ff
Add type hinting here.
jamescrake-merani Jan 28, 2025
f1189ea
Try this for resetting the foreground color.
jamescrake-merani Jan 28, 2025
dec8dc7
Fixed import.
jamescrake-merani Jan 28, 2025
7e2bfa4
Use Lucas' mode idea for the column count.
jamescrake-merani Jan 28, 2025
557dc00
Put unload, and the filename on same line.
jamescrake-merani Jan 29, 2025
b32509b
Changed the bottom row.
jamescrake-merani Jan 30, 2025
8e14c28
Fixed indentation mistake in guess.
jamescrake-merani Jan 30, 2025
1fc3d3c
Changed how symbols are ignored.
jamescrake-merani Jan 30, 2025
0c9fdc3
Add pluses to the symbols.
jamescrake-merani Jan 30, 2025
6507aab
SasData should keep the metadata categories.
jamescrake-merani Feb 24, 2025
b37f8bb
Updated units.
Feb 10, 2025
d4c4386
Remove this comment.
Feb 10, 2025
2e8e9b6
Remove fixme comment.
Feb 10, 2025
2be801f
Try this?
Feb 10, 2025
8474a58
Making casing consistent.
Feb 10, 2025
9ec2cce
Remove guess from the SasView repository.
Feb 12, 2025
f184ebc
Update import.
Feb 12, 2025
135ad2b
Init should probably be at the top.
Feb 12, 2025
c02e482
Move this logic into SasData.
Feb 12, 2025
f5dae93
Removed the old import.
Feb 12, 2025
68b3b95
Import the right function.
Feb 12, 2025
5504112
Handle ignored columns.
Feb 13, 2025
323fa23
Fixed crashes when a filename just using casing.
Feb 14, 2025
0e7379f
Removed unneeded emit call.
Feb 17, 2025
9e1d09c
Use the bidrectional pairings.
Feb 17, 2025
9fbcd3e
Fixes linting errors
DrPaulSharp Aug 13, 2025
20592d5
Fixes build
DrPaulSharp Aug 13, 2025
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 build_tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pyparsing
PySide6
pytools
qtconsole
sasdata
sasdata @ git+https://github.com/SasView/sasdata.git@refactor_24
sasmodels
scipy
siphash24
Expand All @@ -38,4 +38,4 @@ zope
requests

# Alphabetized list of OS-specific packages
pywin32; platform_system == "Windows"
pywin32; platform_system == "Windows"
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ requires = [
"periodictable",
"pyopengl",
"pyside6",
"qtconsole",
"scipy",
"superqt",
"sasdata",
"sasdata @ git+https://github.com/SasView/sasdata.git@refactor_24",
"sasmodels",
"twisted",
"uncertainties",
Expand Down
89 changes: 89 additions & 0 deletions src/ascii_dialog/col_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from typing import cast

from PySide6.QtCore import Signal, Slot
from PySide6.QtWidgets import QHBoxLayout, QWidget

from sasdata.ascii_reader_metadata import bidirectional_pairings
from sasdata.quantities.units import NamedUnit

from ascii_dialog.column_unit import ColumnUnit


class ColEditor(QWidget):
"""An editor widget which allows the user to specify the columns of the data
from a set of options based on which dataset type has been selected."""
column_changed = Signal()

def __init__(self, cols: int, options: list[str]):
super().__init__()

self.cols = cols
self.options = options
self.layout = QHBoxLayout(self)
self.option_widgets: list[ColumnUnit] = []
for _ in range(cols):
new_widget = ColumnUnit(self.options)
new_widget.column_changed.connect(self.onColumnUpdate)
self.layout.addWidget(new_widget)
self.option_widgets.append(new_widget)

@Slot()
def onColumnUpdate(self):
column_changed = cast(ColumnUnit, self.sender())
pairing = bidirectional_pairings.get(column_changed.currentColumn)
if pairing is not None:
for col_unit in self.option_widgets:
# Second condition is important because otherwise, this event will keep being called, and the GUI will
# go into an infinite loop.
if col_unit.currentColumn == pairing and col_unit.currentUnit != column_changed.currentUnit:
col_unit.currentUnit = column_changed.currentUnit

def setCols(self, new_cols: int):
"""Set the amount of columns for the user to edit."""

# Decides whether we need to extend the current set of combo boxes, or
# remove some.
if self.cols < new_cols:
for _ in range(new_cols - self.cols):
new_widget = ColumnUnit(self.options)
new_widget.column_changed.connect(self.onColumnUpdate)
self.layout.addWidget(new_widget)
self.option_widgets.append(new_widget)

self.cols = new_cols
if self.cols > new_cols:
excess_cols = self.cols - new_cols
length = len(self.option_widgets)
excess_combo_boxes = self.option_widgets[length - excess_cols:length]
for box in excess_combo_boxes:
self.layout.removeWidget(box)
box.setParent(None)
self.option_widgets = self.option_widgets[0:length - excess_cols]
self.cols = new_cols
self.column_changed.emit()

def setColOrder(self, cols: list[str]):
"""Sets the series of currently selected columns to be cols, in that
order. If there are not enough column widgets include as many of the
columns in cols as possible.

"""
try:
for i, col_name in enumerate(cols):
self.option_widgets[i].setCurrentColumn(col_name)
except IndexError:
pass # Can ignore because it means we've run out of widgets.

def colNames(self) -> list[str]:
"""Get a list of all of the currently selected columns."""
return [widget.currentColumn for widget in self.option_widgets]

@property
def columns(self) -> list[tuple[str, NamedUnit | None]]:
return [(widget.currentColumn, widget.currentUnit if widget.currentColumn != "<ignore>" else None) for widget in self.option_widgets]

def replaceOptions(self, new_options: list[str]) -> None:
"""Replace options from which the user can choose for each column."""
self.options = new_options
for widget in self.option_widgets:
widget.replaceOptions(new_options)
128 changes: 128 additions & 0 deletions src/ascii_dialog/column_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python3

from PySide6.QtCore import Signal, Slot
from PySide6.QtGui import QRegularExpressionValidator
from PySide6.QtWidgets import QComboBox, QHBoxLayout, QSizePolicy, QWidget

from sasdata.dataset_types import unit_kinds
from sasdata.default_units import defaults_or_fallback
from sasdata.quantities.units import NamedUnit

from ascii_dialog.unit_selector import UnitSelector


def configure_size_policy(combo_box: QComboBox) -> None:
policy = combo_box.sizePolicy()
policy.setHorizontalPolicy(QSizePolicy.Policy.Ignored)
combo_box.setSizePolicy(policy)

class ColumnUnit(QWidget):
"""Widget with 2 combo boxes: one allowing the user to pick a column, and
another to specify the units for that column."""
def __init__(self, options) -> None:
super().__init__()
self.col_widget = self.createColComboBox(options)
self.unit_widget = self.createUnitComboBox(self.col_widget.currentText())
self.layout = QHBoxLayout(self)
self.layout.addWidget(self.col_widget)
self.layout.addWidget(self.unit_widget)
self.current_option: str

column_changed = Signal()

def createColComboBox(self, options: list[str]) -> QComboBox:
"""Create the combo box for specifying the column based on the given
options."""
new_combo_box = QComboBox()
configure_size_policy(new_combo_box)
for option in options:
new_combo_box.addItem(option)
new_combo_box.setEditable(True)
validator = QRegularExpressionValidator(r"[a-zA-Z0-9]+")
new_combo_box.setValidator(validator)
new_combo_box.currentTextChanged.connect(self.onOptionChange)
return new_combo_box

def createUnitComboBox(self, selected_option: str) -> QComboBox:
"""Create the combo box for specifying the unit for selected_option"""
new_combo_box = QComboBox()
configure_size_policy(new_combo_box)
new_combo_box.setEditable(True)
self.updateUnits(new_combo_box, selected_option)
new_combo_box.currentTextChanged.connect(self.onUnitChange)
return new_combo_box

def updateUnits(self, unit_box: QComboBox, selected_option: str):
unit_box.clear()
self.current_option = selected_option
# Use the list of preferred units but fallback to the first 5 if there aren't any for this particular column.
if self.current_option == '<ignore>':
unit_box.setDisabled(True)
else:
unit_box.setDisabled(False)
unit_options = defaults_or_fallback(self.current_option)
option_symbols = [unit.symbol for unit in unit_options]
for option in option_symbols[:5]:
unit_box.addItem(option)
unit_box.addItem('Select More')


def replaceOptions(self, new_options) -> None:
"""Replace the old options for the column with new_options"""
self.col_widget.clear()
self.col_widget.addItems(new_options)

def setCurrentColumn(self, new_column_value: str) -> None:
"""Change the current selected column to new_column_value"""
self.col_widget.setCurrentText(new_column_value)
self.updateUnits(self.unit_widget, new_column_value)


@Slot()
def onOptionChange(self):
# If the new option is empty string, its probably because the current
# options have been removed. Can safely ignore this.
self.column_changed.emit()
new_option = self.col_widget.currentText()
if new_option == '':
return
try:
self.updateUnits(self.unit_widget, new_option)
except KeyError:
# Means the units for this column aren't known. This shouldn't be
# the case in the real version so for now we'll just clear the unit
# widget.
self.unit_widget.clear()

@Slot()
def onUnitChange(self):
new_text = self.unit_widget.currentText()
if new_text == 'Select More':
selector = UnitSelector(unit_kinds[self.col_widget.currentText()].name, False)
selector.exec()
# We need the selection unit in the list of options, or else QT has some dodgy behaviour.
self.unit_widget.insertItem(-1, selector.selected_unit.symbol)
self.unit_widget.setCurrentText(selector.selected_unit.symbol)
# This event could get triggered when the units have just been cleared, and not actually updated. We don't want
# to trigger it in this case.
elif not new_text == '':
self.column_changed.emit()

@property
def currentColumn(self):
"""The currently selected column."""
return self.col_widget.currentText()

@property
def currentUnit(self) -> NamedUnit:
"""The currently selected unit."""
current_unit_symbol = self.unit_widget.currentText()
for unit in unit_kinds[self.current_option].units:
if current_unit_symbol == unit.symbol:
return unit
# This error shouldn't really happen so if it does, it indicates there is a bug in the code.
raise ValueError("Current unit doesn't seem to exist")

@currentUnit.setter
def currentUnit(self, new_value: NamedUnit):
self.unit_widget.setCurrentText(new_value.symbol)
5 changes: 5 additions & 0 deletions src/ascii_dialog/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env python


TABLE_MAX_ROWS = 1000
NOFILE_TEXT = "Click the button below to load a file."
Loading