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
f9bc301
Provide default group, and disable the option.
Aug 9, 2024
f04e194
Added a placeholder for the search box.
Aug 9, 2024
68cd8cd
Simulate having preferred options.
Aug 9, 2024
f4443ee
Allow double clicking to select a unit.
Aug 12, 2024
9dce749
Have a dictionary for the files loaded.
Aug 12, 2024
7e3c004
Get raw_csv based on filename.
Aug 12, 2024
b55a2b3
Added a filename chooser widget.
Aug 12, 2024
fa41fd2
Add an event for when the current file changes.
Aug 12, 2024
c9809e7
Changed when guesses are attempted.
Aug 12, 2024
4ba8d5a
Track rows is included seperately for each file.
Aug 12, 2024
50c398c
New widget for unit preferences.
Aug 12, 2024
4d20f08
Created a preference line widget.
Aug 12, 2024
1db1fba
Add a line for each column.
Aug 12, 2024
f096a43
Forgot to set layout parent.
Aug 12, 2024
29a6561
Again forgot parent :P
Aug 12, 2024
3a1f4cf
Put the preferences in a scroll area.
Aug 12, 2024
9781a9f
Turn off the horizontal scroll.
Aug 12, 2024
9ef8159
Added a selection menu widget.
Aug 12, 2024
efed694
Got the context menu to work.
Aug 13, 2024
90953cb
Set the checkbox first then update the rest.
Aug 13, 2024
4c79214
Use the new list in sasview rather than hardcoding
Aug 13, 2024
f90f8c7
Removed some unused imports.
Aug 13, 2024
815bb0c
Don't enable the select button immediately.
Aug 13, 2024
3b6ad2f
Unpinned pyside6.
Aug 14, 2024
058b2fd
Fixed typo.
Sep 6, 2024
3195934
Remvoed shabang.
Sep 6, 2024
a4e22bd
Fixed casing.
Sep 6, 2024
03aea5b
Unsplit line.
Sep 9, 2024
a69daa5
Split import into two lines.
Sep 9, 2024
23dd839
Looks like a few names didn't change automatically
Sep 9, 2024
00c06fa
Double clicking a unit selects it.
Sep 9, 2024
120851f
Added an unload button.
Sep 9, 2024
25516cb
Use a horizontal layout.
Sep 9, 2024
4d9151a
Handle case where there are no more files.
Sep 9, 2024
11c1a81
Disable table when there's no data.
Sep 9, 2024
363dcec
Handle a unicode decode error.
Sep 9, 2024
58e2c6e
Set filename label on update.
Sep 9, 2024
c0918d3
Reset the label back to original after unload.
Sep 9, 2024
bbcb101
For now, ignore the horizontal size hint.
Sep 9, 2024
79b001d
Fixed error that sometimes happens when selecting.
Sep 9, 2024
01d4296
Disable the button when there's none to unload.
Sep 9, 2024
f5f4091
Set current filename to none when there is none.
Sep 10, 2024
efc898f
Give a window title.
Sep 10, 2024
b955eb1
Added a done button.
Oct 21, 2024
a6ab38d
Get the column tuple.
Oct 21, 2024
c2cb5f7
Make this a property.
Oct 21, 2024
25c5a91
Added exclude lines to match param in dataclass.
Oct 21, 2024
76b13f7
Fixed logic error.
Oct 21, 2024
c4aa385
Hook up the done button to an event.
Oct 21, 2024
29e35e3
Fixed slot connection.
Oct 21, 2024
eb58a3e
Ascii dialog is now a dialog not a widget.
Oct 21, 2024
fd13782
I don't think these comments are needed anymore.
Oct 21, 2024
01a6510
Changed how the current unit is found.
Oct 21, 2024
87419b6
Include the selected unit in the options.
Oct 21, 2024
7d71368
Accept when clicking the done button.
Oct 21, 2024
ccd90fc
Need to call items in order to destructure.
Oct 21, 2024
60c85a9
Just hard code the value.
Oct 21, 2024
927b86a
Fix excluded_lines.
Oct 21, 2024
09a8aa9
Keep track of the full path.
Oct 21, 2024
beacd53
Fix the params.
Oct 21, 2024
ec76e16
Load the data instead of printing params only.
Oct 21, 2024
07846f0
Return the unit not the symbol.
Oct 22, 2024
2cfe936
Send in an empty dict of metadata for now.
Oct 25, 2024
96ccf2f
Added an edit metadata button.
Oct 25, 2024
58240c3
Bring in the files for the metadata filename gui.
Oct 25, 2024
ca4ae71
Renamed file, and ade it a dialog.
Oct 25, 2024
a6c5e08
Forgot to commit new file.
Oct 25, 2024
2864411
Added save button.
Oct 25, 2024
cab9a4a
Hook up the save button to an event.
Oct 25, 2024
0b2670d
Print out the component metadata on success.
Oct 25, 2024
fdd6849
Fixed imports.
Oct 25, 2024
d13c540
Add edit metadata button.
Oct 25, 2024
ebb380a
Fixed import.
Oct 25, 2024
271dd36
Get filename from self.
Oct 25, 2024
47eef26
Created a property for the separator text.
Oct 25, 2024
b95e736
Added a dict for separators.
Oct 25, 2024
89f799d
Take in initial values for these.
Oct 25, 2024
6c2e424
Set the separator field.
Oct 30, 2024
acd1061
Pass in previous metadata, using defaults.
Nov 1, 2024
7304865
Selected components should persist.
Nov 1, 2024
52badc4
Use the actual metadata.
Nov 1, 2024
770378f
Add widget for custom metadata entry.
Nov 1, 2024
37248ce
Changed name to be more consistent.
Nov 1, 2024
d434146
Add a custom entry button to the layout.
Nov 1, 2024
9edfdf5
Use a signal for when the custom button is pressed
Nov 1, 2024
16f7772
Started with the selector widget.
Nov 6, 2024
e3ffc30
Hook up event handlers properly.
Nov 18, 2024
c9579e6
Use the generic selector widget.
Nov 21, 2024
545bd6d
Init the base class.
Nov 21, 2024
0c0f032
Forgot to pass self into layout.
Nov 21, 2024
2cb72ce
Handle when there is no new widget.
Nov 21, 2024
2cd3fd2
Use isinstance.
Nov 21, 2024
9aaed7b
Fixed event handling.
Nov 21, 2024
eae21bb
Layout not inited properly.
Nov 21, 2024
fc13867
Need to delete, and reassign selector widget.
Nov 21, 2024
50286d1
This line shouldn't be here.
Nov 21, 2024
80f2fc1
Set the title of the metadata dialog.
Nov 21, 2024
73bee4b
Use separate functions for creating these widgets.
Nov 21, 2024
f16b47c
Use the new function.
Nov 21, 2024
4185595
Removed comment that doesn't make sense anymore.
Nov 22, 2024
37368c0
Handle value changes.
Nov 22, 2024
aec6b00
Pass in the new args.
Nov 22, 2024
b0206b2
Fixed typos in comments.
Nov 22, 2024
23a67b7
Choose default widget based on current option.
Nov 22, 2024
721dc1b
Set the field from the already set metadata.
Nov 22, 2024
70f4ddf
Wrong control.
Nov 22, 2024
d8f1aef
Pass raw_metadata into params.
Nov 25, 2024
6810578
This should be a TODO comment.
Nov 25, 2024
f2200e2
Updated this map with a todo warning.
Nov 25, 2024
879c7af
Gonna try a different approach.
Nov 25, 2024
fe7b145
Fixed bug where not editing metadata wouldn't work
Nov 25, 2024
72b5612
Strip all of the lines.
Nov 26, 2024
0f7d9e7
First step towards a master metadata dictionary.
Nov 27, 2024
672e05f
Pass along the master metadata dict.
Nov 28, 2024
29fab07
Pass in the master metadata.
Nov 28, 2024
dbeb120
Changed round a bunch of type hints.
Nov 28, 2024
2d798fe
Master metadata should be the same for all files.
Dec 2, 2024
08a7ee7
Give the master metadata a default value.
Dec 2, 2024
c2ecfdf
This should be type hinted.
Dec 2, 2024
b40e784
Remove the metadata dict param.
Dec 2, 2024
6513523
I think these are the wrong way round.
Dec 2, 2024
bcab6b9
Give the master metadata to metadata filename.
Dec 2, 2024
02deb63
Create some classes for metadata.
Dec 2, 2024
3880a17
Remove unneeded import.
Dec 2, 2024
3950db5
Implemented get_metadata function.
Dec 2, 2024
c27f92c
Update metadata function.
Dec 2, 2024
8197591
Add defaults.
Dec 2, 2024
623a811
Implemented add file function.
Dec 2, 2024
6b04e5a
Make default_categories not a method.
Dec 2, 2024
5ac1253
Changed the signature of get metadata.
Dec 2, 2024
d27cb82
Start using the new internal metadata class.
Dec 2, 2024
3eed53c
Need to use factory for defaults.
Dec 2, 2024
0c491cb
Add a separator field.
Dec 3, 2024
56b3af1
Don't need the separator argument anymore.
Dec 3, 2024
9a5d6be
Type hint to keep pyright happy.
Dec 3, 2024
f1f76f5
Some more argument fixes.
Dec 3, 2024
1848ea2
Don't need the separator param.
Dec 3, 2024
d19dc89
Implemented clear_metadata function.
Dec 3, 2024
e4f7493
Component selector uses the new metadata class.
Dec 3, 2024
1879fb3
Get the filename components in the class itself.
Dec 3, 2024
b305054
Replicate the behaviour of the old system.
Dec 3, 2024
62875f3
Updated the clear metadata function.
Dec 3, 2024
366c166
Update for internal metadata.
Dec 3, 2024
4f6f061
Use new params.
Dec 3, 2024
63c1d76
Make sure a separator is initialised.
Dec 3, 2024
544c89e
Use the name load file.
Dec 3, 2024
d73cd9b
Need to add file to metadata when loaded.
Dec 3, 2024
3c589df
Forgot to add these :P
Dec 3, 2024
02321cb
Remove old draw options call.
Dec 3, 2024
779173f
Missing else.
Dec 3, 2024
48646a4
Pull out the new internal metadata.
Dec 3, 2024
66f7fd9
Don't need this comment.
Dec 3, 2024
ae52719
Take into account this is now a list.
Dec 4, 2024
a15f071
Use the replaced class from sasdata.
Dec 4, 2024
f650408
Whoops forgot to save these files.
Dec 4, 2024
7f4fb14
Forgot to remove old import.
Dec 4, 2024
8669725
Use the new params.
Dec 4, 2024
b3860c6
Send the full file path.
Dec 4, 2024
5ba12d8
Should only split in metadata class.
Dec 4, 2024
522059e
Default separator should be set in dialog.py
Dec 4, 2024
e396a96
Load multiple files at the same time.
Dec 6, 2024
f74a9df
Updated name to avoid conflict with QT function.
Dec 9, 2024
417652f
Added type hints.
Dec 9, 2024
9314372
Add unparasable lines to warning label.
Dec 9, 2024
78ad512
Take into account the startpos.
Dec 9, 2024
1d33125
Update warning label is a function.
Dec 9, 2024
6fe9f3a
Call new function when its needed.
Dec 9, 2024
305f43e
Forgot to save :P
Dec 9, 2024
9265866
Fixed how lines are counted.
Dec 9, 2024
de38d9c
Try an orange font for this.
Dec 9, 2024
93158a9
Type hint to stop pyright from complaining.
Dec 10, 2024
210f0cd
Don't pass the CSV if there isn't one.
Dec 10, 2024
ee4faeb
Separate this into another file.
Dec 10, 2024
fd50719
Fixed a crash when we have > 1000 rows.
Dec 10, 2024
987a53f
Started implementing default units.
Dec 10, 2024
e87e7f3
Use the new preferred units.
Dec 10, 2024
a19f82b
Add some radios for choosing what to separate on.
Dec 11, 2024
8752f85
Default to using the character.
Dec 11, 2024
418b789
Use a separate propety for the expression.
Dec 11, 2024
3931ef5
Split on casing as well.
Dec 11, 2024
0721e4c
Use new constant for casing regex.
Dec 11, 2024
1b594d8
Try hooking up to this event.
Dec 11, 2024
439033c
We should probably use our internal split function.
Dec 11, 2024
04e722a
Fixed regex.
Dec 11, 2024
5bac0ec
Was using the wrong event.
Dec 11, 2024
f3b9f57
Changed where options is generated.
Dec 11, 2024
8a9092f
Need to set this earlier to stop the event firing
Dec 11, 2024
df0378d
This shouldn't be here anymore.
Dec 11, 2024
4d421e1
These functions aren't needed anymore.
Dec 11, 2024
9a83491
Update the separator before updating stuff.
Dec 11, 2024
5b2d12c
Call purge unreachable on separator update.
Dec 12, 2024
3ad5a95
Disable the separator box if casing is enabled.
Dec 12, 2024
1aac075
Return unformatted if we're using casing separation.
Dec 12, 2024
99305ca
Fixed error when there are no capital letters.
Dec 12, 2024
b261265
Use a property for starting pos.
Dec 12, 2024
5495bd3
Update warning on selection/deselection.
Dec 12, 2024
13422af
Add a setter for the current unit.
Dec 12, 2024
ec04fdc
Make sure units match on uncertanties.
Dec 12, 2024
09df257
Trigger column changed when the unit changes.
Dec 12, 2024
9a65fdf
Stop event triggering when unit is empty.
Dec 12, 2024
d88ee45
Make sure ALL the columns are numbers.
Dec 13, 2024
0e8b6e9
Use the new init separator method for the metadata.
Dec 13, 2024
73a22bb
Add dev menu
lucas-wilkins Jul 30, 2024
73bf88a
Make menu show when config setting made
lucas-wilkins Jul 30, 2024
70082c9
Should just be using split line from the reader.
Dec 18, 2024
4428117
Shouldn't be calling items here.
Dec 18, 2024
a63da01
Convert to list to make the interpreter happy.
Dec 18, 2024
b2d1e3a
This isn't true anymore.
Dec 18, 2024
c89b577
Type hinting to stop linting from complaining.
Jan 8, 2025
9c3976d
Changed the params for the new order.
Jan 8, 2025
0e828ad
Updated order again.
Jan 8, 2025
e581ecc
Changed order yet again.
Jan 8, 2025
5cce48a
Add logic from starting the ascii reader from dev.
jamescrake-merani Jan 15, 2025
7770533
Don't use relative module paths.
jamescrake-merani Jan 15, 2025
483a41f
Got rid of filename label, and move edit metadata.
jamescrake-merani Jan 28, 2025
61e265d
Rename load file to select file.
jamescrake-merani Jan 28, 2025
3c8bc07
Add a cancel button.
jamescrake-merani Jan 28, 2025
5aaf6b3
Disbale units when column is ignored.
jamescrake-merani Jan 28, 2025
1f4d3d4
Centre the checkbox and remove label.
jamescrake-merani Jan 28, 2025
292fdb0
Try this for clearer.
jamescrake-merani Jan 28, 2025
0d3a699
Maybe lets just empty the message.
jamescrake-merani Jan 28, 2025
ec99464
Implement set checked method as well.
jamescrake-merani Jan 28, 2025
28acfe1
Didn't call method properly.
jamescrake-merani Jan 28, 2025
95da0ba
Add type hinting here.
jamescrake-merani Jan 28, 2025
a772cf4
Try this for resetting the foreground color.
jamescrake-merani Jan 28, 2025
e792821
Fixed import.
jamescrake-merani Jan 28, 2025
3bdeff0
Use Lucas' mode idea for the column count.
jamescrake-merani Jan 28, 2025
7332fec
Put unload, and the filename on same line.
jamescrake-merani Jan 29, 2025
8a805b6
Changed the bottom row.
jamescrake-merani Jan 30, 2025
4f6a4a0
Fixed indentation mistake in guess.
jamescrake-merani Jan 30, 2025
95690e0
Changed how symbols are ignored.
jamescrake-merani Jan 30, 2025
3a47122
Add pluses to the symbols.
jamescrake-merani Jan 30, 2025
5127b1a
SasData should keep the metadata categories.
jamescrake-merani Feb 24, 2025
0084ada
Updated units.
Feb 10, 2025
3265ead
Remove this comment.
Feb 10, 2025
e7a8568
Remove fixme comment.
Feb 10, 2025
bf220be
Try this?
Feb 10, 2025
fa7305c
Making casing consistent.
Feb 10, 2025
b2c1f61
Remove guess from the SasView repository.
Feb 12, 2025
8662c19
Update import.
Feb 12, 2025
573d5cb
Init should probably be at the top.
Feb 12, 2025
bd01aa1
Move this logic into SasData.
Feb 12, 2025
9a34cdc
Removed the old import.
Feb 12, 2025
a285a3d
Import the right function.
Feb 12, 2025
5f448f7
Handle ignored columns.
Feb 13, 2025
fae3b3b
Fixed crashes when a filename just using casing.
Feb 14, 2025
805ef92
Removed unneeded emit call.
Feb 17, 2025
c916642
Use the bidrectional pairings.
Feb 17, 2025
9873cb9
Fixes linting errors
DrPaulSharp Aug 13, 2025
d718f99
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
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ env:
# The test-installer job can run with the pyinstaller debug bundle
INSTALLER_USE_DEBUG: false
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
# Python version to be used in the CI
CI_PYTHON_VERSION: 3.12

jobs:

Expand Down Expand Up @@ -58,7 +60,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.12
python-version: ${{ env.CI_PYTHON_VERSION }}

- uses: actions/checkout@v5

Expand Down Expand Up @@ -86,7 +88,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: 3.12
python-version: ${{ env.CI_PYTHON_VERSION }}

### Check if this wheel is already cached

Expand Down Expand Up @@ -440,6 +442,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macos-latest, ubuntu-22.04 ]
python-version: [ 3.12 ]
include: ${{ fromJson(needs.matrix.outputs.installer-matrix-json) }}

name: Test installer
Expand Down
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 @@ -39,4 +39,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