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 296 commits into
base: refactor_24
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 211 commits
Commits
Show all changes
296 commits
Select commit Hold shift + click to select a range
0dcf738
+ not * for 1 or more.
jamescrake-merani Jul 30, 2024
18323fe
Function to guess starting position.
jamescrake-merani Jul 30, 2024
1f0ebbc
Fill table on some events.
jamescrake-merani Jul 30, 2024
3953928
Use new function for guessing starting pos.
jamescrake-merani Jul 30, 2024
b0ad077
Fixed typo.
jamescrake-merani Jul 30, 2024
a2914a5
Correct expression.
jamescrake-merani Jul 30, 2024
31ef0f1
Ignore minus sign as well.
jamescrake-merani Jul 30, 2024
39f77cc
Strip before splitting.
jamescrake-merani Jul 30, 2024
74d3063
Still show hidden items but grey them out.
jamescrake-merani Jul 30, 2024
4f7a484
Get the current dataset type.
jamescrake-merani Jul 30, 2024
bfc4829
Use the options for the dataset type.
jamescrake-merani Jul 30, 2024
3ad48df
Method to replace options.
jamescrake-merani Jul 30, 2024
d522004
Change options when dataset changes.
jamescrake-merani Jul 30, 2024
ad3d716
Automagically set an assumed col order.
jamescrake-merani Jul 30, 2024
80a211c
Ignore index errors.
jamescrake-merani Jul 30, 2024
ef2d4d1
Whoops exception handling in wrong place.
jamescrake-merani Jul 30, 2024
3075594
Change when the event handler has happened.
jamescrake-merani Jul 30, 2024
1307eec
Update columns.
jamescrake-merani Jul 30, 2024
d92a870
Fixed bug when user doesn't select a file.
jamescrake-merani Jul 30, 2024
35757f0
Filename wrong part of the result.
jamescrake-merani Jul 30, 2024
e911bc2
Comment is more descriptive.
jamescrake-merani Jul 30, 2024
4b04b13
Fixed options updates.
jamescrake-merani Jul 31, 2024
2af64d4
Set editable to true for all boxes.
jamescrake-merani Jul 31, 2024
3b9068b
Removed todo comment.
jamescrake-merani Jul 31, 2024
745e8fb
Validator for the columns.
jamescrake-merani Jul 31, 2024
db9d44f
Get the unit widgit to show up next to the col.
jamescrake-merani Aug 1, 2024
b1c0714
Changed replacing options.
jamescrake-merani Aug 1, 2024
2d68063
Fix set_col_order.
jamescrake-merani Aug 1, 2024
72b8141
Fixerd col_names function.
jamescrake-merani Aug 1, 2024
ff5e293
Created the ColumnUnit widgit.
jamescrake-merani Aug 1, 2024
4f82ff4
Function for replace options.
jamescrake-merani Aug 1, 2024
49d8218
Use the new widget.
jamescrake-merani Aug 1, 2024
59e3d1f
Fixed import.
jamescrake-merani Aug 1, 2024
8530b06
Use property for getting current column.
jamescrake-merani Aug 1, 2024
d06879c
Don't need brackets for property.
jamescrake-merani Aug 1, 2024
1595c8d
Forgot to add to layout.
jamescrake-merani Aug 1, 2024
02a0a0b
Change units when we change the column.
jamescrake-merani Aug 1, 2024
4bc1cfa
Theoeretically don't need this anymore.
jamescrake-merani Aug 1, 2024
6da9ddd
Ignore if empty string.
jamescrake-merani Aug 1, 2024
6f09405
Don't resize to contents.
jamescrake-merani Aug 1, 2024
f11e4fd
Missing return statement.
jamescrake-merani Aug 1, 2024
019492f
Column headers on table automatically update.
jamescrake-merani Aug 1, 2024
14e7f25
Determine if we have all the required columns.
jamescrake-merani Aug 1, 2024
52dd1b3
Added a label for warnings.
jamescrake-merani Aug 1, 2024
53830fe
Try creating an error message.
jamescrake-merani Aug 1, 2024
60e1011
Set the error message if required cols are missing
jamescrake-merani Aug 2, 2024
70252dc
Fixed required label (a bit).
jamescrake-merani Aug 2, 2024
197e28d
Improved the error message shown.
jamescrake-merani Aug 2, 2024
77008e4
Wrong way round.
jamescrake-merani Aug 2, 2024
660ff94
Add a try statement to avoid key error.
jamescrake-merani Aug 2, 2024
90d5932
Hook the event here as well.
jamescrake-merani Aug 2, 2024
a55c269
Changed around events to fix bugs.
jamescrake-merani Aug 2, 2024
ca7daa4
Create a separate warning label class.
jamescrake-merani Aug 2, 2024
30d94e2
If no missing, all is fine.
jamescrake-merani Aug 2, 2024
6758b3e
Use the new warning label.
jamescrake-merani Aug 2, 2024
ce428ad
Add functionality for duplicate columns.
jamescrake-merani Aug 2, 2024
394656d
Function for getting duplicate columns.
jamescrake-merani Aug 2, 2024
e78ec75
Pass duplicates in.
jamescrake-merani Aug 2, 2024
f64778c
Columns have changed when the number changes.
jamescrake-merani Aug 2, 2024
a8b59cc
Changed orderings to fix bug.
jamescrake-merani Aug 2, 2024
e77f0e7
Abstract the font setting.
jamescrake-merani Aug 2, 2024
785e3de
Create a class for the row status.
jamescrake-merani Aug 5, 2024
02ce670
Update label based on state.
jamescrake-merani Aug 5, 2024
726c42b
Update label when needed.
jamescrake-merani Aug 5, 2024
027678f
Show row status on table.
jamescrake-merani Aug 5, 2024
bb9db70
Don't include extra columns.
jamescrake-merani Aug 5, 2024
d5f7232
Maintain a list of row status widgets.
jamescrake-merani Aug 5, 2024
d897c05
Fixed comparison.
jamescrake-merani Aug 5, 2024
478db26
Keep state outside of widgets.
jamescrake-merani Aug 5, 2024
3f1e74e
Set the initial state based on guessed starting ppos.
jamescrake-merani Aug 5, 2024
38eae3f
Created a status changed signal.
jamescrake-merani Aug 5, 2024
1b3d1bb
Hook into row status change event.
jamescrake-merani Aug 5, 2024
1eddbf4
Pass in the row.
jamescrake-merani Aug 5, 2024
e58b8c4
Forgot to add to the list.
jamescrake-merani Aug 5, 2024
3c09829
Stretch to full width.
jamescrake-merani Aug 5, 2024
30b1826
Change font and colour depending on check state.
jamescrake-merani Aug 5, 2024
3096f75
Redraw the table when row status has changed.
jamescrake-merani Aug 5, 2024
07e8b09
Set item props elsewhere so they can update.
jamescrake-merani Aug 5, 2024
3a988bd
Set the font so it'll go back.
jamescrake-merani Aug 5, 2024
8155c64
Removed commented out code.
jamescrake-merani Aug 5, 2024
4fe627a
Don't do tristate anymore.
jamescrake-merani Aug 5, 2024
e91368e
Make checkbox binary.
jamescrake-merani Aug 5, 2024
03ad6ad
Bring back the starting pos.
jamescrake-merani Aug 5, 2024
b4ca3d5
Display all the data if its below max.
jamescrake-merani Aug 5, 2024
2b6f09e
Reset rows is included on load.
jamescrake-merani Aug 5, 2024
89710d6
Increased limit to 1000
jamescrake-merani Aug 5, 2024
d74e2a2
Type hinting and tidying.
jamescrake-merani Aug 6, 2024
8336ef5
Removed old comment.
jamescrake-merani Aug 6, 2024
dd9ca1b
Removed old comment.
jamescrake-merani Aug 6, 2024
7481fa0
Removed unused function.
jamescrake-merani Aug 6, 2024
3a5a7fb
Added more type hinting.
jamescrake-merani Aug 6, 2024
8f7e175
Removed code for guessing the seperator.
jamescrake-merani Aug 6, 2024
5a0e578
Fixed typo.
jamescrake-merani Aug 6, 2024
02653ee
Type hinting, and comment editing.
jamescrake-merani Aug 6, 2024
9cf5aa7
Added some docstrings.
jamescrake-merani Aug 6, 2024
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
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 onColumnUpdate(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.onColumnUpdate)
self.layout.addWidget(new_widget)
self.option_widgets.append(new_widget)

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].set_current_column(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.current_column 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.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.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)

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()
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()
new_combo_box.setEditable(True)
# word_list = ['alpha', 'omega', 'omicron', 'zeta']
# completer = QCompleter(word_list, self)
# new_combo_box.setCompleter(completer)
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()
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 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):
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 currentColumn(self):
"""The currently selected column."""
return self.col_widget.currentText()

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