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

2993 ascii file reader options #3007

Draft
wants to merge 391 commits into
base: refactor_24
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 208 commits
Commits
Show all changes
391 commits
Select commit Hold shift + click to select a range
96f9596
Removed commented out code.
jamescrake-merani Aug 6, 2024
eb975c8
Added some docstrings.
jamescrake-merani Aug 6, 2024
f094701
Added docstring.
jamescrake-merani Aug 6, 2024
4d31523
Documented warning label class.
jamescrake-merani Aug 6, 2024
f57aaca
Remove unneeeded import.
jamescrake-merani Aug 6, 2024
7c23af1
Removed some old comments.
jamescrake-merani Aug 6, 2024
01c20b6
Document col editor.
jamescrake-merani Aug 6, 2024
1e57d3e
I don't think this function is being used anymore.
jamescrake-merani Aug 6, 2024
1ffe53b
Remove import.
jamescrake-merani Aug 6, 2024
ae3b7d6
Fixed bug with the regex.
jamescrake-merani Aug 6, 2024
cc78b3c
Move init to top.
jamescrake-merani Aug 6, 2024
0a448df
Move init to top.
jamescrake-merani Aug 6, 2024
afed9f5
Fixed typo.
jamescrake-merani Aug 6, 2024
2b6d224
Some more docstrings.
jamescrake-merani Aug 6, 2024
c35ab0b
Use dictionary for looking up dataset.
jamescrake-merani Aug 6, 2024
269f63a
More docstrings.
jamescrake-merani Aug 6, 2024
94846ac
Return a set instead of a list.
jamescrake-merani Aug 6, 2024
19d8bf4
Use elipsis to indicate there is more data.
jamescrake-merani Aug 6, 2024
2444fbc
Allign the elipsis.
jamescrake-merani Aug 6, 2024
d1a8e02
Don't need a seperate for loop for typesetting.
jamescrake-merani Aug 6, 2024
441372f
Moved where the check for max row happens.
jamescrake-merani Aug 6, 2024
99d059f
Rename parameter.
jamescrake-merani Aug 6, 2024
58ffb24
Don't count multiple ignores as duplicates.
jamescrake-merani Aug 6, 2024
6df877e
Method for determining options.
jamescrake-merani Aug 6, 2024
4b524ac
Removed redundant var.
jamescrake-merani Aug 6, 2024
a2ddad8
Removed imports not being used anymore.
jamescrake-merani Aug 6, 2024
6af85cc
Added exception handling for reading the file.
jamescrake-merani Aug 6, 2024
b5a3836
Show units in unit box.
jamescrake-merani Aug 8, 2024
fbb6205
Use sasdata for the dataset types.
jamescrake-merani Aug 8, 2024
3ac79a6
Beginning of unit selector widget.
jamescrake-merani Aug 9, 2024
0b95ae8
Create a widget for listing units.
jamescrake-merani Aug 9, 2024
4be7cb9
Integrate the new list widget.
jamescrake-merani Aug 9, 2024
e57ae17
Update when the selected group changes.
jamescrake-merani Aug 9, 2024
4f3fb36
Include symbol in the representation on the list.
jamescrake-merani Aug 9, 2024
cb6dfc2
Added a search box.
jamescrake-merani Aug 9, 2024
cfac528
Use lowercase for comparisons.
jamescrake-merani Aug 9, 2024
d001320
Base on QDialog.
jamescrake-merani Aug 9, 2024
ce8d690
Have a way of getting the selected unit.
jamescrake-merani Aug 9, 2024
a4be0dc
Have a way of selecting, and closing the dialog.
jamescrake-merani Aug 9, 2024
ce67bc8
Use unicode symbols instead of ascii.
jamescrake-merani Aug 9, 2024
09c0b21
Integrate the unit selector with the ascii dialog.
jamescrake-merani Aug 9, 2024
c392f18
Change the selected unit when using.
jamescrake-merani Aug 9, 2024
91e2738
Property for current unit.
jamescrake-merani Aug 9, 2024
e51d6b6
Provide default group, and disable the option.
jamescrake-merani Aug 9, 2024
ce8f035
Added a placeholder for the search box.
jamescrake-merani Aug 9, 2024
2529120
Simulate having preferred options.
jamescrake-merani Aug 9, 2024
a6c3d4f
Allow double clicking to select a unit.
jamescrake-merani Aug 12, 2024
a2de561
Have a dictionary for the files loaded.
jamescrake-merani Aug 12, 2024
852e3b1
Get raw_csv based on filename.
jamescrake-merani Aug 12, 2024
d8fad4a
Added a filename chooser widget.
jamescrake-merani Aug 12, 2024
ce7f305
Add an event for when the current file changes.
jamescrake-merani Aug 12, 2024
6cccf57
Changed when guesses are attempted.
jamescrake-merani Aug 12, 2024
588c470
Track rows is included seperately for each file.
jamescrake-merani Aug 12, 2024
215e0f7
New widget for unit preferences.
jamescrake-merani Aug 12, 2024
977a2f8
Created a preference line widget.
jamescrake-merani Aug 12, 2024
13434b5
Add a line for each column.
jamescrake-merani Aug 12, 2024
8e0d0c6
Forgot to set layout parent.
jamescrake-merani Aug 12, 2024
0d33b8c
Again forgot parent :P
jamescrake-merani Aug 12, 2024
3f23542
Put the preferences in a scroll area.
jamescrake-merani Aug 12, 2024
c8ff2f7
Turn off the horizontal scroll.
jamescrake-merani Aug 12, 2024
0eab878
Added a selection menu widget.
jamescrake-merani Aug 12, 2024
b916ebd
Got the context menu to work.
jamescrake-merani Aug 13, 2024
a0170dc
Set the checkbox first then update the rest.
jamescrake-merani Aug 13, 2024
b86fe90
Use the new list in sasview rather than hardcoding
jamescrake-merani Aug 13, 2024
666b076
Removed some unused imports.
jamescrake-merani Aug 13, 2024
a29595c
Don't enable the select button immediately.
jamescrake-merani Aug 13, 2024
d83fadf
Unpinned pyside6.
jamescrake-merani Aug 14, 2024
78910b4
Fixed typo.
jamescrake-merani Sep 6, 2024
1bc1421
Remvoed shabang.
jamescrake-merani Sep 6, 2024
76555d6
Fixed casing.
jamescrake-merani Sep 6, 2024
67b5807
Unsplit line.
jamescrake-merani Sep 9, 2024
f90e2ea
Split import into two lines.
jamescrake-merani Sep 9, 2024
a5c64fc
Looks like a few names didn't change automatically
jamescrake-merani Sep 9, 2024
09942b8
Double clicking a unit selects it.
jamescrake-merani Sep 9, 2024
1d90603
Added an unload button.
jamescrake-merani Sep 9, 2024
e44e7d0
Use a horizontal layout.
jamescrake-merani Sep 9, 2024
22c5c0a
Handle case where there are no more files.
jamescrake-merani Sep 9, 2024
79e49ce
Disable table when there's no data.
jamescrake-merani Sep 9, 2024
139ee2a
Handle a unicode decode error.
jamescrake-merani Sep 9, 2024
c5cf089
Set filename label on update.
jamescrake-merani Sep 9, 2024
ec1b493
Reset the label back to original after unload.
jamescrake-merani Sep 9, 2024
8ab825e
For now, ignore the horizontal size hint.
jamescrake-merani Sep 9, 2024
df546fb
Fixed error that sometimes happens when selecting.
jamescrake-merani Sep 9, 2024
9022cc4
Disable the button when there's none to unload.
jamescrake-merani Sep 9, 2024
f2224f1
Set current filename to none when there is none.
jamescrake-merani Sep 10, 2024
ab684b9
Give a window title.
jamescrake-merani Sep 10, 2024
090da54
Added a done button.
jamescrake-merani Oct 21, 2024
14c1aed
Get the column tuple.
jamescrake-merani Oct 21, 2024
ce9f2d4
Make this a property.
jamescrake-merani Oct 21, 2024
899e93a
Added exclude lines to match param in dataclass.
jamescrake-merani Oct 21, 2024
83df09a
Fixed logic error.
jamescrake-merani Oct 21, 2024
1d3e91b
Hook up the done button to an event.
jamescrake-merani Oct 21, 2024
85977b3
Fixed slot connection.
jamescrake-merani Oct 21, 2024
325806b
Ascii dialog is now a dialog not a widget.
jamescrake-merani Oct 21, 2024
a814c36
I don't think these comments are needed anymore.
jamescrake-merani Oct 21, 2024
9cd4df8
Changed how the current unit is found.
jamescrake-merani Oct 21, 2024
7156abe
Include the selected unit in the options.
jamescrake-merani Oct 21, 2024
c2d6c06
Accept when clicking the done button.
jamescrake-merani Oct 21, 2024
a53f55e
Need to call items in order to destructure.
jamescrake-merani Oct 21, 2024
b4c6280
Just hard code the value.
jamescrake-merani Oct 21, 2024
5590164
Fix excluded_lines.
jamescrake-merani Oct 21, 2024
a529e52
Keep track of the full path.
jamescrake-merani Oct 21, 2024
bd7e2db
Fix the params.
jamescrake-merani Oct 21, 2024
c6344c0
Load the data instead of printing params only.
jamescrake-merani Oct 21, 2024
8dcced0
Return the unit not the symbol.
jamescrake-merani Oct 22, 2024
f01c994
Send in an empty dict of metadata for now.
jamescrake-merani Oct 25, 2024
da2eb95
Added an edit metadata button.
jamescrake-merani Oct 25, 2024
d02db13
Bring in the files for the metadata filename gui.
jamescrake-merani Oct 25, 2024
1dd0b5f
Renamed file, and ade it a dialog.
jamescrake-merani Oct 25, 2024
7075354
Forgot to commit new file.
jamescrake-merani Oct 25, 2024
903a424
Added save button.
jamescrake-merani Oct 25, 2024
24dc2c1
Hook up the save button to an event.
jamescrake-merani Oct 25, 2024
7f546ba
Print out the component metadata on success.
jamescrake-merani Oct 25, 2024
5bad16d
Fixed imports.
jamescrake-merani Oct 25, 2024
1f100e5
Add edit metadata button.
jamescrake-merani Oct 25, 2024
5ddc7ce
Fixed import.
jamescrake-merani Oct 25, 2024
d1748e8
Get filename from self.
jamescrake-merani Oct 25, 2024
10582c2
Created a property for the separator text.
jamescrake-merani Oct 25, 2024
ef5fa5d
Added a dict for separators.
jamescrake-merani Oct 25, 2024
25b01c0
Take in initial values for these.
jamescrake-merani Oct 25, 2024
783b271
Set the separator field.
jamescrake-merani Oct 30, 2024
6c89ce7
Pass in previous metadata, using defaults.
jamescrake-merani Nov 1, 2024
0af4f40
Selected components should persist.
jamescrake-merani Nov 1, 2024
07cecd4
Use the actual metadata.
jamescrake-merani Nov 1, 2024
28c0375
Add widget for custom metadata entry.
jamescrake-merani Nov 1, 2024
ad35b79
Changed name to be more consistent.
jamescrake-merani Nov 1, 2024
3ac829a
Add a custom entry button to the layout.
jamescrake-merani Nov 1, 2024
0d1304b
Use a signal for when the custom button is pressed
jamescrake-merani Nov 1, 2024
381ac0e
Started with the selector widget.
jamescrake-merani Nov 6, 2024
4e86f4c
Hook up event handlers properly.
jamescrake-merani Nov 18, 2024
3848319
Use the generic selector widget.
jamescrake-merani Nov 21, 2024
4a69c86
Init the base class.
jamescrake-merani Nov 21, 2024
b7ccb0a
Forgot to pass self into layout.
jamescrake-merani Nov 21, 2024
420c9e5
Handle when there is no new widget.
jamescrake-merani Nov 21, 2024
74bd1d7
Use isinstance.
jamescrake-merani Nov 21, 2024
16d8493
Fixed event handling.
jamescrake-merani Nov 21, 2024
55af567
Layout not inited properly.
jamescrake-merani Nov 21, 2024
605fff6
Need to delete, and reassign selector widget.
jamescrake-merani Nov 21, 2024
f5eb7a5
This line shouldn't be here.
jamescrake-merani Nov 21, 2024
bb3c506
Set the title of the metadata dialog.
jamescrake-merani Nov 21, 2024
88b61c8
Use separate functions for creating these widgets.
jamescrake-merani Nov 21, 2024
ffdbc11
Use the new function.
jamescrake-merani Nov 21, 2024
7aeef6a
Removed comment that doesn't make sense anymore.
jamescrake-merani Nov 22, 2024
c7cb4a6
Handle value changes.
jamescrake-merani Nov 22, 2024
869edbd
Pass in the new args.
jamescrake-merani Nov 22, 2024
4bc0111
Fixed typos in comments.
jamescrake-merani Nov 22, 2024
26d3bca
Choose default widget based on current option.
jamescrake-merani Nov 22, 2024
c22cff1
Set the field from the already set metadata.
jamescrake-merani Nov 22, 2024
53a9df1
Wrong control.
jamescrake-merani Nov 22, 2024
82c633d
Pass raw_metadata into params.
jamescrake-merani Nov 25, 2024
bcf3ea7
This should be a TODO comment.
jamescrake-merani Nov 25, 2024
8ad0054
Updated this map with a todo warning.
jamescrake-merani Nov 25, 2024
189115f
Gonna try a different approach.
jamescrake-merani Nov 25, 2024
2c7f19c
Fixed bug where not editing metadata wouldn't work
jamescrake-merani Nov 25, 2024
0f42252
Strip all of the lines.
jamescrake-merani Nov 26, 2024
de195b8
First step towards a master metadata dictionary.
jamescrake-merani Nov 27, 2024
78609df
Pass along the master metadata dict.
jamescrake-merani Nov 28, 2024
19f94f3
Pass in the master metadata.
jamescrake-merani Nov 28, 2024
f1b6440
Changed round a bunch of type hints.
jamescrake-merani Nov 28, 2024
2ae7f46
Master metadata should be the same for all files.
jamescrake-merani Dec 2, 2024
0f2be4e
Give the master metadata a default value.
jamescrake-merani Dec 2, 2024
65c396b
This should be type hinted.
jamescrake-merani Dec 2, 2024
90ea644
Remove the metadata dict param.
jamescrake-merani Dec 2, 2024
c43ed07
I think these are the wrong way round.
jamescrake-merani Dec 2, 2024
267ff9d
Give the master metadata to metadata filename.
jamescrake-merani Dec 2, 2024
26df2eb
Create some classes for metadata.
jamescrake-merani Dec 2, 2024
6d45043
Remove unneeded import.
jamescrake-merani Dec 2, 2024
3ac3124
Implemented get_metadata function.
jamescrake-merani Dec 2, 2024
1199772
Update metadata function.
jamescrake-merani Dec 2, 2024
5aeac89
Add defaults.
jamescrake-merani Dec 2, 2024
054872d
Implemented add file function.
jamescrake-merani Dec 2, 2024
464384e
Make default_categories not a method.
jamescrake-merani Dec 2, 2024
4d07d64
Changed the signature of get metadata.
jamescrake-merani Dec 2, 2024
f2cfafe
Start using the new internal metadata class.
jamescrake-merani Dec 2, 2024
f093cfc
Need to use factory for defaults.
jamescrake-merani Dec 2, 2024
4460094
Add a separator field.
jamescrake-merani Dec 3, 2024
9186f3f
Don't need the separator argument anymore.
jamescrake-merani Dec 3, 2024
ae8d029
Type hint to keep pyright happy.
jamescrake-merani Dec 3, 2024
e9de4f6
Some more argument fixes.
jamescrake-merani Dec 3, 2024
e98c125
Don't need the separator param.
jamescrake-merani Dec 3, 2024
64f1dd4
Implemented clear_metadata function.
jamescrake-merani Dec 3, 2024
56ebc7f
Component selector uses the new metadata class.
jamescrake-merani Dec 3, 2024
b0aeb07
Get the filename components in the class itself.
jamescrake-merani Dec 3, 2024
dfde8ca
Replicate the behaviour of the old system.
jamescrake-merani Dec 3, 2024
3abeac9
Updated the clear metadata function.
jamescrake-merani Dec 3, 2024
c283d17
Update for internal metadata.
jamescrake-merani Dec 3, 2024
338ac48
Use new params.
jamescrake-merani Dec 3, 2024
973599c
Make sure a separator is initialised.
jamescrake-merani Dec 3, 2024
088994f
Use the name load file.
jamescrake-merani Dec 3, 2024
f08c0a0
Need to add file to metadata when loaded.
jamescrake-merani Dec 3, 2024
f0aa11a
Forgot to add these :P
jamescrake-merani Dec 3, 2024
bd8ec7c
Remove old draw options call.
jamescrake-merani Dec 3, 2024
72dcd5e
Missing else.
jamescrake-merani Dec 3, 2024
185e8d9
Pull out the new internal metadata.
jamescrake-merani Dec 3, 2024
c26616b
Don't need this comment.
jamescrake-merani Dec 3, 2024
fd738c6
Take into account this is now a list.
jamescrake-merani Dec 4, 2024
70d57e3
Use the replaced class from sasdata.
jamescrake-merani Dec 4, 2024
02d1015
Whoops forgot to save these files.
jamescrake-merani Dec 4, 2024
a1046f4
Forgot to remove old import.
jamescrake-merani Dec 4, 2024
e6c85ce
Use the new params.
jamescrake-merani Dec 4, 2024
c967411
Send the full file path.
jamescrake-merani Dec 4, 2024
c7b9d5f
Should only split in metadata class.
jamescrake-merani Dec 4, 2024
580bf5b
Default separator should be set in dialog.py
jamescrake-merani Dec 4, 2024
ba0b0b6
Load multiple files at the same time.
jamescrake-merani Dec 6, 2024
9938705
Updated name to avoid conflict with QT function.
jamescrake-merani Dec 9, 2024
22b87e2
Added type hints.
jamescrake-merani Dec 9, 2024
f4c33a3
Add unparasable lines to warning label.
jamescrake-merani Dec 9, 2024
4073732
Take into account the startpos.
jamescrake-merani Dec 9, 2024
f618492
Update warning label is a function.
jamescrake-merani Dec 9, 2024
1765b04
Call new function when its needed.
jamescrake-merani Dec 9, 2024
53542b9
Forgot to save :P
jamescrake-merani Dec 9, 2024
826895a
Fixed how lines are counted.
jamescrake-merani Dec 9, 2024
81e80a2
Try an orange font for this.
jamescrake-merani Dec 9, 2024
0d2dea5
Type hint to stop pyright from complaining.
jamescrake-merani Dec 10, 2024
881ee79
Don't pass the CSV if there isn't one.
jamescrake-merani Dec 10, 2024
a298350
Separate this into another file.
jamescrake-merani Dec 10, 2024
4683dba
Fixed a crash when we have > 1000 rows.
jamescrake-merani Dec 10, 2024
8fb5cc0
Started implementing default units.
jamescrake-merani Dec 10, 2024
ea48e84
Use the new preferred units.
jamescrake-merani Dec 10, 2024
c020117
Add some radios for choosing what to separate on.
jamescrake-merani Dec 11, 2024
f8d86ee
Default to using the character.
jamescrake-merani Dec 11, 2024
55e63ec
Use a separate propety for the expression.
jamescrake-merani Dec 11, 2024
1a28f39
Split on casing as well.
jamescrake-merani Dec 11, 2024
ff2f981
Use new constant for casing regex.
jamescrake-merani Dec 11, 2024
17f0020
Try hooking up to this event.
jamescrake-merani Dec 11, 2024
8d39ed0
We should probably use our internal split function.
jamescrake-merani Dec 11, 2024
fa15585
Fixed regex.
jamescrake-merani Dec 11, 2024
216a8f4
Was using the wrong event.
jamescrake-merani Dec 11, 2024
6c689bd
Changed where options is generated.
jamescrake-merani Dec 11, 2024
38b86e9
Need to set this earlier to stop the event firing
jamescrake-merani Dec 11, 2024
7e1b60e
This shouldn't be here anymore.
jamescrake-merani Dec 11, 2024
64194f4
These functions aren't needed anymore.
jamescrake-merani Dec 11, 2024
75a06e7
Update the separator before updating stuff.
jamescrake-merani Dec 11, 2024
9248d88
Call purge unreachable on separator update.
jamescrake-merani Dec 12, 2024
7f2cb4a
Disable the separator box if casing is enabled.
jamescrake-merani Dec 12, 2024
c407b24
Return unformatted if we're using casing separation.
jamescrake-merani Dec 12, 2024
a03290d
Fixed error when there are no capital letters.
jamescrake-merani Dec 12, 2024
950cd04
Use a property for starting pos.
jamescrake-merani Dec 12, 2024
d41fbd7
Update warning on selection/deselection.
jamescrake-merani Dec 12, 2024
6eddc96
Add a setter for the current unit.
jamescrake-merani Dec 12, 2024
4f61e15
Make sure units match on uncertanties.
jamescrake-merani Dec 12, 2024
4446b41
Trigger column changed when the unit changes.
jamescrake-merani Dec 12, 2024
eb3c15b
Stop event triggering when unit is empty.
jamescrake-merani Dec 12, 2024
2bc464e
Make sure ALL the columns are numbers.
jamescrake-merani Dec 13, 2024
7ec2f80
Use the new init separator method for the metadata.
jamescrake-merani Dec 13, 2024
50bf23a
Merge branch 'refactor_24' into 2993-ascii-file-reader-options
jamescrake-merani Dec 18, 2024
9c391e6
Should just be using split line from the reader.
jamescrake-merani Dec 18, 2024
0514fe5
Shouldn't be calling items here.
jamescrake-merani Dec 18, 2024
ba95c60
Convert to list to make the interpreter happy.
jamescrake-merani Dec 18, 2024
91777ba
This isn't true anymore.
jamescrake-merani Dec 18, 2024
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
2 changes: 1 addition & 1 deletion build_tools/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ zope
pywin32; platform_system == "Windows"

