def paint(self, painter, dummyOption, dummyWidget=None): """paint the marker""" with Painter(painter): pen = QPen(QColor(self.color)) painter.setPen(pen) painter.setFont(self.__font) painter.drawText(0, 0, self.__text)
class ScoreItemDelegate(QStyledItemDelegate): """since setting delegates for a row does not work as wanted with a tree view, we set the same delegate on ALL items.""" # try to use colors that look good with all color schemes. Bright # contrast colors are not optimal as long as our lines have a width of # only one pixel: antialiasing is not sufficient colors = [ KApplication.palette().color(x) for x in [QPalette.Text, QPalette.Link, QPalette.LinkVisited] ] colors.append(QColor('orange')) def __init__(self, parent=None): QStyledItemDelegate.__init__(self, parent) def paint(self, painter, option, index): """where the real work is done...""" item = index.internalPointer() if isinstance(item, ScorePlayerItem) and item.parent.row( ) == 3 and index.column() != 0: for idx, playerItem in enumerate( index.parent().internalPointer().children): chart = index.model().chart(option.rect, index, playerItem) if chart: with Painter(painter): painter.translate(option.rect.topLeft()) painter.setPen(self.colors[idx]) painter.setRenderHint(QPainter.Antialiasing) # if we want to use a pen width > 1, we can no longer directly drawPolyline # separately per cell beause the lines spread vertically over two rows: We would # have to draw the lines into one big pixmap and copy # from the into the cells painter.drawPolyline(*chart) return return QStyledItemDelegate.paint(self, painter, option, index)
def unmark(self): """ to turn off the highlight of this partial relation and the connected collection and relation icon """ self.setZ(0) self.lineWidth = 1 if self.relationType == 0: self.setBrush(QBrush(QColor(200, 200, 255), Qt.SolidPattern)) else: self.setBrush(QBrush(QColor(200, 255, 200), Qt.SolidPattern)) self.relationIcon.unmark(False) self.collectionIcon.unmark(False) self.setCoords()
def _drawDarkness(self, painter): """if appropriate, make tiles darker. Mainly used for hidden tiles""" if self.dark: board = self.board rect = board.tileFaceRect().adjusted(-1, -1, -1, -1) color = QColor('black') color.setAlpha(self.tileset.darkenerAlpha) painter.fillRect(rect, color)
def __init__(self): QGraphicsRectItem.__init__(self) pen = QPen(QColor(Qt.blue)) pen.setWidth(6) self.setPen(pen) self.setZValue(ZValues.markerZ) self._board = None self.hide()
def __draw_figure(self, figure, algorithm, palette): has_alpha = algorithm.alpha color = QColor(palette['base']) if not has_alpha: self._context.set_draw_color(color) for pixel in algorithm(figure): if has_alpha: color.setAlphaF(pixel[2]) self._context.set_draw_color(color) self._context.draw_pixel(pixel[0], pixel[1])
def highlightParagraph(self, text, endStateOfLastPara): text = str(text) template = Template() template.set_template(text) for span in template.spans(): font = self.textEdit().currentFont() font.setBold(True) color = QColor('blue') length = span[1] - span[0] self.setFormat(span[0], length, font, color) return 0
def mark(self): """ to highlight the partial relation and connection relation and collection (if they're not marked yet) """ if self.relationType == 0: self.setBrush(QBrush(QColor(0, 0, 255), Qt.SolidPattern)) else: self.setBrush(QBrush(QColor(0, 180, 0), Qt.SolidPattern)) self.setZ(200) self.lineWidth = 2 if self.relationIcon.isMarked != 1: self.relationIcon.mark(False) if self.collectionIcon.isMarked != 1: self.collectionIcon.mark(False) self.setCoords()
def data(self, index, role=Qt.DisplayRole): """score table""" # pylint: disable=too-many-branches,too-many-locals,redefined-variable-type result = None if role == Qt.TextAlignmentRole: if index.column() == 0: result = int(Qt.AlignHCenter | Qt.AlignVCenter) else: result = int(Qt.AlignLeft | Qt.AlignVCenter) if index.isValid() and (0 <= index.row() < len(self.tables)): table = self.tables[index.row()] if role == Qt.DisplayRole and index.column() in (0, 1): result = table.tableid elif role == Qt.DisplayRole and index.column() == 2: players = [] zipped = list(zip(table.playerNames, table.playersOnline)) for idx, pair in enumerate(zipped): name, online = pair[0], pair[1] if idx < len(zipped) - 1: name += ', ' palette = KApplication.palette() if online: color = palette.color(QPalette.Active, QPalette.WindowText).name() style = ('font-weight:normal;' 'font-style:normal;color:%s' % color) else: color = palette.color(QPalette.Disabled, QPalette.WindowText).name() style = ('font-weight:100;font-style:italic;color:%s' % color) players.append('<nobr style="%s">' % style + name + '</nobr>') names = ''.join(players) result = names elif role == Qt.DisplayRole and index.column() == 3: status = table.status() if table.suspendedAt: dateVal = ' ' + datetime.datetime.strptime( table.suspendedAt, '%Y-%m-%dT%H:%M:%S').strftime('%c') status = 'Suspended' else: dateVal = '' result = i18nc('table status', status) + dateVal elif index.column() == 4: if role == Qt.DisplayRole: result = i18n((table.myRuleset if table.myRuleset else table.ruleset).name) elif role == Qt.ForegroundRole: palette = KApplication.palette() color = palette.windowText() if table.myRuleset else 'red' result = QColor(color) return result
def drawShape(self, p): """ Draws the icon. """ p.setPen(QPen(QColor(100, 100, 100), 0)) markPixmap = QPixmap(self.scaledMaskUnmarked) if self.isMarked == 1: markPixmap = QPixmap(self.scaledMaskMarked) p.setPen(QPen(QColor(0, 0, 0), 0)) if self.isMarked == 2: markPixmap = QPixmap(self.scaledMaskHighlight) p.setPen(QPen(QColor(0, 0, 0), 0)) p.drawPixmap(self.x(), self.y(), markPixmap) p.drawPixmap( self.x() + (self.iconPainterWidth - self.iconPixmap.width()) / 2, self.y() + 4, self.iconPixmap) p.drawText( self.x() + (self.iconPainterWidth - self.iconLabelWidth) / 2, self.y() + self.iconPixmap.height() + self.iconLabelHeight + 4, self.iconLabel)
def data(self, index, role=None): # pylint: disable=no-self-use,too-many-branches """score table""" # pylint: disable=too-many-return-statements if not index.isValid(): return column = index.column() item = index.internalPointer() if role is None: role = Qt.DisplayRole if role == Qt.DisplayRole: if isinstance(item, ScorePlayerItem): content = item.content(column) if isinstance(content, HandResult): parentRow = item.parent.row() if parentRow == 0: if not content.penalty: content = '%d %s' % (content.points, content.wind) elif parentRow == 1: content = str(content.payments) else: content = str(content.balance) return content else: if column > 0: return '' else: return item.content(0) if role == Qt.TextAlignmentRole: if index.column() == 0: return int(Qt.AlignLeft | Qt.AlignVCenter) else: return int(Qt.AlignRight | Qt.AlignVCenter) if role == Qt.FontRole: return QFont('Monospaced') if role == Qt.ForegroundRole: if isinstance(item, ScorePlayerItem) and item.parent.row() == 3: content = item.content(column) if not isinstance(content, HandResult): return QBrush(ScoreItemDelegate.colors[index.row()]) if column > 0 and isinstance(item, ScorePlayerItem): content = item.content(column) # pylint: disable=maybe-no-member # pylint thinks content is a str if role == Qt.BackgroundRole: if content and content.won: return QColor(165, 255, 165) if role == Qt.ToolTipRole: englishHints = content.manualrules.split('||') tooltip = '<br />'.join(i18n(x) for x in englishHints) return tooltip
def __draw_figure_debug(self, figure, algorithm, palette): has_alpha = algorithm.alpha color = QColor(palette['base']) if not has_alpha: self._context.set_draw_color(color) for number, pixel in enumerate(algorithm(figure)): if self.__emited_debug_messages < self.__debug_steps and number == self.__emited_debug_messages: self.debug_next_message.emit('draw%s' % str(pixel)) self.__emited_debug_messages += 1 if number >= self.__debug_steps: return if has_alpha: color.setAlphaF(pixel[2]) self._context.set_draw_color(color) self._context.draw_pixel(pixel[0], pixel[1])
def gray_me_out(self): self.reset_btn.setEnabled(False) palt_gray = QPalette() palt_gray.setColor(QPalette.WindowText, QColor(88, 88, 88, 88)) for bg_widg in ( self.advanced_widget.scrollable_widget.lst_var_widg, self.advanced_widget.scrollable_widget.lst_label_widg, self.simpler_widget.lst_var_widg, ): for widg in bg_widg: widg.setStyleSheet("color: rgba(88, 88, 88, 88)") try: widg.setEnabled(False) except BaseException as e: # We don't want to catch bare exceptions but don't know # what this was supposed to catch. Log it. print("Caught unknown exception #9 type %s: %s", type(e).__name__, e) pass
def data(self, index, role=Qt.DisplayRole): """score table""" result = None if role == Qt.TextAlignmentRole: if index.column() == 1: return int(Qt.AlignRight) else: return int(Qt.AlignLeft) if index.isValid() and (0 <= index.row() < len(self.chatLines)): chatLine = self.chatLines[index.row()] if role == Qt.DisplayRole and index.column() == 0: local = chatLine.localtimestamp() result = '%02d:%02d:%02d' % (local.hour, local.minute, local.second) elif role == Qt.DisplayRole and index.column() == 1: result = chatLine.fromUser elif role == Qt.DisplayRole and index.column() == 2: result = i18n(chatLine.message) elif role == Qt.ForegroundRole and index.column() == 2: palette = Internal.app.palette() # pylint: disable=no-member color = 'blue' if chatLine.isStatusMessage else palette.windowText( ) result = QColor(color) return result
def add_opts_lst(self, lst_labels=None, json_path=None, selected_pos=None): if lst_labels is None: logger.debug("json_path = %s", json_path) self.list_labl = ops_list_from_json(json_path) n_row = len(self.list_labl) logger.debug("n_row = %s", n_row) n_col = len(self.list_labl[0]) logger.debug("n_col = %s", n_col) self.setRowCount(n_row) self.setColumnCount(n_col - 1) alpha_str = " " + u"\u03B1" + " " beta_str = " " + u"\u03B2" + " " gamma_str = " " + u"\u03B3" + " " low_delta_str = u"\u03B4" delta_max_str = "max " + low_delta_str header_label_lst = [ delta_max_str, "rmsd", " min cc", "max cc", "latt", " a ", " b ", " c ", alpha_str, beta_str, gamma_str, "Ok", ] self.setHorizontalHeaderLabels(header_label_lst) self.rec_col = None for row, row_cont in enumerate(self.list_labl): for col, col_cont in enumerate(row_cont[1:]): item = QTableWidgetItem(col_cont) item.setFlags(Qt.ItemIsEnabled) if col_cont == " Y": item.setBackground(Qt.green) item.setForeground(Qt.black) self.rec_col = col + 1 elif col_cont == " N": item.setBackground(Qt.red) item.setForeground(Qt.black) else: if row == selected_pos: item.setBackground(Qt.blue) item.setForeground(Qt.yellow) else: if float(row) / 2.0 == int(float(row) / 2.0): item.setBackground(QColor(50, 50, 50, 50)) else: item.setBackground(Qt.white) item.setForeground(Qt.black) item.setFont(QFont("Monospace", self.sys_font_point_size)) # , QFont.Bold)) self.setItem(row, col, item) self.resizeColumnsToContents()
def dragEnterEvent(self, dummyEvent): """drag enters the HandBoard: highlight it""" self.setPen(QPen(QColor(self.penColor)))
def updateDiagram(form, fies, tcs): """ Updates the FIES Diagram according to the status values passed to the function """ from qt import Qt from qt import QColor import string # Update tabular values form.timerLabel.setText(str(tcs['ut'])) cur_counts = form.ExposureMeterCur.x[-1] form.ExpMeterCur.setText("%.2g" % cur_counts) form.ExpMeterAcc.setText("%.2g" % fies['counts']) form.fiesFocus_2.setText(str(fies['fiesfocus'])) form.ccdShutter_2.setText(str(fies['ccdshutter'])) form.calMirror_2.setText(str(fies['calmirror'])) form.calShutter_2.setText(str(fies['calshutter'])) form.calLamps_2.setText(str(fies['callamps'])) form.fiberMask_2.setText(str(fies['fibermask'])) form.fiberArm_2.setText(str(fies['fiberarm'])) form.fiberLamps_2.setText(str(fies['fiberlamps'])) form.guideProbe_2.setText(str(tcs['vignetting'])) form.ccdFilter_2.setText(str(tcs['ccdfilter'] + ':' + tcs['ccdfiltername'])) ###################################################################### # # Show current lightpath(s). # # Basically, you follow the lightpath from lightsource to CCD, evaluating # whether light is passed or not at every node (component). The most # complicated lightpath to draw is centered on the Arm/Mask mechanisms. # To understand the logic in the code below, think of the following # qualitative description of whats going on: # If the pickoff mirror is directing light to the FIES, without arm and # mask mechanisms the telescope beam will flood all fibers in the fiber # head. Both arm and mask will block for some of that light. # The arm will always block one of the fibers; Calibration light # will go through the arm and into the fiber. Not only does the arm # block one of the fibers from the telescope beam - the arm is fine # adjusted to only let either Halogen or ThAR light through from the # calibration unit. If the halogen lamp is turned on, but the arm is # set on ThAr, no light will go through. # The mask sits underneith the arm and blocks light from entering 2,3 # or all 4 fibers in the fiber head. # ###################################################################### # Define some default colors # Calibration fiber colors are determined further down HALOGEN = QColor(255, 220, 20) THAR = Qt.magenta LAMP_ERROR = QColor(255, 0, 0) TELBEAM_ON = QColor(0, 255, 0) BEAM_OFF = Qt.white FIB_OFF = Qt.black MASK_ON = Qt.black MASK_OFF = Qt.white ### PICKOFF MIRROR ### # Turn telescope beam on (always on) form.b_telescope.setPaletteForegroundColor(TELBEAM_ON) if (tcs['pickoffmirror'] == "Park"): # light goes nowhere form.frm_ccdFilter_2.b_tel = False form.frm_fiberArm_2.b_tel = False elif (tcs['pickoffmirror'] == "FIES"): # light is directed to FIES form.frm_ccdFilter_2.b_tel = False form.frm_fiberArm_2.b_tel = True else: # (tcs['pickoffmirror'] == "StanCam") # light is directed to stancam form.frm_ccdFilter_2.b_tel = True form.frm_fiberArm_2.b_tel = False form.pickoffMirror_2.setText(str(tcs['pickoffmirror'])) ### STANCAM FILTER ### if (form.frm_ccdFilter_2.b_tel): form.b_stancam.setPaletteForegroundColor(TELBEAM_ON) form.frm_stancam.b_tel = True else: form.b_stancam.setPaletteForegroundColor(BEAM_OFF) form.frm_stancam.b_tel = False ### STANCAM CCD ### if (form.frm_stancam.b_tel): form.b_stancam_2.setPaletteForegroundColor(TELBEAM_ON) else: form.b_stancam_2.setPaletteForegroundColor(BEAM_OFF) ### FIBER CALIBRATION LAMPS (Telescope Adaptor) ### if (fies['fiberlamps'] != "Lamps Off"): # Define calibration beam color, depending on lamp(s) on if (fies['fiberlamps'] == "Halogen"): CALFIB_ON = HALOGEN elif (fies['fiberlamps'] == "ThAr"): CALFIB_ON = THAR else: # More than one lamp is on, NOT GOOD - SHOW Error CALFIB_ON = LAMP_ERROR form.frm_fiberLamps_2.setPaletteBackgroundColor(CALFIB_ON) form.frm_fiberArm_2.b_cal = True else: # No light reaches the fiberArm unit from the calibration unit form.frm_fiberLamps_2.setPaletteBackgroundColor(BEAM_OFF) form.frm_fiberArm_2.b_cal = False CALFIB_ON = BEAM_OFF ### FIBER ARM ### # beam from telescope if (form.frm_fiberArm_2.b_tel): # Set mask_beam and pickup_beam to Telescope (pickup_beam1, mask_beam1) = (TELBEAM_ON, TELBEAM_ON) (pickup_beam2, mask_beam2) = (TELBEAM_ON, TELBEAM_ON) (pickup_beam3, mask_beam3) = (TELBEAM_ON, TELBEAM_ON) (pickup_beam4, mask_beam4) = (TELBEAM_ON, TELBEAM_ON) else: # Set mask_beam and pickup_beam to Off (pickup_beam1, mask_beam1) = (BEAM_OFF, BEAM_OFF) (pickup_beam2, mask_beam2) = (BEAM_OFF, BEAM_OFF) (pickup_beam3, mask_beam3) = (BEAM_OFF, BEAM_OFF) (pickup_beam4, mask_beam4) = (BEAM_OFF, BEAM_OFF) # armpos 1: Fiber 1, Halogen if (fies['armpos'] == 1): # Components of the fiberarm that will be drawn (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 1, 1, 1, 1, 1, 0, 0, 0) # Draw Halogen Arm armcol = (BEAM_OFF, HALOGEN) # Calibration lamp is set to ThAR, so no light will # go through the arm: Turn off this beam if (CALFIB_ON == THAR): mask_beam1 = BEAM_OFF # Calibration lamp is either Halogen or halogen+thar, in which # case light will pass through the arm. Set the beam # color to be the one of the calibration unit else: mask_beam1 = CALFIB_ON # armpos 2: Fiber 1, ThAr if (fies['armpos'] == 2): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 1, 1, 1, 1, 1, 0, 0, 0) armcol = (BEAM_OFF, THAR) if (CALFIB_ON == HALOGEN): mask_beam1 = BEAM_OFF else: mask_beam1 = CALFIB_ON # armpos 3: Fiber 2, Halogen if (fies['armpos'] == 3): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 1, 1, 1, 0, 1, 0, 0) armcol = (BEAM_OFF, HALOGEN) if (CALFIB_ON == THAR): mask_beam2 = BEAM_OFF else: mask_beam2 = CALFIB_ON # armpos 4: Fiber 2, ThAr if (fies['armpos'] == 4): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 1, 1, 1, 0, 1, 0, 0) armcol = (BEAM_OFF, THAR) if (CALFIB_ON == HALOGEN): mask_beam2 = BEAM_OFF else: mask_beam2 = CALFIB_ON # armpos 5: Fiber 3, Halogen if (fies['armpos'] == 5): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 0, 1, 1, 0, 0, 1, 0) armcol = (BEAM_OFF, HALOGEN) if (CALFIB_ON == THAR): mask_beam3 = BEAM_OFF else: mask_beam3 = CALFIB_ON # armpos 6: Fiber 3, ThAr if (fies['armpos'] == 6): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 0, 1, 1, 0, 0, 1, 0) armcol = (BEAM_OFF, THAR) if (CALFIB_ON == HALOGEN): mask_beam3 = BEAM_OFF else: mask_beam3 = CALFIB_ON # armpos 7: Fiber 4, Halogen if (fies['armpos'] == 7): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 0, 0, 1, 0, 0, 0, 1) armcol = (BEAM_OFF, HALOGEN) if (CALFIB_ON == THAR): mask_beam4 = BEAM_OFF else: mask_beam4 = CALFIB_ON # armpos 8: Fiber 4, ThAr if (fies['armpos'] == 8): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (1, 0, 0, 0, 1, 0, 0, 0, 1) armcol = (BEAM_OFF, THAR) if (CALFIB_ON == HALOGEN): mask_beam4 = BEAM_OFF else: mask_beam4 = CALFIB_ON # armpos 0: Moving if (fies['armpos'] == 0): (ae, as1, as2, as3, as4, a1, a2, a3, a4) = (0, 0, 0, 0, 0, 0, 0, 0, 0) armcol = (BEAM_OFF, THAR) # Set all beams to off while arm is moving (mask_beam1,mask_beam2,mask_beam3,mask_beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF,BEAM_OFF) # The calibration unit is turned on if (form.frm_fiberArm_2.b_cal): form.b_cal_fibarm.setPaletteForegroundColor(CALFIB_ON) # Beam is off, the arm will be drawn in 'off' state else: form.b_cal_fibarm.setPaletteForegroundColor(BEAM_OFF) armcol = (BEAM_OFF, FIB_OFF) # Show the arm mechanism form.arm_entry.setPaletteForegroundColor(armcol[ae]) form.armsec1.setPaletteForegroundColor(armcol[as1]) form.armsec2.setPaletteForegroundColor(armcol[as2]) form.armsec3.setPaletteForegroundColor(armcol[as3]) form.armsec4.setPaletteForegroundColor(armcol[as4]) form.arm1.setPaletteForegroundColor(armcol[a1]) form.arm2.setPaletteForegroundColor(armcol[a2]) form.arm3.setPaletteForegroundColor(armcol[a3]) form.arm4.setPaletteForegroundColor(armcol[a4]) ### FIBER MASK ### # The mask lets light pass through 0, 1 or 2 fibers depending # on mask position. # maskpos 1: Fiber 2 if (fies['maskpos'] == 1): (pickup_beam1,pickup_beam3,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,mask_beam2,BEAM_OFF,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,beam2,FIB_OFF,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_ON,MASK_OFF,MASK_OFF) # maskpos 2: Fiber 3 if (fies['maskpos'] == 2): (pickup_beam1,pickup_beam2,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,BEAM_OFF,mask_beam3,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,FIB_OFF,beam3,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_OFF,MASK_ON,MASK_OFF) # maskpos 3: Fiber 4 if (fies['maskpos'] == 3): (pickup_beam1,pickup_beam2,pickup_beam3) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF,mask_beam4) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,FIB_OFF,FIB_OFF,beam4) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_OFF,MASK_OFF,MASK_ON) # maskpos 4: Fibers Closed if (fies['maskpos'] == 4): (pickup_beam1,pickup_beam2,pickup_beam3,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,FIB_OFF,FIB_OFF,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_OFF,MASK_OFF,MASK_OFF) # maskpos 5: Fiber 1 if (fies['maskpos'] == 5): (pickup_beam2,pickup_beam3,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (mask_beam1,BEAM_OFF,BEAM_OFF,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (beam1,FIB_OFF,FIB_OFF,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_ON,MASK_OFF,MASK_OFF,MASK_OFF) # maskpos 6: Fibers 1+2 if (fies['maskpos'] == 6): (pickup_beam3,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (mask_beam1,mask_beam2,BEAM_OFF,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (beam1,beam2,FIB_OFF,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_ON,MASK_ON,MASK_OFF,MASK_OFF) # maskpos 7: Fibers 2+3 if (fies['maskpos'] == 7): (pickup_beam1,pickup_beam4) = \ (BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,mask_beam2,mask_beam3,BEAM_OFF) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,beam2,beam3,FIB_OFF) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_ON,MASK_ON,MASK_OFF) # maskpos 8: Fibers 3+4 if (fies['maskpos'] == 8): (pickup_beam1,pickup_beam2) = \ (BEAM_OFF,BEAM_OFF) (beam1,beam2,beam3,beam4) = \ (BEAM_OFF,BEAM_OFF,mask_beam3,mask_beam4) (fib_beam1,fib_beam2,fib_beam3,fib_beam4) = \ (FIB_OFF,FIB_OFF,beam3,beam4) (maskpos1,maskpos2,maskpos3,maskpos4) = \ (MASK_OFF,MASK_OFF,MASK_ON,MASK_ON) # Show lightpaths arriving to the arm from pickup mirror form.beam1_0.setPaletteForegroundColor(pickup_beam1) form.beam2_0.setPaletteForegroundColor(pickup_beam2) form.beam3_0.setPaletteForegroundColor(pickup_beam3) form.beam4_0.setPaletteForegroundColor(pickup_beam4) # Show lightpaths arriving to the mask from arm form.beam1_1.setPaletteForegroundColor(beam1) form.beam2_1.setPaletteForegroundColor(beam2) form.beam3_1.setPaletteForegroundColor(beam3) form.beam4_1.setPaletteForegroundColor(beam4) # Show mask positions form.mask1.setPaletteForegroundColor(maskpos1) form.mask2.setPaletteForegroundColor(maskpos2) form.mask3.setPaletteForegroundColor(maskpos3) form.mask4.setPaletteForegroundColor(maskpos4) # Show lightpaths arriving to the fiberhead from mask form.beam1_2.setPaletteForegroundColor(beam1) form.beam2_2.setPaletteForegroundColor(beam2) form.beam3_2.setPaletteForegroundColor(beam3) form.beam4_2.setPaletteForegroundColor(beam4) ### FIBER HEAD ### # Convert BEAMS_OFF beams to FIB_OFF beams, basically # to show inactive fibers as black instead of white. # (This is a bad hack!) if (fib_beam1 == BEAM_OFF): fib_beam1 = FIB_OFF if (fib_beam2 == BEAM_OFF): fib_beam2 = FIB_OFF if (fib_beam3 == BEAM_OFF): fib_beam3 = FIB_OFF if (fib_beam4 == BEAM_OFF): fib_beam4 = FIB_OFF form.fib1_1.setPaletteForegroundColor(fib_beam1) form.fib1_2.setPaletteForegroundColor(fib_beam1) form.fib1_3.setPaletteForegroundColor(fib_beam1) form.fib1_4.setPaletteForegroundColor(fib_beam1) if (fies['ccdshutter'] == "Open"): form.fib1_5.setPaletteForegroundColor(beam1) else: form.fib1_5.setPaletteForegroundColor(BEAM_OFF) # FIBER 2 IS NO LONGER AVAILABLE - DO NOT DRAW #form.fib2_1.setPaletteForegroundColor(fib_beam2) #form.fib2_2.setPaletteForegroundColor(fib_beam2) #form.fib2_3.setPaletteForegroundColor(fib_beam2) #form.fib2_4.setPaletteForegroundColor(fib_beam2) #if (fies['ccdshutter'] == "Open"): # form.fib2_5.setPaletteForegroundColor(beam2) #else: # form.fib2_5.setPaletteForegroundColor(BEAM_OFF) form.fib3_1.setPaletteForegroundColor(fib_beam3) form.fib3_2.setPaletteForegroundColor(fib_beam3) form.fib3_3.setPaletteForegroundColor(fib_beam3) form.fib3_4.setPaletteForegroundColor(fib_beam3) if (fies['ccdshutter'] == "Open"): form.fib3_5.setPaletteForegroundColor(beam3) else: form.fib3_5.setPaletteForegroundColor(BEAM_OFF) form.fib4_1.setPaletteForegroundColor(fib_beam4) form.fib4_2.setPaletteForegroundColor(fib_beam4) form.fib4_3.setPaletteForegroundColor(fib_beam4) form.fib4_4.setPaletteForegroundColor(fib_beam4) if (fies['ccdshutter'] == "Open"): form.fib4_5.setPaletteForegroundColor(beam4) else: form.fib4_5.setPaletteForegroundColor(BEAM_OFF) ### FIES CALIBRATION LAMPS ### if (fies['callamps'] != "Lamps Off"): # Lamp(s) are on, show bg color and set 'incoming fiberlight=on' # on next node: Lamp Selector (calMirror) # Define calibration fiber color, depending on lamp(s) on if (fies['callamps'] == "Halogen"): CALFIB_ON = HALOGEN elif (fies['callamps'] == "ThAr"): CALFIB_ON = THAR else: # More than one lamp is on, NOT GOOD - SHOW RED CALFIB_ON = LAMP_ERROR form.frm_calLamps_2.setPaletteBackgroundColor(CALFIB_ON) form.frm_calMirror_2.b_cal = True else: # incoming fiberlight=off on Lamp Selector node form.frm_calLamps_2.setPaletteBackgroundColor(Qt.white) form.frm_calMirror_2.b_cal = False ### LAMP SELECTOR ### if (form.frm_calMirror_2.b_cal): # Light is recieved from cal lamps, turn on fiber (beam) form.fib5_1.setPaletteForegroundColor(CALFIB_ON) if (fies['callamps'].find(fies['calmirror']) != -1): #Lamp selector set to a lamp currently on, so light # will pass on to the calibration shutter form.frm_calShutter_2.b_cal = True else: # lamp selector shutting of light from cal unit! # light reaches no further form.frm_calShutter_2.b_cal = False else: # No light is reached from callamps, turn off fiber (beam) and # set incoming beamlight=off on shutter form.fib5_1.setPaletteForegroundColor(BEAM_OFF) form.frm_calShutter_2.b_cal = False ### CALIBRATION SHUTTER ### if (form.frm_calShutter_2.b_cal): # Light is recieved from lamp selector, turn on fiber(beam) form.fib5_2.setPaletteForegroundColor(CALFIB_ON) if (fies['calshutter'] == "Open"): # Shutter is open, light will pass to the CCD shutter form.frm_ccdShutter_2.b_cal = True else: # Shutter is closed, light reaches no further form.frm_ccdShutter_2.b_cal = False else: # No light is reached from lamp selector form.fib5_2.setPaletteForegroundColor(BEAM_OFF) form.frm_ccdShutter_2.b_cal = False ### FIES SHUTTER & CCD ### if (form.frm_ccdShutter_2.b_cal): # Light is recieved through cal shutter, turn on fiber form.fib5_3.setPaletteForegroundColor(CALFIB_ON) form.fib5_4.setPaletteForegroundColor(CALFIB_ON) form.fib5_5.setPaletteForegroundColor(CALFIB_ON) if (fies['ccdshutter'] == "Open"): # CCD shutter is open, light will pass to the CCD form.fib5_6.setPaletteForegroundColor(CALFIB_ON) else: # CCD shutter closed, light reaches no further form.fib5_6.setPaletteForegroundColor(BEAM_OFF) else: # No light comes through the calibration shutter form.fib5_3.setPaletteForegroundColor(FIB_OFF) form.fib5_4.setPaletteForegroundColor(FIB_OFF) form.fib5_5.setPaletteForegroundColor(FIB_OFF) form.fib5_6.setPaletteForegroundColor(BEAM_OFF)
def _noPen(self): """remove pen for this board. The pen defines the border""" if Debug.graphics: self.setPen(QPen(QColor(self.penColor))) else: self.setPen(QPen(Qt.NoPen))
class PlayerWind(AnimatedMixin, QGraphicsObject, StrMixin): """a round wind tile""" roundWindColor = QColor(235, 235, 173) whiteColor = QColor('white') def __init__(self, wind, parent=None): """generate new wind marker""" super(PlayerWind, self).__init__() assert not parent assert isinstance(wind, Wind), 'wind {} must be a real Wind but is {}'.format( wind, type(wind)) self.__wind = wind self.__brush = self.whiteColor self.board = None def name(self): """for identification in animations""" return self.__wind.tile def moveDict(self): """a dict with attributes for the new position, normally pos, rotation and scale""" sideCenter = self.board.center() boardPos = QPointF( sideCenter.x() * 1.63, sideCenter.y() - self.boundingRect().height() / 2.0) scenePos = self.board.mapToScene(boardPos) return {'pos': scenePos, 'rotation': sceneRotation(self.board)} def setDrawingOrder(self): """we want the winds above all others""" if self.activeAnimation.get('pos'): movingZ = ZValues.movingZ else: movingZ = 0 self.setZValue(ZValues.markerZ + movingZ) @property def wind(self): """our wind""" return self.__wind @property def prevailing(self): """is this the prevailing wind?""" return self.__brush is self.roundWindColor @prevailing.setter def prevailing(self, value): if isinstance(value, bool): newPrevailing = value else: newPrevailing = self.wind == Wind.all4[value % 4] self.__brush = self.roundWindColor if newPrevailing else self.whiteColor def paint(self, painter, dummyOption, dummyWidget=None): """paint the marker""" with Painter(painter): painter.setBrush(self.__brush) size = Internal.scene.windTileset.faceSize.height() ellRect = QRectF(QPoint(), QPoint(size, size)) painter.drawEllipse(ellRect) renderer = Internal.scene.windTileset.renderer() painter.translate(12, 12) painter.scale(0.60, 0.60) renderer.render(painter, self.wind.markerSvgName, self.boundingRect()) def boundingRect(self): # pylint: disable=no-self-use """define the part of the tile we want to see""" size = Internal.scene.windTileset.faceSize.height() * 1.1 return QRectF(QPoint(), QPoint(size, size)) def __str__(self): """for debugging""" return 'WindMarker(%s x/y= %.1f/%1f)' % ( self.name(), self.x(), self.y())
def paint(self, painter, dummyOption, dummyWidget): """override predefined paint""" painter.setFont(self.font) painter.fillRect(self.rect(), QBrush(QColor('yellow'))) painter.drawText(self.rect(), self.msg)