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

Pull request for check_list.py widget #213

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3d2e94e
made check_list.py, added starter code, made tasks.txt, added tasks.
tinymassi Feb 19, 2024
f8a9e44
added widget creation code & some button code
tinymassi Feb 22, 2024
191b946
forgot to save changes before last commit
tinymassi Feb 22, 2024
256a486
Added txt parsing and code to store & publish tasks as checkboxes
tinymassi Feb 23, 2024
89b066c
small changes to comments
tinymassi Feb 23, 2024
e5a38b9
updating everything for git clone
tinymassi Feb 23, 2024
55eaf87
changed tasks.txt to tasks.json
tinymassi Feb 24, 2024
dd8f271
Modified json file, changed parsing methods
tinymassi Feb 24, 2024
18d47a4
added progress bar and checkbox functionality
tinymassi Feb 24, 2024
6afce70
Customized progress bar and scroll wheel through stolen code
tinymassi Feb 29, 2024
7caa8b6
Reformatted json file to hopefully line up point values in widget
tinymassi Feb 29, 2024
f624632
put prog bar on outerlayout, added extra details regarding tasks fini…
tinymassi Feb 29, 2024
b25ce41
added better text alignment
tinymassi Feb 29, 2024
a9dbfac
Fixed missing import, updated file name, css for main win
steph1111 Feb 29, 2024
93f1217
CSS style file for check list widget
steph1111 Feb 29, 2024
5cef2cc
Merge branch 'check-list-widget' of github.com:CabrilloRoboticsClub/c…
steph1111 Feb 29, 2024
ca27352
Added text customization. Edited a couple of things in json file
tinymassi Mar 1, 2024
8ed92c7
Merge branch 'check-list-widget' of github.com:CabrilloRoboticsClub/c…
tinymassi Mar 1, 2024
8649938
added CSS code. not sure if it works yet
tinymassi Mar 6, 2024
524a729
Added CSS code and removed redundant code from check_list.py
tinymassi Mar 8, 2024
ebca767
almost finalized version of check_list.py
tinymassi Mar 9, 2024
c5dcc1f
Merge branch 'dashboard' of github.com:CabrilloRoboticsClub/cabrillo_…
steph1111 Mar 9, 2024
a2e935c
Merge branch 'check-list-widget-new' of github.com:CabrilloRoboticsCl…
steph1111 Mar 9, 2024
b700816
implemented check_list widget onto dashboard
steph1111 Mar 9, 2024
043f67b
updated color names for css
tinymassi Mar 15, 2024
8f32433
commiting before updating new color values in color_pallete.py
tinymassi Mar 15, 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
11 changes: 11 additions & 0 deletions src/seahawk/seahawk_deck/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from seahawk_deck.dash_widgets.state_widget import StateWidget
from seahawk_deck.dash_widgets.throttle_curve_widget import ThrtCrvWidget
from seahawk_deck.dash_widgets.turn_bank_indicator_widget import TurnBankIndicator
from seahawk_deck.dash_widgets.check_list import CheckList
from seahawk_deck.set_remote_params import SetRemoteParams
from seahawk_msgs.msg import InputStates

Expand Down Expand Up @@ -224,6 +225,7 @@ def update_colors(self, new_colors: dict):
self.tab_widget.depth_widget.set_colors(self.colors)
self.tab_widget.turn_bank_indicator_widget.set_colors(self.colors)
self.tab_widget.countdown_widget.set_colors(self.colors)
self.tab_widget.checklist_widget.set_colors(self.colors)


