Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 4 additions & 8 deletions rkdeveloptool-gui/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
PartitionPPTWorker, CommandWorker, RKFWPrepWorker, FileHashWorker,
DecompressWorker, CallWorker
)
from .ui_text_updates import populate_address_combo
from .ui_text_updates import CUSTOM_ADDRESS, populate_address_combo


def _is_sector_zero(address):
Expand Down Expand Up @@ -1251,13 +1251,9 @@ def burn_image(gui):
gui.show_message("Warning", "select_image_address", "Warning")
return

address = gui.address_combo.currentText()
if gui.tr("custom_address") in address:
address = gui.custom_address.text()
else:
match = re.search(r'\((\S+)\)', address)
if match:
address = match.group(1)
address = gui.address_combo.currentData()
if address == CUSTOM_ADDRESS:
address = gui.custom_address.text().strip()

if not address:
gui.show_message("Warning", "select_image_address", "Warning")
Expand Down
7 changes: 2 additions & 5 deletions rkdeveloptool-gui/ui_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,11 +914,8 @@ def create_log_panel(gui):

def on_address_changed(gui):
"""Handle address combo change"""
text = gui.address_combo.currentText()
if gui.tr("custom_address") in text:
gui.custom_address.setEnabled(True)
else:
gui.custom_address.setEnabled(False)
from .ui_text_updates import CUSTOM_ADDRESS
gui.custom_address.setEnabled(gui.address_combo.currentData() == CUSTOM_ADDRESS)


def change_storage(gui):
Expand Down
13 changes: 10 additions & 3 deletions rkdeveloptool-gui/ui_text_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def update_statusbar_texts(gui):
gui.update_device_status()


# Item data of the address combo's "custom address" entry.
CUSTOM_ADDRESS = "custom"


def populate_address_combo(gui):
"""Populate address combo box in download tab.

Expand All @@ -305,14 +309,17 @@ def populate_address_combo(gui):
try:
current_idx = gui.address_combo.currentIndex()
gui.address_combo.clear()
gui.address_combo.addItem(gui.tr("address_full_firmware"))
gui.address_combo.addItem(gui.tr("custom_address"))
# Each item carries its address as data: the labels differ by
# language, and parsing them sent "完整固件" to rkdeveloptool as the
# address (#85).
gui.address_combo.addItem(gui.tr("address_full_firmware"), "0x0")
gui.address_combo.addItem(gui.tr("custom_address"), CUSTOM_ADDRESS)

# Add parsed partitions if available
if hasattr(gui, 'partitions') and gui.partitions:
for name, info in gui.partitions.items():
addr = info.get('address', '')
gui.address_combo.addItem(f"{name} ({addr})")
gui.address_combo.addItem(f"{name} ({addr})", addr)

if 0 <= current_idx < gui.address_combo.count():
gui.address_combo.setCurrentIndex(current_idx)
Expand Down
38 changes: 38 additions & 0 deletions tests/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,43 @@ def check_theme_poll(app):
app.processEvents()


def check_burn_address(app):
"""Burn Image writes at the address the combo means, in every language.
The Chinese full-firmware label "0x0 (完整固件)" was parsed as the
address "完整固件" (#85)."""
from rkdeveloptool_gui import operations as ops
from rkdeveloptool_gui.ui_text_updates import populate_address_combo

work = tempfile.mkdtemp(dir=_tmp)
image = os.path.join(work, "disk.img")
with open(image, "wb") as f:
f.write(b"\0" * 510 + b"\x55\xaa" + b"\0" * 1536)
got, real = [], ops._burn_file
ops._burn_file = lambda gui, path, address, build: got.append(address)
try:
for lang in ("zh", "en"):
window = RKDevToolGUI(TranslationManager(lang=lang, settings=AppSettings()),
settings=AppSettings())
window.stop_device_detection()
window.partitions = {"boot": {"address": "0x8000"}}
populate_address_combo(window)
window.image_path.setText(image)
window.custom_address.setText(" 0x4000 ")
got.clear()
for index in range(3):
window.address_combo.setCurrentIndex(index)
ops.burn_image(window)
if got != ["0x0", "0x4000", "0x8000"]:
errors.append(f"Burn Image addresses in {lang}: {got}")
if window.custom_address.isEnabled():
errors.append("the custom address field stays enabled for a partition")
window.cleanup()
window.deleteLater()
app.processEvents()
finally:
ops._burn_file = real


def run_window(app, lang):
settings = AppSettings()
manager = TranslationManager(lang=lang, settings=settings)
Expand Down Expand Up @@ -3206,6 +3243,7 @@ def main():

check_translations()
check_qt_translation(app)
check_burn_address(app)
check_theme_poll(app)
check_partition_backup(app)
check_first_run_wizard(app)
Expand Down
Loading