Skip to content

Commit

Permalink
added better text alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymassi committed Feb 29, 2024
1 parent f624632 commit b25ce41
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/seahawk/seahawk_deck/dash_widgets/check_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ def __init__(self, parent: str, task_list_file: str, style_sheet_file: str):

# Creating labels for text to be displayed on
self.title = qtw.QLabel(parent)
self.title.setAlignment(qtc.Qt.AlignCenter)

# Creating a label for the tasks done
self.tasks_done = qtw.QLabel(parent)

# Creating a label for points earned
self.points_earned = qtw.QLabel(parent)
self.points_earned.move(100,10)
self.points_earned.setWordWrap(True)
self.points_earned.setAlignment(qtc.Qt.AlignCenter)
#self.points_earned.setWordWrap(True)

# Giving string values to the created labels
self.title.setText("TASKS:")
Expand Down Expand Up @@ -104,6 +103,7 @@ def __init__(self, parent: str, task_list_file: str, style_sheet_file: str):
# Int variable that keeps track of how many tasks have been done
self.current_tasks = 0

# Checks if the function check_box_state was called
self.was_check_box_called = False

# Open json file and store it as a dictionary of dictionaries of strings and lists
Expand All @@ -115,7 +115,7 @@ def __init__(self, parent: str, task_list_file: str, style_sheet_file: str):
outer_layout.addWidget(self.title)
outer_layout.addWidget(self.points_earned)
outer_layout.addWidget(self.progress_bar)
inner_layout.addWidget(self.tasks_done)


for part, tasks_dict in data_list.items():
for task_title, tasks_list in tasks_dict.items():
Expand All @@ -127,8 +127,9 @@ def __init__(self, parent: str, task_list_file: str, style_sheet_file: str):
for task in tasks_list:
self.total_tasks += 1
spliced_task = task.split('\t')
task = f"{spliced_task[0]:.<70}{spliced_task[1]:>10}"
task = f"{spliced_task[0]:.<70}{spliced_task[1]}"
self.checkBox = qtw.QCheckBox(parent) # Create a new check box for each task
self.checkBox.setStyleSheet("QCheckBox::indicator {width: 20px; height: 20px;}")
self.checkBox.setText(task) # Add the task text
inner_layout.addWidget(self.checkBox) # Add the checkbox widget onto the inner_layout
match = re.search(point_search, task) # Parse the task for its point value
Expand All @@ -140,7 +141,7 @@ def __init__(self, parent: str, task_list_file: str, style_sheet_file: str):
self.show() # Idk what this is but it helped format things good

if self.was_check_box_called == False:
self.points_earned.setText(f"POINTS EARNED: {self.current_points} / {self.total_points} TASKS COMPLETED: {self.current_tasks} / {self.total_tasks}")
self.points_earned.setText(f"POINTS EARNED: {self.current_points} / {self.total_points} TASKS COMPLETED: {self.current_tasks} / {self.total_tasks}")



Expand All @@ -157,7 +158,7 @@ def check_box_state (self, state):
self.current_tasks -= 1
self.current_points -= self.task_dict[sender.text()] # Remove from the current score

self.points_earned.setText(f"POINTS EARNED: {self.current_points} / {self.total_points} TASKS COMPLETED: {self.current_tasks} / {self.total_tasks}")
self.points_earned.setText(f"POINTS EARNED: {self.current_points} / {self.total_points} TASKS COMPLETED: {self.current_tasks} / {self.total_tasks}")

self.prog_par_percent = int(100 * (self.current_points/self.total_points)) # Get % of how many points earned

Expand Down

1 comment on commit b25ce41

@steph1111
Copy link
Member

@steph1111 steph1111 commented on b25ce41 Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work on this!! This looks so good and works really well so far. For your first gui this is super impressive 😤

Problem with formatting tasks

It turns out that in the terminal, the way characters are spaced in stdout is different than they are in qt which is really annoying. I tried messing with this for a while and did not really get anywhere yet. I tried making a custom formatter which did not assume characters in python and qt were one to one but there was no luck there :/ My solutions for now would be
1. Do what you were doing before with manually entering the dots in the .json file and test till you find the right ratio. This seems extremely painful tho so only do this if you really want to
2. I did some research and it looks like instead of using the text that goes with QCheckBox, pair the checkbox with a QLabel. Then wed have a layout kinda like an HBox for each task. In which the first item is the task and the second is the points. We could then align the points all the way to the right which would at least align all the points, still no dots tho
3. The last idea would be to see if we can mess with the css of the text to make it mono spaced and maybe that could fix things. This is probably the most promising, but wed have to look further into it. UPDATE this is definitely what we want to do here. I tried it and it works

Parent everywhere

You actually do not need to provide parent when you are creating a widget, I ran your code again without parent and it works the same

# Orig
self.progress_bar = qtw.QProgressBar(parent)
# Update 
self.progress_bar = qtw.QProgressBar()

A bit more pythonic

This does not affect how your code runs, just some fun python tricks you can choose to use or not, this really does not matter

>>> task = "Deploy SMART cable on seafloor (1) \t 5pts"
>>> task_name, pts = task.split("\t")
>>> task_name 
'Deploy SMART cable on seafloor (1) '
>>> pts
' 5pts'
>>> pts.strip(" pts")
'5'

Order of items

Rearrange your addWidget() calls such that the titles and progress bar get added before the scroll area

outer_layout.addWidget(self.title)
outer_layout.addWidget(self.points_earned)
outer_layout.addWidget(self.progress_bar)
inner_layout.addWidget(self.tasks_done)
outer_layout.addWidget(scroll_area)

Please sign in to comment.