# Alphabetized list of version-pinned packages
PySide6==6.4.3 # Later versions do not mesh well with pyinstaller < 6.0
PySide6
74 changes: 74 additions & 0 deletions src/ascii_dialog/col_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from PySide6.QtGui import QRegularExpressionValidator
from PySide6.QtWidgets import QComboBox, QHBoxLayout, QWidget
from PySide6.QtCore import Slot, Signal
from 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()

@Slot()
def on_column_update(self):
self.column_changed.emit()


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

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

def set_cols(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.on_column_update)
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 set_col_order(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].set_current_column(col_name)
except IndexError:
pass # Can ignore because it means we've run out of widgets.

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

def replace_options(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.replace_options(new_options)
99 changes: 99 additions & 0 deletions src/ascii_dialog/column_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env python3

from PySide6.QtCore import Signal, Slot
from PySide6.QtWidgets import QComboBox, QCompleter, QHBoxLayout, QWidget
from PySide6.QtGui import QRegularExpressionValidator
from sasdata.dataset_types import unit_kinds
from sasdata.quantities.units import symbol_lookup

from unit_selector import UnitSelector

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.create_col_combo_box(options)
self.unit_widget = self.create_unit_combo_box(self.col_widget.currentText())
self.layout = QHBoxLayout(self)
self.layout.addWidget(self.col_widget)
self.layout.addWidget(self.unit_widget)

column_changed = Signal()

def create_col_combo_box(self, options: list[str]) -> QComboBox:
"""Create the combo box for specifying the column based on the given
options."""
new_combo_box = QComboBox()
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.on_option_change)
return new_combo_box

