gui/moninj: compute size of widgets based on font sizes

This commit is contained in:
Sebastien Bourdeauducq 2016-03-17 18:38:27 +08:00
parent f73934112b
commit fb8a5486e3
1 changed files with 20 additions and 20 deletions

View File

@ -4,7 +4,7 @@ import socket
import struct import struct
from operator import itemgetter from operator import itemgetter
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets, QtGui
from artiq.tools import TaskObject from artiq.tools import TaskObject
from artiq.protocols.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
@ -21,20 +21,30 @@ _mode_enc = {
"in": 3 "in": 3
} }
_widget_size = QtCore.QSize(350, 300)
class _MoninjWidget(QtWidgets.QFrame):
def __init__(self):
QtWidgets.QFrame.__init__(self)
qfm = QtGui.QFontMetrics(self.font())
self._size = QtCore.QSize(
29*qfm.averageCharWidth(),
10*qfm.lineSpacing())
self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.setFrameShape(QtWidgets.QFrame.Box)
self.setFrameShadow(QtWidgets.QFrame.Raised)
def sizeHint(self):
return self._size
class _TTLWidget(QtWidgets.QFrame): class _TTLWidget(_MoninjWidget):
def __init__(self, channel, send_to_device, force_out, title): def __init__(self, channel, send_to_device, force_out, title):
self.channel = channel self.channel = channel
self.send_to_device = send_to_device self.send_to_device = send_to_device
self.force_out = force_out self.force_out = force_out
QtWidgets.QFrame.__init__(self) _MoninjWidget.__init__(self)
self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.setFrameShape(QtWidgets.QFrame.Box)
self.setFrameShadow(QtWidgets.QFrame.Raised)
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
self.setLayout(grid) self.setLayout(grid)
@ -89,9 +99,6 @@ class _TTLWidget(QtWidgets.QFrame):
self.set_value(0, False, False) self.set_value(0, False, False)
def sizeHint(self):
return _widget_size
def set_mode(self, mode): def set_mode(self, mode):
data = struct.pack("bbb", data = struct.pack("bbb",
2, # MONINJ_REQ_TTLSET 2, # MONINJ_REQ_TTLSET
@ -124,17 +131,13 @@ class _TTLWidget(QtWidgets.QFrame):
self._expctl_action.setChecked(True) self._expctl_action.setChecked(True)
class _DDSWidget(QtWidgets.QFrame): class _DDSWidget(_MoninjWidget):
def __init__(self, bus_channel, channel, sysclk, title): def __init__(self, bus_channel, channel, sysclk, title):
self.bus_channel = bus_channel self.bus_channel = bus_channel
self.channel = channel self.channel = channel
self.sysclk = sysclk self.sysclk = sysclk
QtWidgets.QFrame.__init__(self) _MoninjWidget.__init__(self)
self.setSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
self.setFrameShape(QtWidgets.QFrame.Box)
self.setFrameShadow(QtWidgets.QFrame.Raised)
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
self.setLayout(grid) self.setLayout(grid)
@ -154,9 +157,6 @@ class _DDSWidget(QtWidgets.QFrame):
self.set_value(0) self.set_value(0)
def sizeHint(self):
return _widget_size
def set_value(self, ftw): def set_value(self, ftw):
frequency = ftw*self.sysclk()/2**32 frequency = ftw*self.sysclk()/2**32
self._value.setText("<font size=\"6\">{:.7f} MHz</font>" self._value.setText("<font size=\"6\">{:.7f} MHz</font>"