PDA

View Full Version : [PyQt4]—Visual display of a register



osfd
10th January 2012, 17:24
Hi there,
I use a micro-controller (uc) to control an asic (Application Specific Integrated Circuit). To do so, I wrote a PyQt4 application with a lot of qlineedit and qdoublespinbox and a few buttons. The buttons send to the uc the relevant information according to the content of lines and double spinboxes. The uc translates data to the asic protocol and talk to him. The communication is made through serial com using pyserial…
Most of my registers are less than 8 bits long and the user enter the values with doublespinboxes. Though, I have a bunch of registers to control that are 32 and 192 bits long. I found a turnaround to easily enter the values but I would like to give the user a way to check and type values in an easier way.
So far I use a QLineEdit with the following syntax for a 32 bits register:
0:23,24,25:31=0,1,0
which means from 0 to 23 the value is 0 then 1 for 24th bit and then 0 for 25 to 31
of course, I wrote a small parser to convert the QLineEdit to serial bits that the uc understand.
My idea is represented by the figure below :

http://olivierlemaire.files.wordpress.com/2012/01/visual_long_register.png

I would like, according to the above example, that all squares are red (Low state) except for 24 that should be green (Active state) !! Of course, that would be great if I could also toggle the states by clicking on the cells of this widget…
My issue is that I just don’t know how to do that… I kinda see a turnaround using checkboxes but I don’t think I can put numbers in. I tried with a qtablewidget, not so successful ! maybe with toggle button and changing the background color according to its state… Really, I don’t know.
Thanks in advance for your help.
Have a good one,
Olivier

Lykurg
10th January 2012, 17:35
For simplicity I would simply subclass a QWidget and do all the painting myself. It isn't so hard. Then reimp mousePressEvent and calculate which bit was clicked using the x coordinate of the mousepressevent. Alter private member "currentBit" and force a repaint by calling update()...