Skip to content

Commit

Permalink
Restore sequence file viewer code that got nuked at some point
Browse files Browse the repository at this point in the history
  • Loading branch information
gribeill committed Jul 29, 2019
1 parent 7513451 commit ab5b379
Showing 1 changed file with 122 additions and 1 deletion.
123 changes: 122 additions & 1 deletion QGL/drivers/APS2Pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

# Whether we use PHASE_OFFSET modulation commands or bake it into waveform
# Default to false as we usually don't have many variants
USE_PHASE_OFFSET_INSTRUCTION = True
USE_PHASE_OFFSET_INSTRUCTION = False

# Whether to save the waveform offsets for partial compilation
SAVE_WF_OFFSETS = False
Expand Down Expand Up @@ -1557,3 +1557,124 @@ def display_raw_instructions(raw):
def display_raw_file(filename):
raw = raw_instructions(filename)
display_raw_instructions(raw)

if __name__ == '__main__':
if len(sys.argv) == 2:

from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QTableWidget, QTableWidgetItem, QVBoxLayout, QAbstractItemView, QPushButton
from PyQt5.QtGui import QIcon, QColor, QFont

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
from matplotlib.figure import Figure

table_font = QFont("Arial", weight=QFont.Bold)

colors = {"WFM": QColor(0,200,0),
"GOTO": QColor(0,100,100),
"MARKER": QColor(150,150,200)}

class MatplotlibWidget(QWidget):
def __init__(self, I, Q, parent=None):
super(MatplotlibWidget, self).__init__(parent)
self.title = 'Waveform'
self.left = 100
self.top = 100
self.width = 800
self.height = 600
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)

self.figure = Figure()
self.canvas = FigureCanvasQTAgg(self.figure)

self.axis = self.figure.add_subplot(111)
self.axis.plot(I)
self.axis.plot(Q)
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.canvas)
self.setLayout(self.layout)
self.canvas.draw()
self.show()


class App(QWidget):

COLUMN_COUNT = 7
def __init__(self, instructions, waveforms):
super().__init__()
self.title = 'APS2 Disassembled Instructions'
self.left = 100
self.top = 100
self.width = 1000
self.height = 1200
self.instructions = instructions
self.waveforms = waveforms
print(self.waveforms)
self.initUI()
self.plotters = []

def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)

self.createTable()
self.layout = QVBoxLayout()
self.layout.addWidget(self.tableWidget)
self.setLayout(self.layout)

# Show widget
self.show()

def createTable(self):
# Create table
self.tableWidget = QTableWidget()
self.tableWidget.setRowCount(len(self.instructions))
self.tableWidget.setColumnCount(7)

for k, instr in enumerate(self.instructions):
fields = str(instr).replace(',','').replace(';', '').split(" ")
if "|" in fields:
fields.remove("|")
if fields[0] in colors:
color = colors[fields[0]]
else:
color = None
for l, f in enumerate(fields):
text = fields[l]
if text == "GOTO":
btn = QPushButton(self.tableWidget)
btn.setText('GOTO')
target_row = int(fields[1].split("=")[1])
def scroll_to_goto_target(row=target_row, tab=self.tableWidget):
tab.scrollToItem(tab.item(row, 0))
btn.clicked.connect(scroll_to_goto_target)
self.tableWidget.setCellWidget(k, l, btn)
if text == "WFM" and int(fields[4].split("=")[1])==0:
# Not a TA pair
btn = QPushButton(self.tableWidget)
btn.setText('WFM')
addr = int(fields[6].split("=")[1])
count = int(fields[5].split("=")[1])
def open_plotter(addr=None, I=self.waveforms[0][addr:addr+count], Q=self.waveforms[1][addr:addr+count]):
w = MatplotlibWidget(I,Q)
self.plotters.append(w)
btn.clicked.connect(open_plotter)
self.tableWidget.setCellWidget(k, l, btn)
else:
item = QTableWidgetItem(text)
item.setFont(table_font)
if color:
item.setBackground(color)
self.tableWidget.setItem(k, l, item)
if l < self.COLUMN_COUNT-1:
for j in range(l+1, self.COLUMN_COUNT):
item = QTableWidgetItem("")
if color:
item.setBackground(color)
self.tableWidget.setItem(k, j, item)
self.tableWidget.move(0,0)
self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)

app = QApplication(sys.argv[:1])
ex = App(read_instructions(sys.argv[1]), read_waveforms(sys.argv[1]))
sys.exit(app.exec_())

0 comments on commit ab5b379

Please sign in to comment.