Skip to content

Commit

Permalink
Merge branch '1.0.0-dev' into aspect
Browse files Browse the repository at this point in the history
  • Loading branch information
dl1com authored Oct 17, 2023
2 parents 0c28644 + 66f3411 commit 4298f73
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-multi-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ jobs:
echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
echo "python=python${{matrix.python-version}}" >> $GITHUB_OUTPUT
echo "manifest=$(cat src/main/resources/base/ayab/firmware/manifest.txt)" >> $GITHUB_OUTPUT
echo "python-appimage=python${{matrix.python-version}}.17-cp38-cp38-manylinux2014_x86_64.AppImage" >> $GITHUB_OUTPUT
echo "python-appimage=python${{matrix.python-version}}.18-cp38-cp38-manylinux2014_x86_64.AppImage" >> $GITHUB_OUTPUT
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
8 changes: 6 additions & 2 deletions src/main/python/ayab/ayab.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ def __activate_ui(self):
def __activate_menu(self):
self.menu.ui.action_open_image_file.triggered.connect(
self.scene.ayabimage.select_file)
self.menu.ui.action_quit.triggered.connect(
QCoreApplication.instance().quit)
self.menu.ui.action_quit.triggered.connect(self.__quit)
self.menu.ui.action_load_AYAB_firmware.triggered.connect(
self.flash.open)
self.menu.ui.action_cancel.triggered.connect(self.engine.cancel)
Expand All @@ -126,6 +125,11 @@ def __set_prefs(self):
self.prefs.open_dialog()
self.scene.refresh()

def __quit(self):
logging.debug("Quitting")
QCoreApplication.instance().quit()
sys.exit()

def start_knitting(self):
"""Start the knitting process."""
self.start_operation()
Expand Down
6 changes: 4 additions & 2 deletions src/main/python/ayab/engine/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ def req_test_API6(self):
self.__ser.write(data)

def req_start_API6(self, start_needle, stop_needle,
continuous_reporting):
continuous_reporting, disable_hardware_beep):
"""Send a start message to the device."""
data = bytearray()
data.append(Token.reqStart.value)
data.append(start_needle)
data.append(stop_needle)
data.append(continuous_reporting)
data.append(
1 * continuous_reporting +
2 * (not disable_hardware_beep))
hash = 0
hash = add_crc(hash, data)
data.append(hash)
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/ayab/engine/communication_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def req_test_API6(self) -> None:
self.rx_msg_list.append(cnfTest)

def req_start_API6(self, start_needle, stop_needle,
continuous_reporting) -> None:
continuous_reporting, disable_hardware_beep) -> None:
"""Send a request to start knitting."""
self.__is_started = True
cnfStart = bytes([Token.cnfStart.value, 0])
Expand Down
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 @@ -63,6 +63,7 @@ def start(self, pattern, options, operation):
self.mode = options.mode
self.inf_repeat = options.inf_repeat
self.continuous_reporting = options.continuous_reporting
self.prefs = options.prefs
self.len_pat_expanded = self.pat_height * self.num_colors
self.passes_per_row = self.mode.row_multiplier(self.num_colors)
self.start_needle = max(0, self.pattern.pat_start_needle)
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/ayab/engine/engine_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _API6_request_start(control, operation):
# request start
control.com.req_start_API6(control.pattern.knit_start_needle,
control.pattern.knit_end_needle - 1,
control.continuous_reporting)
control.continuous_reporting,
control.prefs.value("disable_hardware_beep"))
control.state = State.CONFIRM_START
control.logger.debug("State CONFIRM_START")
else:
Expand Down
14 changes: 12 additions & 2 deletions src/main/python/ayab/firmware_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import QSettings, QCoreApplication
from PyQt5.QtWidgets import QFrame, QListWidgetItem
from PyQt5.QtWidgets import QDialog, QListWidgetItem

import serial
import json
Expand All @@ -33,8 +33,10 @@
from .firmware_flash_gui import Ui_Firmware
from . import utils

# press Esc to Quit dialog
# press Return to Flash firmware

