Skip to content

Commit

Permalink
bg coloring for current color label
Browse files Browse the repository at this point in the history
  • Loading branch information
X-sam committed Jul 4, 2024
1 parent cafe9ab commit 4953616
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/main/python/ayab/engine/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def cnf_line_API6(self, line_number: int) -> bool:
return True # pattern finished

def __update_status(self, line_number: int, color: int, bits: bitarray) -> None:
self.status.total_rows = self.pat_height
self.status.current_row = self.pat_row + 1
self.status.line_number = line_number
if self.inf_repeat:
Expand Down
10 changes: 4 additions & 6 deletions src/main/python/ayab/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def knit_config(self, image: Image.Image) -> None:
self.pattern.alignment = self.config.alignment

# update progress bar
self.emit_progress_bar_updater(
self.config.start_row + 1, self.pattern.pat_height, 0, ""
)
data = Status()
data.copy(self.status)
self.emit_progress_bar_updater(data)

# switch to status tab
# if self.config.continuous_reporting:
Expand Down Expand Up @@ -214,9 +214,7 @@ def __handle_status(self) -> None:
self.control.midline,
self.config.auto_mirror,
)
self.emit_progress_bar_updater(
data.current_row, self.pattern.pat_height, data.repeats, data.color_symbol
)
self.emit_progress_bar_updater(data)

def cancel(self) -> None:
self.__canceled = True
2 changes: 2 additions & 0 deletions src/main/python/ayab/engine/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ def copy(self, status: Status) -> None:
self.carriage_type = status.carriage_type
self.carriage_position = status.carriage_position
self.carriage_direction = status.carriage_direction
self.total_rows = status.total_rows
self.mirror = status.mirror

def parse_device_state_API6(self, state: Any, msg: bytes) -> None:
if not (self.active):
Expand Down
26 changes: 16 additions & 10 deletions src/main/python/ayab/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

from __future__ import annotations
from typing import TYPE_CHECKING
from PySide6.QtGui import QColor

if TYPE_CHECKING:
from .ayab import GuiMain
from .engine.status import ColorSymbolType
from .engine.status import Status


class ProgressBar(object):
Expand All @@ -40,23 +41,22 @@ def reset(self) -> None:
self.total = -1
self.repeats = -1
self.color = ""
self.backgroundColor = 0xFFFFFF
self.__row_label.setText("")
self.__color_label.setText("")
self.__status_label.setText("")

def update(
self,
row: int,
total: int = 0,
repeats: int = 0,
color_symbol: ColorSymbolType = "",
status: Status
) -> bool:
if row < 0:
if status.current_row < 0:
return False
self.row = row
self.total = total
self.repeats = repeats
self.color = color_symbol
self.row = status.current_row
self.total = status.total_rows
self.repeats = status.repeats
self.color = status.color_symbol
self.backgroundColor = status.color
self.refresh()
return True

Expand All @@ -69,6 +69,12 @@ def refresh(self) -> None:
color_text = ""
else:
color_text = "Color " + self.color
bgColor = QColor.fromRgb(self.backgroundColor)
if bgColor.lightness() < 128:
fgColor = 0xffffff
else: fgColor = 0x000000
self.__color_label.setStyleSheet("QLabel {background-color: "+f"#{self.backgroundColor:06x}"+f";color:#{fgColor:06x}"+";}")

self.__color_label.setText(color_text)

# Update labels
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/ayab/signal_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SignalReceiver(QObject):
# signals are defined as class attributes which are
# over-ridden by instance attributes with the same name
start_row_updater = Signal(int)
progress_bar_updater = Signal(int, int, int, str)
progress_bar_updater = Signal(Status)
knit_progress_updater = Signal(Status, int, int, bool)
notifier = Signal(str, bool)
# statusbar_updater = Signal('QString', bool)
Expand Down
4 changes: 2 additions & 2 deletions src/main/python/ayab/signal_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def emit_start_row_updater(self, start_row: int) -> None:
self.__signal_receiver.start_row_updater.emit(start_row)

def emit_progress_bar_updater(
self, row: int, total: int, repeats: int, color_symbol: ColorSymbolType
self, status: Status
) -> None:
self.__signal_receiver.progress_bar_updater.emit(
row, total, repeats, color_symbol
status
)

def emit_knit_progress_updater(
Expand Down

0 comments on commit 4953616

Please sign in to comment.