class TabWidget(qtw.QWidget):
Expand Down Expand Up @@ -281,6 +283,8 @@ def __init__(self, parent: MainWindow, ros_qt_bridge: RosQtBridge, style_sheet_f

# Create specific tabs
self.create_pilot_tab(self.tab_dict["Pilot"])
self.create_copilot_tab(self.tab_dict["Co-Pilot"])


# Apply css styling
self.set_colors(self.colors)
Expand Down Expand Up @@ -355,6 +359,13 @@ def create_pilot_tab(self, tab: qtw.QWidget):

home_window_layout.addLayout(vert_widgets_layout, stretch=1)
home_window_layout.addLayout(cam_layout, stretch=9)

def create_copilot_tab(self, tab: qtw.QWidget):
home_window_layout = qtw.QHBoxLayout(tab)

self.checklist_widget = CheckList(tab, PATH + "/dash_widgets/tasks.json", PATH + "/dash_styling/check_list.txt", self.colors)

home_window_layout.addWidget(self.checklist_widget)

@staticmethod
def update_cam_img(data: Image, video_frame: VideoFrame):
Expand Down
76 changes: 76 additions & 0 deletions src/seahawk/seahawk_deck/dash_styling/check_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
QFrame {{
background-color: {SURFACE_PRIMARY};
border-radius: 10px;
}}

QProgressBar {{
background: {SURFACE_PRIMARY};
border: 2px solid {ACCENT};
border-radius: 5px;
qproperty-alignment: AlignCenter;
color: white;
text-align: center;
}}

QProgressBar::chunk {{
background-color: {ACCENT};
width: 20px;
}}

QCheckBox {{
color: {TEXT_EMPH};
font-family: "Courier New", Monospace;
font-size: 13pt;
background: {SURFACE_PRIMARY};
}}

QCheckBox::indicator {{
width: 20px;
height: 20px;
}}

QCheckBox:hover {{
color: white;
}}

QLabel[accessibleName="title"] {{
color: white;
font-family: "Courier New", Monospace;
font-size: 30pt;
font-weight: bold;
}}

QLabel[accessibleName="points_earned"] {{
color: {TEXT_EMPH};
font-family: "Courier New", Monospace;
font-size: 15pt;
font-weight: bold;
border-radius: 5px;
}}

QLabel[accessibleName="task_titles"] {{
color: white;
font-family: "Courier New", Monospace;
font-size: 16pt;
font-weight: bold;
}}

QScrollBar:vertical {{
border: none;
width: 10px;
margin: 0px 0px 0px 0px;
}}

QScrollBar::handle:vertical {{
background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
stop: 0 {ACCENT}, stop: 0.5 {ACCENT}, stop:1 {ACCENT});
min-height: 0px;
border-radius: 5px;
}}

QScrollBar::add-line:vertical {{
background: {TAB_BKG};
width: 20px;
subcontrol-position: right;
subcontrol-origin: margin;
}}
164 changes: 164 additions & 0 deletions src/seahawk/seahawk_deck/dash_widgets/check_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# dash_widgets/check_list.py
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtGui as qtg
from PyQt5 import QtCore as qtc
# from PyQt5.QtMultiMedia import Qsound # implement sound???

import re
import json


class CheckList(qtw.QWidget):
"""
Creates a 'CheckList' which inherits from the 'qtw.QWidget' class. A 'CheckList'
functions as a task checklist. Tasks and their point values are read from a
file then listed as a check-able list. Once a task is checked off, the points for
that task are added to a sum and graphically displayed on a progress bar
"""

def __init__(self, parent: str, task_list_file: str, style_sheet_file: str, colors: dict):
"""
Initialize checklist widget

Args:
parent: Widget to overlay 'CheckList' on
task_list_file: File containing a list of tasks to be displayed
style_sheet_file: Style sheet text file formatted as a CSS f-string
"""
super().__init__(parent)

with open (style_sheet_file) as style_sheet:
self.style_sheet = style_sheet.read()

# Create layout where widget will be mounted on parent
outer_layout = qtw.QVBoxLayout(self)
self.setLayout(outer_layout)

# Add a widget to mount to the outer layout
frame = qtw.QFrame()
outer_layout.addWidget(frame)

# Add a grid to the widget to add text & features
inner_layout = qtw.QVBoxLayout(frame)
frame.setLayout(inner_layout)

inner_layout.addStretch()

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

# Creating a label for points earned
self.points_earned = qtw.QLabel(parent)
self.points_earned.setAlignment(qtc.Qt.AlignCenter)
self.points_earned.setAccessibleName("points_earned")

# Giving string values to the created labels
self.title.setText("TASKS:")

# Create a scroll area template
scroll_area = qtw.QScrollArea()

# Make the scroll_area resizeable with window
scroll_area.setWidgetResizable(True)

# Create the scroll area on the main frame
scroll_area.setWidget(frame)

# Creating the progress bar
self.progress_bar = qtw.QProgressBar(parent)

# Has the task as a key, and a its # of points as value
self.task_dict = {}

# Variable to store points of each task
self.points = 0

# Variable for the total points achievable for comp
self.total_points = 0

# Variable for keeping track of current points earned
self.current_points = 0

# Variable for keeping track of progress bar percentage
self.prog_par_percent = 0

# Used later to grab point value out of string task
point_search = r"(\d+)pts"

# Int variable that stores total tasks
self.total_tasks = 0

# 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
with open(task_list_file, 'r') as file:
data_list = json.load(file)

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