class FirmwareFlash(QFrame):
class FirmwareFlash(QDialog):
# Arduino devices and their `avrdude` names
device_dict = {
"uno": "atmega328p",
Expand All @@ -53,6 +55,7 @@ def __init__(self, parent):
self.ui = Ui_Firmware()
self.ui.setupUi(self)
self.ui.flash_firmware.setEnabled(False)
self.ui.flash_firmware.setDefault(True)
self.load_json()

self.ui.port_combo_box.currentIndexChanged.connect(self.port_selected)
Expand All @@ -67,6 +70,12 @@ def open(self):
self.port_selected()
self.show()

def close(self):
"""Close dialog and clean firmware list."""
#self.clean_controller_list()
self.clean_firmware_list()
self.accept()

def load_json(self):
self.json_object = self.parse_json("")
self.add_items_from_json_object()
Expand Down Expand Up @@ -158,6 +167,7 @@ def execute_flash_command(self):
self.__logger.info("Flashing done!")
utils.display_blocking_popup(
tr_("Firmware", "Flashing done!"))
self.close()
return True

def generate_command(self, base_dir, os_name, controller_name,
Expand Down
12 changes: 6 additions & 6 deletions src/main/python/ayab/firmware_flash_gui.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Firmware</class>
<widget class="QFrame" name="FirmwareFlashFrame">
<widget class="QDialog" name="FirmwareFlashFrame">
<property name="geometry">
<rect>
<x>0</x>
Expand All @@ -13,11 +13,8 @@
<property name="windowTitle">
<string>Firmware Flashing Utility</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<property name="modal">
<bool>True</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down Expand Up @@ -78,6 +75,9 @@ p, li { white-space: pre-wrap; }
<property name="text">
<string>Flash</string>
</property>
<property name="flat">
<bool>False</bool>
</property>
</widget>
</item>
<item>
Expand Down
25 changes: 12 additions & 13 deletions src/main/python/ayab/knitprogress.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# https://github.com/AllYarnsAreBeautiful/ayab-desktop

from PyQt5.QtCore import Qt, QCoreApplication, QRect, QSize
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem, QLabel, QSizePolicy, QAbstractItemView, QWidget, QHBoxLayout
from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem, QLabel, QSizePolicy, QAbstractItemView, QWidget, QHBoxLayout, QHeaderView
from bitarray import bitarray

from . import utils
Expand All @@ -39,10 +39,9 @@ def __init__(self, parent):
super().__init__(parent.ui.graphics_splitter)
self.clear()
self.setRowCount(0)
self.setStyleSheet("border-width: 0;")
self.setGeometry(QRect(0, 0, 700, 220))
self.setContentsMargins(1, 1, 1, 1)
self.verticalHeader().setDefaultSectionSize(16)
self.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
self.verticalHeader().setVisible(False)
self.blank = QTableWidgetItem()
self.blank.setSizeHint(QSize(0, 0))
Expand Down Expand Up @@ -115,15 +114,15 @@ def update(self, status, row_multiplier, midline, auto_mirror):
status.bits.reverse()
midline = len(status.bits) - midline

table_text = "<table style='cell-spacing: 1; cell-padding: 1; background-color: #{:06x};'><tr> ".format(
table_text = "<table style='cell-spacing: 1; cell-padding: 1; background-color: #{:06x};'><tr>".format(
self.orange)
for c in range(0, midline):
table_text += self.__stitch(status.color, status.bits[c],
status.alt_color)
table_text += "</tr></table>"
left_side = QLabel(table_text)

table_text = "<table style='cell-spacing: 1; cell-padding: 1; background-color: #{:06x};'><tr> ".format(
table_text = "<table style='cell-spacing: 1; cell-padding: 1; background-color: #{:06x};'><tr>".format(
self.green)
for c in range(midline, len(status.bits)):
table_text += self.__stitch(status.color, status.bits[c],
Expand All @@ -137,8 +136,10 @@ def update(self, status, row_multiplier, midline, auto_mirror):
n_cols = len(columns)
self.setCellWidget(0, n_cols, left_side)
self.setCellWidget(0, n_cols + 1, right_side)
if row_multiplier == 1:
self.hideColumn(1)
if n_cols < 4:
self.horizontalHeader().hideSection(5)
self.hideColumn(5)
self.resizeColumnsToContents()

self.previousStatus = status
Expand All @@ -147,20 +148,18 @@ def update(self, status, row_multiplier, midline, auto_mirror):
self.scene.row_progress = status.current_row

def __item(self, text):
table = "<table><tr><td>" + text + "</td></tr></table>"
item = QTableWidgetItem(text)
return item

def __stitch(self, color, bit, alt_color=None):
# FIXME: borders are not visible
text = "<td width='12' style='"
text = "<td width='12' style='border: 1 black "
if bit:
text += "border: 1 solid black; background-color: #{:06x};".format(
text += "solid; background-color: #{:06x};".format(
color)
elif alt_color is not None:
text += "border: 1 solid black; background-color: #{:06x};".format(
text += "solid; background-color: #{:06x};".format(
alt_color)
else:
text += "border: 1 dotted black;"
text += "'/>"
return text
text += "dotted;"
return text + "'/>"
1 change: 1 addition & 0 deletions src/main/python/ayab/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Preferences(SignalSender):
'aspect_ratio': AspectRatio,
# 'default_continuous_reporting': bool,
'quiet_mode': bool,
'disable_hardware_beep': bool,
'language': Language,
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/python/ayab/tests/test_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ def test_update_API6(self):
assert result == expected_result

def test_req_start_API6(self):
start_val, end_val, continuous_reporting, crc8 = 0, 10, True, 0x36
start_val, end_val, continuous_reporting, disable_hardware_beep, crc8 = 0, 10, True, False, 0x8A
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
byte_array = bytearray([
Token.slipFrameEnd.value, Token.reqStart.value,
start_val, end_val, continuous_reporting, crc8,
Token.slipFrameEnd.value,
Token.reqStart.value,
start_val,
end_val,
1 * continuous_reporting + 2 * (not disable_hardware_beep),
crc8,
Token.slipFrameEnd.value
])
bytes_read = self.dummy_serial.read(len(byte_array))
Expand Down
10 changes: 6 additions & 4 deletions src/main/python/ayab/tests/test_communication_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def test_update_API6(self):
assert self.comm_dummy.update_API6() == (None, Token.none, 0)

def test_req_start_API6(self):
start_val, end_val, continuous_reporting, crc8 = 0, 10, True, 0xb9
start_val, end_val, continuous_reporting, disable_hardware_beep = 0, 10, True, False
expected_result = (bytes([Token.cnfStart.value, 0]), Token.cnfStart, 0)
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
bytes_read = self.comm_dummy.update_API6()
assert bytes_read == expected_result

Expand Down Expand Up @@ -86,9 +87,10 @@ def test_cnf_line_API6(self):

def test_req_line_API6(self):
self.comm_dummy.open_serial()
start_val, end_val, continuous_reporting = 0, 10, True
start_val, end_val, continuous_reporting, disable_hardware_beep = 0, 10, True, False
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
self.comm_dummy.update_API6() # cnfStart

for i in range(0, 256):
Expand Down

0 comments on commit 4298f73

Please sign in to comment.