def create_unit_combo_box(self, selected_option: str) -> QComboBox:
"""Create the combo box for specifying the unit for selected_option"""
new_combo_box = QComboBox()
new_combo_box.setEditable(True)
# word_list = ['alpha', 'omega', 'omicron', 'zeta']
# completer = QCompleter(word_list, self)
# new_combo_box.setCompleter(completer)
self.update_units(new_combo_box, selected_option)
new_combo_box.currentTextChanged.connect(self.on_unit_change)
return new_combo_box

def update_units(self, unit_box: QComboBox, selected_option: str):
unit_box.clear()
options = [unit.symbol for unit in unit_kinds[selected_option].units]
# We don't have preferred units yet. In order to simulate this, just
# take the first 5 options to display.
for option in options[:5]:
unit_box.addItem(option)
unit_box.addItem('Select More')


def replace_options(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 set_current_column(self, new_column_value: str) -> None:
"""Change the current selected column to new_column_value"""
self.col_widget.setCurrentText(new_column_value)
self.update_units(self.unit_widget, new_column_value)


@Slot()
def on_option_change(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.update_units(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 on_unit_change(self):
if self.unit_widget.currentText() == 'Select More':
selector = UnitSelector(unit_kinds[self.col_widget.currentText()].name, False)
selector.exec()
self.unit_widget.setCurrentText(selector.selected_unit.symbol)

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

@property
def current_unit(self):
"""The currently selected unit."""
return symbol_lookup[self.unit_widget.currentText()]
Loading