Skip to content

Commit

Permalink
Color-code buffer full/empty
Browse files Browse the repository at this point in the history
  • Loading branch information
dl8dtl committed Mar 30, 2024
1 parent 3ccc199 commit 7f09662
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/python/adgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ def __init__(self, argv):
self.memories.filename.editingFinished.connect(self.detect_flash_file)
self.load_settings()

self.buffer_empty = 'background-color: rgb(255,240,240);'
self.buffer_full = 'background-color: rgb(240,255,240);'

def log(self, s: str, level: int = ad.MSG_INFO, no_nl: bool = False):
# level to color mapping
colors = [
Expand Down Expand Up @@ -704,7 +707,9 @@ def flash_read(self):
return
amnt = ad.avr_read_mem(self.pgm, self.dev, m)
self.flash_size = amnt
self.log(f"Read {amnt} bytes")
self.log(f"Read {amnt} bytes")
if amnt > 0:
self.memories.buffer.setStyleSheet(self.buffer_full)

def flash_write(self):
self.adgui.progressBar.setEnabled(True)
Expand All @@ -726,6 +731,7 @@ def clear_buffer(self):
m.clear(m.size)
self.log(f"Cleared {m.size} bytes of buffer, and allocation flags")
self.flash_size = 0
self.memories.buffer.setStyleSheet(self.buffer_empty)

def flash_save(self):
if self.memories.ffAuto.isChecked() or \
Expand Down Expand Up @@ -773,6 +779,8 @@ def flash_load(self):
amnt = ad.fileio(ad.FIO_READ, self.flashname, fmt, self.dev, "flash", -1)
self.log(f"Read {amnt} bytes from {self.flashname}")
self.flash_size = amnt
if amnt > 0:
self.memories.buffer.setStyleSheet(self.buffer_full)

def chip_erase(self):
result = QMessageBox.question(self.memories,
Expand All @@ -783,6 +791,8 @@ def chip_erase(self):
result = self.pgm.chip_erase(self.dev)
if result == 0:
self.log("Device erased")
self.flash_size = 0
self.memories.buffer.setStyleSheet(self.buffer_empty)
else:
self.log("Failed to erase device", ad.MSG_WARNING)

Expand Down
2 changes: 1 addition & 1 deletion src/python/memories.ui
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ color: rgb(180, 180, 180);</string>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
<string notr="true">background-color: rgb(255,240,240);</string>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
Expand Down

0 comments on commit 7f09662

Please sign in to comment.