for part, tasks_dict in data_list.items():
for task_title, tasks_list in tasks_dict.items():
if self.total_tasks != 0:
inner_layout.addSpacing(20) # Space things out by 20 pixels
self.task_titles = qtw.QLabel(parent) # Create new task title for each task_title
self.task_titles.setAccessibleName("task_titles")
self.task_titles.setText(task_title) # Set the task_title text
inner_layout.addWidget(self.task_titles) # Add the task title as a widget to the inner layout
for task in tasks_list:
self.total_tasks += 1
spliced_task = task.split('\t')
task = f"{spliced_task[0]:.<55}{spliced_task[1]}"
self.checkBox = qtw.QCheckBox(parent) # Create a new check box for each task
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
self.points = int(match.group(1)) # Add the point value to the points variable
self.total_points += self.points
self.task_dict[task] = self.points # Store the task and its point value in a dictionary
inner_layout.addSpacing(10) # Space the check boxes out
self.checkBox.stateChanged.connect(self.check_box_state) # Keep track of each checkbox state
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.set_colors(colors)


def check_box_state (self, state):
sender = self.sender() # Find the checkbox that was pressed

was_check_box_called = True

if state == qtc.Qt.Checked: # If the button has been pressed
self.current_tasks += 1
self.current_points += self.task_dict[sender.text()] # Add to the current score

else: # If the button has been de-selected
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.prog_bar_percent = int(100 * (self.current_points/self.total_points)) # Get % of how many points earned

self.progress_bar.setValue(self.prog_bar_percent) # Update progress bar to this new percentage


def set_colors(self, new_colors: dict):
self.setStyleSheet(self.style_sheet.format(**new_colors))


# Uncomment later when we add the CSS
# with open(style_sheet_file) as style_sheet:
# self.setStyleSheet(style_sheet.read().format(**COLOR_CONSTS))
# test.py
73 changes: 73 additions & 0 deletions src/seahawk/seahawk_deck/dash_widgets/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"part_1": {
"[1.1] Multi Function Node Tasks:": [
"Trigger release of multi-func node's recovery float \t 10pts",
"Visually determine failed recovery float \t 5pts",
"Pull pin & release failed recovery float \t. 10pts",
"Return failed recovery float to surface \t 5pts",
"Connect recovery line to bale on multi-func node \t 15pts",
"Manually return multi-func node to surface \t 5pts"
]
},

"part_2": {
"[2.1] SMART Cable Tasks:": [
"Deploy SMART cable on seafloor (1) \t 5pts",
"Deploy SMART cable on seafloor (2) \t 5pts",
"Deploy SMART cable on seamount \t 10pts",
"Place SMART repeater in designated area \t 10pts",
"Return end of cable to surface \t 5pts",
"Measure temp to check SMART cable sensor \t 15pts",
"Retrieve power connector from AUV \t 5pts",
"Install power connector \t 15pts"
]
},

"part_3": {
"[3.1] Probiotics 2:": [
"Place irrigation sys in loc \t 10pts",
"Deploy sprinkler on coral head \t 10pts",
"Activate irrigation sys \t 10pts"
],

"[3.2] Coral Restoration:": [
"Transplant branching coral \t 10pts",
"Transplant brain coral (autonomously) \t 30pts"
],

"[3.3] 3D Coral Modeling (Autonomous):": [
"Create 3D model of coral area \t 20pts",
"Measure length of coral area \t 10pts",
"Scale 3D model using len of coral area \t 5pts",
"Use 3D model to estimate height of coral area \t 10pts"
],

"[3.3] 3D Coral Modeling (Manual):": [
"Measure len of coral area \t 10pts",
"Measure height of coral area \t 10pts",
"Create 3D model of coral area \t 10pts"
],

"[3.4] Sturgeon Spawning Ground Tasks:": [
"Recover acoustic receiver \t 10pts",
"Create graph of sturgeon loc from receiver data \t 15pts",
"Determine spawning site \t 5pts",
"Place ADCP \t 10pts",
"Recover sediment sample \t 10pts"
]
},

"part_4": {
"[4.0] Float Tasks:": [
"Build vertical profile float \t 5pts",
"Deploy float \t 5pts",
"Float comms w/ mission station b4 descent \t 10pts",
"Float completes vert prof w/ buoyancy engine (1) \t 10pts",
"Float comms data w/ mission station (1) \t 5pts",
"Data graph of depth vs time (2) \t 10pts",
"Float completes vert prof w/ buoyancy engine (2) \t 10pts",
"Float comms data w/ mission station (2) \t 5pts",
"Data graph of depth vs time (2) \t 10pts"
]
}
}
Loading