class OilStorageDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(OilStorageDisplay, self).__init__(parent) self.oil_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.oil_label.setText('Oil Storage') self.oil_label.setIndent(15) self.oil = Resource(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): objlayout = QtGui.QHBoxLayout() objlayout.setSpacing(0) objlayout.setMargin(0) objlayout.addWidget(self.oil_label) objlayout.addWidget(self.oil) self.setLayout(objlayout) def update_oil(self, oil): self.oil.update_resource(resource=oil) def tick(self): ''' testing solo mode ''' import random random.seed() oil = random.randrange(-2, 2) self.update_oil(oil)
class AirmassDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(AirmassDisplay, self).__init__(parent) self.airmass_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.airmass_label.setText('AirMass') self.airmass_label.setIndent(15) self.airmass = Airmass(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): layout = QtGui.QHBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.addWidget(self.airmass_label) layout.addWidget(self.airmass) self.setLayout(layout) def update_airmass(self, el): self.airmass.update_airmass(el) def tick(self): ''' testing solo mode ''' import random el = random.uniform(-20.0, 200) if el < -10 or el > 190: el = '##STATNONE##' self.update_airmass(el)
class CalProbeDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(CalProbeDisplay, self).__init__(parent) self.calprobe_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.calprobe_label.setText('CalProbe') self.calprobe_label.setIndent(15) self.calprobe = CalProbe(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): layout = QtGui.QHBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.addWidget(self.calprobe_label) layout.addWidget(self.calprobe) self.setLayout(layout) def update_calprobe(self, probe): self.calprobe.update_calprobe(probe) def tick(self): ''' testing solo mode ''' import random random.seed() indx = random.randrange(0, 35) indx2 = random.randrange(0, 5) foci = [ 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000L, 0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000, 0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000, 0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000000, "Unknown", None, '##STATNONE##', '##NODATA##', '##ERROR##' ] foci2 = [0x01, 0x02, 0x04, "Unknown", None, '##STATNONE##', \ '##NODATA##', 0x08, '##ERROR##'] try: focus = foci[indx] focus2 = foci2[indx2] except Exception as e: focus = None focus2 = None print e probe = random.random() * random.randrange(-20, 20) self.update_calprobe(probe)
def __init__(self, parent=None, logger=None): super(PaDisplay, self).__init__(parent) self.pa_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.pa_label.setText('Position Angle') self.pa_label.setIndent(15) self.pa = Pa(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(CalDisplay, self).__init__(parent) self.cal_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.cal_label.setText('Cal') self.cal_label.setIndent(15) self.cal = Cal(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(OilStorageDisplay, self).__init__(parent) self.oil_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.oil_label.setText('Oil Storage') self.oil_label.setIndent(15) self.oil = Resource(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(TimeElLimitDisplay, self).__init__(parent) self.timelimit_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.timelimit_label.setText('Time to EL Limit') self.timelimit_label.setIndent(15) self.ellimit = TimeElLimit(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(ObjectDisplay, self).__init__(parent) self.obj_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.obj_label.setText('Object') self.obj_label.setIndent(15) #self.obj_label.setAlignment(QtCore.Qt.AlignVCenter) self.obj = Object(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(PropIdDisplay, self).__init__(parent) self.propid_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.propid_label.setText('Proposal ID') self.propid_label.setIndent(15) #self.propid_label.setAlignment(QtCore.Qt.AlignVCenter) self.propid = PropId(parent=parent, logger=logger) self.__set_layout()
def __init__(self, parent=None, logger=None): super(DomeffDisplay, self).__init__(parent) self.domeff_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.domeff_label.setText('Domeff') self.domeff_label.setIndent(15) #self.propid_label.setAlignment(QtCore.Qt.AlignVCenter) self.domeff = Domeff(parent=parent, logger=logger) self.__set_layout()
def __init__(self,*args, **kwargs): #super(AGPlot, self).__init__(*args, **kwargs) CalCanvas.__init__(self, *args, **kwargs) # display milliampere(mA) self.ma = Canvas(parent=kwargs['parent'], fs=8, width=175,\ height=25, align='vcenter', \ logger=kwargs['logger']) self.ma.setText('') self.ma.setIndent(15) self.on = 1 self.off =2
class TimeRotLimitDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(TimeRotLimitDisplay, self).__init__(parent) self.timelimit_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.timelimit_label.setText('Time to Rot Limit') self.timelimit_label.setIndent(15) self.rotlimit = TimeRotLimit(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): rotlayout = QtGui.QHBoxLayout() rotlayout.setSpacing(0) rotlayout.setMargin(0) rotlayout.addWidget(self.timelimit_label) rotlayout.addWidget(self.rotlimit) self.setLayout(rotlayout) def update_rotlimit(self, flag, rot, link, focus, focus2): self.rotlimit.update_rotlimit(flag, rot, link, focus, focus2) def tick(self): ''' testing solo mode ''' import random indx = random.randrange(0,3) indx2 = random.randrange(0,5) flag = [0, 8, 10, 'Unknown'] flag = flag[indx] rot = random.uniform(0, 760) if rot > 750.0: rot = '##NODATA##' link = random.randrange(0,4) # popt/pir/popt2/cs/ns/ns focus = [0x01000000, 0x02000000, 0x00000000, 0x08000000, 0x00010000, 0x00040000][indx2] # ns/ns/ns/popt2 focus2 = [0x01, 0x02,0x04, 0x08][indx] self.update_rotlimit(flag, rot, link, focus, focus2)
class DomeffDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(DomeffDisplay, self).__init__(parent) self.domeff_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.domeff_label.setText('Domeff') self.domeff_label.setIndent(15) #self.propid_label.setAlignment(QtCore.Qt.AlignVCenter) self.domeff = Domeff(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): layout = QtGui.QHBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.addWidget(self.domeff_label) layout.addWidget(self.domeff) self.setLayout(layout) def update_domeff(self, ff_a, ff_1b, ff_2b, ff_3b, ff_4b): self.domeff.update_domeff(ff_a, ff_1b, ff_2b, ff_3b, ff_4b) def tick(self): ''' testing solo mode ''' import random indx = random.randrange(0, 5) ff_a = (1, 2, 5, None, 1) ff_1b, ff_2b, ff_3b, ff_4b = [8, 20, 2, 8] #ff_1b, ff_2b, ff_3b, ff_4b = [None, 1 , 90, '#STATNO#'] try: ff_a = ff_a[indx] except Exception: pass else: self.update_domeff(ff_a, ff_1b, ff_2b, ff_3b, ff_4b)
class PropIdDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(PropIdDisplay, self).__init__(parent) self.propid_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.propid_label.setText('Proposal ID') self.propid_label.setIndent(15) #self.propid_label.setAlignment(QtCore.Qt.AlignVCenter) self.propid = PropId(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): objlayout = QtGui.QHBoxLayout() objlayout.setSpacing(0) objlayout.setMargin(0) objlayout.addWidget(self.propid_label) objlayout.addWidget(self.propid) self.setLayout(objlayout) def update_propid(self, propid): self.propid.update_propid(propid) def tick(self): ''' testing solo mode ''' import random random.seed() indx = random.randrange(0, 9) propid = ['o12011', None, 'o11111', 'o12345', "Unknown", \ '##STATNONE##', '##NODATA##', 'o99999', '##ERROR##'] try: propid = propid[indx] except Exception as e: propid = 'o12011' print e self.update_propid(propid)
class ObjectDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(ObjectDisplay, self).__init__(parent) self.obj_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.obj_label.setText('Object') self.obj_label.setIndent(15) #self.obj_label.setAlignment(QtCore.Qt.AlignVCenter) self.obj = Object(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): objlayout = QtGui.QHBoxLayout() objlayout.setSpacing(0) objlayout.setMargin(0) objlayout.addWidget(self.obj_label) objlayout.addWidget(self.obj) self.setLayout(objlayout) def update_object(self, obj): self.obj.update_object(obj) def tick(self): ''' testing solo mode ''' import random random.seed() indx = random.randrange(0, 9) obj = ['FOFOSS', None, 'NAOJ1212', 'M78asfaf', "Unknown", \ '##STATNONE##', '##NODATA##', 'GINZA', '##ERROR##'] try: obj = obj[indx] except Exception as e: obj = 'SUBARU' print e self.update_object(obj)
class TimeElLimitDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(TimeElLimitDisplay, self).__init__(parent) self.timelimit_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.timelimit_label.setText('Time to EL Limit') self.timelimit_label.setIndent(15) self.ellimit = TimeElLimit(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): ellayout = QtGui.QHBoxLayout() ellayout.setSpacing(0) ellayout.setMargin(0) ellayout.addWidget(self.timelimit_label) ellayout.addWidget(self.ellimit) self.setLayout(ellayout) def update_ellimit(self, flag, low, high): self.ellimit.update_ellimit(flag, low, high) def tick(self): ''' testing solo mode ''' import random indx = random.randrange(0,3) flag = [0, 1, 2, 'Unknown'] flag = flag[indx] low = random.uniform(0, 760) high = random.uniform(0, 760) if low > 750.0: low = '##NODATA##' if high > 750.0: high = '##STATNONE##' self.update_ellimit(flag, low, high)
class PaDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(PaDisplay, self).__init__(parent) self.pa_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', \ weight='bold', logger=logger) self.pa_label.setText('Position Angle') self.pa_label.setIndent(15) self.pa = Pa(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): layout = QtGui.QHBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.addWidget(self.pa_label) layout.addWidget(self.pa) self.setLayout(layout) def update_pa(self, pa, cmd_diff): self.pa.update_pa(pa, cmd_diff) def tick(self): ''' testing solo mode ''' import random pa = random.uniform(-100.0, 150) cmd_diff = random.uniform(-0.5, 0.5) if pa > 100: pa = '##STATNONE##' if cmd_diff < -0.3: cmd_diff = 'Unknown' self.update_pa(pa, cmd_diff)
class CalDisplay(QtGui.QWidget): def __init__(self, parent=None, logger=None): super(CalDisplay, self).__init__(parent) self.cal_label = Canvas(parent=parent, fs=10, width=175,\ height=25, align='vcenter', weight='bold', \ logger=logger) self.cal_label.setText('Cal') self.cal_label.setIndent(15) self.cal = Cal(parent=parent, logger=logger) self.__set_layout() def __set_layout(self): hlayout = QtGui.QHBoxLayout() hlayout.setSpacing(0) hlayout.setMargin(0) vlayout = QtGui.QVBoxLayout() vlayout.setSpacing(0) vlayout.setMargin(0) vlayout.addWidget(self.cal_label) vlayout.addWidget(self.cal.ma) hlayout.addLayout(vlayout) hlayout.addWidget(self.cal) self.setLayout(hlayout) def update_cal(self, hct1, hct2, hal1, hal2, rgl1, rgl2, \ hct1_amp, hct2_amp, hal1_amp, hal2_amp): self.cal.update_cal(hct1, hct2, hal1, hal2, rgl1, rgl2, \ hct1_amp, hct2_amp, hal1_amp, hal2_amp) def tick(self): ''' testing solo mode ''' import random # off hct1= 'aa'; hct2= 'a' hal1 = hal2 = '2a' rgl1 = rgl2 = '22' #hal1 = '1a' #hal2 = '2a' # on hct1= 'a9'; hct2 = '9' # test hct1= '6a'; hct2 = 'a' #hct1= 'aa'; hct2 = 'a' hct1_amp = hct2_amp = 14.86 hal1_amp = hal2_amp = 54.321 self.update_cal(hct1, hct2, hal1, hal2, rgl1, rgl2, \ hct1_amp, hct2_amp, hal1_amp, hal2_amp)
class Cal(CalCanvas): """ Cal Source """ def __init__(self,*args, **kwargs): #super(AGPlot, self).__init__(*args, **kwargs) CalCanvas.__init__(self, *args, **kwargs) # display milliampere(mA) self.ma = Canvas(parent=kwargs['parent'], fs=8, width=175,\ height=25, align='vcenter', \ logger=kwargs['logger']) self.ma.setText('') self.ma.setIndent(15) self.on = 1 self.off =2 def __num_of_undef_vals(self, val_set): ''' find out the number of undefined values''' for val in [self.on, self.off]: try: val_set.remove(val) except KeyError: pass return len(val_set) def __mask_value(self, val, focus): mask = {'CS': 0x03, 'NSIR': 0x30, 'NSOPT': 0x0c, \ 'PF1': 0x30, 'PF2': 0xc0} try: #val = int('%s' %val, 16) val = val & mask[focus] except Exception: val = None finally: return val def __shift_value(self, val, focus): ''' right shift ''' shift = {'CS': 0, 'NSIR': 4, 'NSOPT': 2, \ 'PF1': 4, 'PF2': 6} masked = self.__mask_value(val, focus) try: val = masked >> shift[focus] except Exception: val = None finally: return val def __update(self, lamps, num_on): for lamp, val in lamps.items(): vals = set(val.lamp) num_undef = self.__num_of_undef_vals(val_set=vals) self.logger.debug('lamps %s'%vals) self.logger.debug('num undef %s' %str(num_undef)) if num_undef: lamp.set_fc(self.alarm) lamp.set_alpha(1) else: self.logger.debug('val lamp %s' %str(val.lamp)) self.logger.debug('val amp %s' %str(val.amp)) ma = '' if self.on in val.lamp: lamp.set_fc(self.normal) lamp.set_alpha(0.5) self.logger.debug('on') self.logger.debug('val amp=%s' %val.amp) if num_on > self.on: # at least 2 lamps are on lamp.set_fc(self.warn) lamp.set_alpha(1) else: # 1 lamp is on if not val.amp in ERROR: ma = '%+5.3fmA' %val.amp self.ma.setText(ma) self.logger.debug('amp=%s' %str(ma)) else: self.logger.debug('off') #if not ma: # self.ma.setText(ma) lamp.set_fc(self.bg) lamp.set_alpha(1) def update_cal(self, hct1, hct2, hal1, hal2, rgl1, rgl2, \ hct1_amp, hct2_amp, hal1_amp, hal2_amp, \ rgl1_amp=None, rgl2_amp=None): ''' hct1 = TSCV.CAL_HCT_LAMP1 hct2 = TSCV.CAL_HCT_LAMP2 hal1 = TSCV.CAL_HAL_LAMP1 hal2 = TSCV.CAL_HAL_LAMP2 rgl1 = TSCV.CAL_RGL_LAMP1 rgl2 = TSCV.CAL_RGL_LAMP2 hal1_amp = TSCL.CAL_HAL1_AMP hal2_amp = TSCL.CAL_HAL2_AMP hct1_amp = TSCL.CAL_HCT1_AMP hct2_amp = TSCL.CAL_HCT2_AMP ''' # hct1 = (hct1_cs, hct1_nsopt, hct1_pf1, hct1_pf2) # hct2 = (hct2_cs, hct2_nsopt) # hal1 = (hal1_cs, hal1_nsopt, hal1_nsir) # hal2 = (hal2_cs, hal2_nsopt, hal2_nsir) # rgl1 = (rgl1_cs, rgl1_nsir) # rgl2 = (rgl2_cs, rgl2_nsir) self.logger.debug('updating hct1=%s hct2=%s hal1=%s hal2=%s rgl1=%s rgl2=%s' %(hct1, hct2, hal1, hal2, rgl1, rgl2)) hct1_cs = self.__shift_value(hct1, focus='CS') hct1_nsopt = self.__shift_value(hct1, focus='NSOPT') hct1_pf1 = self.__shift_value(hct1, focus='PF1') hct1_pf2 = self.__shift_value(hct1, focus='PF2') hct2_cs = self.__shift_value(hct2, focus='CS') hct2_nsopt = self.__shift_value(hct2, focus='NSOPT') hal1_cs = self.__shift_value(hal1, focus='CS') hal1_nsopt = self.__shift_value(hal1, focus='NSOPT') hal1_nsir = self.__shift_value(hal1, focus='NSIR') hal2_cs = self.__shift_value(hal2, focus='CS') hal2_nsopt = self.__shift_value(hal2, focus='NSOPT') hal2_nsir = self.__shift_value(hal2, focus='NSIR') rgl1_cs = self.__shift_value(rgl1, focus='CS') rgl1_nsir = self.__shift_value(rgl1, focus='NSIR') rgl2_cs = self.__shift_value(rgl2, focus='CS') rgl2_nsir = self.__shift_value(rgl2, focus='NSIR') bhct1 = Bunch(lamp=(hct1_cs, hct1_nsopt, hct1_pf1, hct1_pf2), amp=hct1_amp) bhct2 = Bunch(lamp=(hct2_cs, hct2_nsopt), amp=hct2_amp) bhal1 = Bunch(lamp= (hal1_cs, hal1_nsopt, hal1_nsir), amp=hal1_amp) bhal2 = Bunch(lamp=(hal2_cs, hal2_nsopt, hal2_nsir), amp=hal2_amp) brgl1 = Bunch(lamp=(rgl1_cs, rgl1_nsir), amp=rgl1_amp) brgl2 = Bunch(lamp=(rgl2_cs, rgl2_nsir), amp=rgl2_amp) blamps = {self.th_ar1: bhct1, self.th_ar2: bhct2, \ self.hal1: bhal1, self.hal2: bhal2, \ self.ne: brgl1, self.ar: brgl2} self.logger.debug('shifted hct1cs=%s htc1nsopt=%s hct1pf1=%s hct1pf2=%s' %(str(hct1_cs), str(hct1_nsopt), str(hct1_pf1), str(hct1_pf2))) lamps = [hct1_cs, hct1_nsopt, hct1_pf1, hct1_pf2, hct2_cs, hct2_nsopt, \ hal1_cs, hal1_nsopt, hal1_nsir, hal2_cs, hal2_nsopt, hal2_nsir, \ rgl1_cs, rgl1_nsir, rgl2_cs, rgl2_nsir] num_on = lamps.count(self.on) self.__update(blamps, num_on) self.draw()