Exemplo n.º 1
0
 def add_combo_box( self, choicesL, index_init=0, name='cycle_desc',
                     advance_n=True, fulldesc='Select Engine Cycle', 
                     text_align='right', text_font=ARIAL_10, col=0, width=100,
                     parent=None, layout=None):
                    
     # if parent is input, add widget to parent
     if parent is None:
         parent = self
     
     
     if layout is None:
         NRow = parent.get_next_row_number(advance_n)
     
     lbl = QLabel("    %s "%fulldesc, parent)
     combo_box = QComboBox(parent)    
     lbl.setFont( text_font )
     combo_box.setFont( text_font )
     
     self.objectD['%s_combo_box'%name] = combo_box
     for choice in choicesL:
         combo_box.addItem(choice)
     combo_box.setCurrentIndex(index_init)
     if layout is None:
         parent.grid.addWidget(lbl,      NRow, col)
     else:
         layout.addWidget( lbl )
     
     
         
     hbox = QHBoxLayout()
     hbox.addWidget(combo_box)
     hbox.addStretch(1)
     widget = QWidget()
     widget.setLayout(hbox)
     
     if layout is None:
         parent.grid.addWidget(widget, NRow, col+1)
     
         if text_align=='right':
             parent.grid.setAlignment(lbl, Qt.AlignRight )
     else:
         layout.addWidget( widget )
     
     combo_box.setFixedWidth( width )
         
     combo_box.activated[str].connect( lambda: self.combo_box_changed( '%s_combo_box'%name ) )   
         
     self.input_widget_by_nameD[name] = (combo_box, 'combo_box')
Exemplo n.º 2
0
class MCAHPanel(QWidget):
    def __init__(self, parent, altitudeUnit=AltitudeUnits.FT):
        QWidget.__init__(self, parent)
        while not isinstance(parent, QDialog):
            parent = parent.parent()
        self.setObjectName("MCAHPanel" +
                           str(len(parent.findChildren(MCAHPanel))))

        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)

        self.hLayout = QHBoxLayout(self)
        self.hLayout.setSpacing(0)
        self.hLayout.setMargin(0)
        self.hLayout.setObjectName("hLayout")

        self.basicFrame = Frame(self, "HL")
        self.basicFrame.Spacing = 0
        self.hLayout.addWidget(self.basicFrame)

        self.lblMCAH = QLabel(self.basicFrame)
        self.lblMCAH.setMinimumSize(QSize(250, 0))
        font = QFont()
        font.setWeight(50)
        font.setBold(False)
        self.lblMCAH.setFont(font)
        self.lblMCAH.setObjectName(("lblMCAH"))
        self.basicFrame.Add = self.lblMCAH
        self.cmbMCAH = QComboBox(self.basicFrame)
        font = QFont()
        font.setWeight(50)
        font.setBold(False)
        self.cmbMCAH.setFont(font)
        self.cmbMCAH.setObjectName(self.objectName() + "_cmbMCAH")
        self.basicFrame.Add = self.cmbMCAH
        self.txtMCAH = QLineEdit(self.basicFrame)
        font = QFont()
        font.setWeight(50)
        font.setBold(False)
        self.txtMCAH.setFont(font)
        self.txtMCAH.setObjectName(self.objectName() + "_txtMCAH")
        self.txtMCAH.setMinimumWidth(70)
        self.txtMCAH.setMaximumWidth(70)
        self.basicFrame.Add = self.txtMCAH
        self.setLayout(self.hLayout)

        spacerItem = QSpacerItem(0, 10, QSizePolicy.Minimum,
                                 QSizePolicy.Minimum)
        self.hLayout.addItem(spacerItem)
        self.cmbMCAH.addItems([MCAHType.MCA, MCAHType.MCH])
        #         self.txtMCAH.textChanged.connect(self.txtAltitude_TextChanged)
        self.altitudeUnit = altitudeUnit

    def setValue(self, altitude_0):
        if self.altitudeUnit == AltitudeUnits.FT:
            value1 = altitude_0.Feet
        elif self.altitudeUnit == AltitudeUnits.M:
            value1 = altitude_0.Metres
        self.txtMCAH.setText(str(value1))

    def set_Value(self, altitude_0):
        if self.altitudeUnit == AltitudeUnits.FT:
            value1 = altitude_0.Feet
        elif self.altitudeUnit == AltitudeUnits.M:
            value1 = altitude_0.Metres
        self.txtMCAH.setText(str(value1))

    def get_Value(self):
        try:
            return Altitude(float(self.txtMCAH.text()), self.altitudeUnit)
        except:
            raise UserWarning, self.lblMCAH.text() + " is invalid!"

    Value = property(get_Value, set_Value, None, None)

    def IsEmpty(self):
        if self.txtMCAH.text() == "":
            return True
        else:
            return False

    def method_2(self, altitude_0):
        if (self.cmbMCAH.currentIndex() == 0):
            return self.Value
        return self.Value + (altitude_0)

    def method_3(self, altitude_0):
        if (self.cmbMCAH.currentIndex() != 0):
            return self.Value
        return self.Value - (altitude_0)
Exemplo n.º 3
0
class RecordingWidget(QWidget):
    """Widget containing main recording UI for Freeseer"""

    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        icon = QIcon()
        icon.addPixmap(QPixmap(":/freeseer/logo.png"), QIcon.Normal, QIcon.Off)
        self.setWindowIcon(icon)
        self.resize(400, 400)

        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        boldFont = QFont()
        boldFont.setBold(True)

        # Control bar
        self.controlRow = QHBoxLayout()
        self.mainLayout.addLayout(self.controlRow)

        self.standbyIcon = QIcon.fromTheme("system-shutdown")
        recordFallbackIcon = QIcon(":/multimedia/record.png")
        self.recordIcon = QIcon.fromTheme("media-record", recordFallbackIcon)
        stopFallbackIcon = QIcon(":/multimedia/stop.png")
        self.stopIcon = QIcon.fromTheme("media-playback-stop", stopFallbackIcon)
        self.pauseIcon = QIcon.fromTheme("media-playback-pause")
        self.resumeIcon = QIcon.fromTheme("media-playback-start")
        self.headphoneIcon = QIcon()
        self.headphoneIcon.addPixmap(QPixmap(":/multimedia/headphones.png"), QIcon.Normal, QIcon.Off)

        self.standbyPushButton = QPushButton("Standby")
        self.standbyPushButton.setToolTip("Standby")
        self.standbyPushButton.setMinimumSize(QSize(0, 40))
        self.standbyPushButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.standbyPushButton.setIcon(self.standbyIcon)
        self.standbyPushButton.setCheckable(True)
        self.standbyPushButton.setObjectName("standbyButton")
        self.controlRow.addWidget(self.standbyPushButton)

        self.recordPushButton = QPushButton("Record")
        self.recordPushButton.setToolTip("Record")
        self.recordPushButton.setMinimumSize(QSize(0, 40))
        self.recordPushButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.recordPushButton.setIcon(self.recordIcon)
        self.recordPushButton.setHidden(True)
        self.recordPushButton.setEnabled(False)
        self.recordPushButton.setCheckable(True)
        self.recordPushButton.setObjectName("recordButton")
        self.controlRow.addWidget(self.recordPushButton)
        self.connect(self.recordPushButton, SIGNAL("toggled(bool)"), self.setRecordIcon)

        self.pauseToolButton = QToolButton()
        self.pauseToolButton.setText("Pause")
        self.pauseToolButton.setToolTip("Pause")
        self.pauseToolButton.setIcon(self.pauseIcon)
        self.pauseToolButton.setMinimumSize(QSize(40, 40))
        self.pauseToolButton.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.pauseToolButton.setHidden(True)
        self.pauseToolButton.setEnabled(False)
        self.pauseToolButton.setCheckable(True)
        self.controlRow.addWidget(self.pauseToolButton)
        self.connect(self.pauseToolButton, SIGNAL("toggled(bool)"), self.setPauseIcon)

        playbackIcon = QIcon.fromTheme("video-x-generic")
        self.playPushButton = QPushButton()
        self.playPushButton.setText("Play Video")
        self.playPushButton.setToolTip("Play last recorded Video")
        self.playPushButton.setIcon(playbackIcon)
        self.playPushButton.setMinimumSize(QSize(40, 40))
        self.playPushButton.setMaximumSize(QSize(120, 40))
        self.playPushButton.setHidden(True)
        self.playPushButton.setEnabled(False)
        self.playPushButton.setCheckable(True)
        self.controlRow.addWidget(self.playPushButton)

        # Filter bar
        self.filterBarLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.filterBarLayout)

        self.filterBarLayoutRow_1 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_1)
        self.eventLabel = QLabel("Event")
        self.eventLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.eventComboBox = QComboBox()
        self.eventLabel.setBuddy(self.eventComboBox)
        self.roomLabel = QLabel("Room")
        self.roomLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.roomComboBox = QComboBox()
        self.roomLabel.setBuddy(self.roomComboBox)
        self.dateLabel = QLabel("Date")
        self.dateLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.dateComboBox = QComboBox()
        self.dateLabel.setBuddy(self.dateComboBox)
        self.filterBarLayoutRow_1.addWidget(self.eventLabel)
        self.filterBarLayoutRow_1.addWidget(self.eventComboBox)
        self.filterBarLayoutRow_1.addWidget(self.roomLabel)
        self.filterBarLayoutRow_1.addWidget(self.roomComboBox)
        self.filterBarLayoutRow_1.addWidget(self.dateLabel)
        self.filterBarLayoutRow_1.addWidget(self.dateComboBox)

        self.filterBarLayoutRow_2 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_2)
        self.talkLabel = QLabel("Talk ")
        self.talkLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.talkComboBox = QComboBox()
        self.talkComboBox.setFont(boldFont)
        self.talkComboBox.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)
        self.talkComboBox.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
        self.filterBarLayoutRow_2.addWidget(self.talkLabel)
        self.filterBarLayoutRow_2.addWidget(self.talkComboBox)

        # Preview Layout
        self.previewLayout = QHBoxLayout()
        self.mainLayout.addLayout(self.previewLayout)

        self.previewWidget = QWidget()
        self.audioSlider = QSlider()
        self.audioSlider.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.audioSlider.setEnabled(False)
        self.previewLayout.addWidget(self.previewWidget)
        self.previewLayout.addWidget(self.audioSlider)

        self.statusLabel = QLabel()
        self.mainLayout.addWidget(self.statusLabel)

        # Audio Feedback Checkbox
        self.audioFeedbackCheckbox = QCheckBox()
        self.audioFeedbackCheckbox.setLayoutDirection(Qt.RightToLeft)
        self.audioFeedbackCheckbox.setIcon(self.headphoneIcon)
        self.audioFeedbackCheckbox.setToolTip("Enable Audio Feedback")
        self.mainLayout.addWidget(self.audioFeedbackCheckbox)

    def setRecordIcon(self, state):
        if state:
            self.recordPushButton.setIcon(self.stopIcon)
        else:
            self.recordPushButton.setIcon(self.recordIcon)

    def setPauseIcon(self, state):
        if state:
            self.pauseToolButton.setIcon(self.resumeIcon)
        else:
            self.pauseToolButton.setIcon(self.pauseIcon)
Exemplo n.º 4
0
class RecordingWidget(QWidgetWithDpi):
    """Widget containing main recording UI for Freeseer"""

    def __init__(self, parent=None):
        super(RecordingWidget, self).__init__(parent)

        icon = QIcon()
        icon.addPixmap(QPixmap(":/freeseer/logo.png"), QIcon.Normal, QIcon.Off)
        self.setWindowIcon(icon)
        self.resize(400, 400)

        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.setStyleSheet(
            """
            QToolButton {
                background-color: #D1D1D1;
                border-style: solid;
                border-width: 1px;
                border-radius: 10px;
                border-color: #969696;
                padding: 6px;
            }

            QToolButton:pressed {
                background-color: #A3A2A2;
                border-width: 2px;
                border-color: #707070;
            }

            QToolButton:checked {
                background-color: #A3A2A2;
                border-width: 2px;
                border-color: #707070;
            }

            QToolButton:disabled {
                background-color: #EDEDED;
                border-color: #BFBDBD;
            }

            QToolButton:hover {
                border-width: 2px;
            }
        """
        )

        boldFont = QFont()
        boldFont.setBold(True)

        fontSize = self.font().pixelSize()
        fontUnit = "px"
        if fontSize == -1:  # Font is set as points, not pixels.
            fontUnit = "pt"
            fontSize = self.font().pointSize()

        # Control bar
        self.controlRow = QHBoxLayout()
        self.mainLayout.addLayout(self.controlRow)

        self.recordIcon = QIcon(":/multimedia/record.png")
        self.stopIcon = QIcon(":/multimedia/stop.png")
        pauseIcon = QIcon(":/multimedia/pause.png")
        playIcon = QIcon(":/multimedia/play.png")
        self.headphoneIcon = QIcon()
        self.headphoneIcon.addPixmap(QPixmap(":/multimedia/headphones.png"), QIcon.Normal, QIcon.Off)

        self.is_recording = False
        self.recordButton = QToolButtonWithDpi()
        self.recordButton.setToolTip("Record")
        self.recordButton.setFixedSize(QSize(60, 40))
        self.recordButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.recordButton.setIcon(self.recordIcon)
        self.recordButton.setEnabled(False)
        self.recordButton.setObjectName("recordButton")
        self.controlRow.addWidget(self.recordButton, 0, Qt.AlignLeft)
        self.connect(self.recordButton, SIGNAL("clicked()"), self.setRecordIcon)

        self.playButton = QToolButtonWithDpi()
        self.playButton.setToolTip("Play last recorded Video")
        self.playButton.setFixedSize(QSize(60, 40))
        self.playButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.playButton.setIcon(playIcon)
        self.playButton.setEnabled(False)
        self.controlRow.addWidget(self.playButton, 0, Qt.AlignLeft)

        self.pauseButton = QToolButtonWithDpi()
        self.pauseButton.setToolTip("Pause")
        self.pauseButton.setIcon(pauseIcon)
        self.pauseButton.setFixedSize(QSize(60, 40))
        self.pauseButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.pauseButton.setEnabled(False)
        self.pauseButton.setCheckable(True)
        self.controlRow.addWidget(self.pauseButton, 0, Qt.AlignLeft)

        self.controlRow.addSpacerItem(self.qspacer_item_with_dpi(30, 40))
        self.controlRow.addStretch(1)

        self.standbyButton = QPushButtonWithDpi("Standby")
        self.standbyButton.setStyleSheet(
            """
            QPushButton {{
                color: white;
                background-color: #47a447;
                border-style: solid;
                border-width: 0px;
                border-radius: 10px;
                border-color: #398439;
                font: bold {}{};
                padding: 6px;
            }}

            QPushButton:pressed {{
                background-color: #3E8A3E;
                border-color: #327532;
            }}

            QPushButton:hover {{
                border-width: 2px;
            }}
        """.format(
                fontSize + 3, fontUnit
            )
        )
        self.standbyButton.setToolTip("Standby")
        self.standbyButton.setFixedSize(QSize(180, 40))
        self.standbyButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.standbyButton.setCheckable(True)
        self.standbyButton.setObjectName("standbyButton")
        self.controlRow.addWidget(self.standbyButton)

        self.disengageButton = QPushButtonWithDpi("Leave record-mode")
        self.disengageButton.setStyleSheet(
            """
            QPushButton {{
                color: white;
                background-color: #D14343;
                border-style: solid;
                border-width: 0px;
                border-radius: 10px;
                border-color: #B02C2C;
                font: bold {}{};
                padding: 6px;
            }}

            QPushButton:pressed {{
                background-color: #AD2B2B;
                border-color: #8C2929;
            }}

            QPushButton:hover {{
                border-width: 2px;
            }}

            QPushButton:disabled {{
                background-color: #B89E9E;
        }}
        """.format(
                fontSize + 3, fontUnit
            )
        )
        self.disengageButton.setToolTip("Leave record-mode")
        self.disengageButton.setFixedSize(QSize(180, 40))
        self.disengageButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.disengageButton.setHidden(True)
        self.disengageButton.setObjectName("disengageButton")
        self.controlRow.addWidget(self.disengageButton)

        # Filter bar
        self.filterBarLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.filterBarLayout)

        self.filterBarLayoutRow_1 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_1)
        self.eventLabel = QLabel("Event")
        self.eventLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.eventComboBox = QComboBox()
        self.eventLabel.setBuddy(self.eventComboBox)
        self.roomLabel = QLabel("Room")
        self.roomLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.roomComboBox = QComboBox()
        self.roomLabel.setBuddy(self.roomComboBox)
        self.dateLabel = QLabel("Date")
        self.dateLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.dateComboBox = QComboBox()
        self.dateLabel.setBuddy(self.dateComboBox)
        self.filterBarLayoutRow_1.addWidget(self.eventLabel)
        self.filterBarLayoutRow_1.addWidget(self.eventComboBox)
        self.filterBarLayoutRow_1.addWidget(self.roomLabel)
        self.filterBarLayoutRow_1.addWidget(self.roomComboBox)
        self.filterBarLayoutRow_1.addWidget(self.dateLabel)
        self.filterBarLayoutRow_1.addWidget(self.dateComboBox)

        self.filterBarLayoutRow_2 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_2)
        self.talkLabel = QLabel("Talk ")
        self.talkLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.talkComboBox = QComboBox()
        self.talkComboBox.setFont(boldFont)
        self.talkComboBox.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)
        self.talkComboBox.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
        self.filterBarLayoutRow_2.addWidget(self.talkLabel)
        self.filterBarLayoutRow_2.addWidget(self.talkComboBox)

        # Preview Layout
        self.previewLayout = QHBoxLayout()
        self.mainLayout.addLayout(self.previewLayout)

        self.previewWidget = QWidget()
        self.audioSlider = QSlider()
        self.audioSlider.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.audioSlider.setEnabled(False)
        self.previewLayout.addWidget(self.previewWidget)
        self.previewLayout.addWidget(self.audioSlider)

        self.statusLabel = QLabel()
        self.mainLayout.addWidget(self.statusLabel)

        # Audio Feedback Checkbox
        self.audioFeedbackCheckbox = QCheckBox()
        self.audioFeedbackCheckbox.setLayoutDirection(Qt.RightToLeft)
        self.audioFeedbackCheckbox.setIcon(self.headphoneIcon)
        self.audioFeedbackCheckbox.setToolTip("Enable Audio Feedback")
        self.mainLayout.addWidget(self.audioFeedbackCheckbox)

    def setRecordIcon(self):
        self.is_recording = not self.is_recording
        if self.is_recording:
            self.recordButton.setIcon(self.stopIcon)
        else:
            self.recordButton.setIcon(self.recordIcon)
Exemplo n.º 5
0
class WindPanel(QFrame):
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        #         self.frame_WindIA = QFrame(parent)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Raised)
        self.setObjectName(("frame_WindIA"))
        self.horizontalLayout_32 = QHBoxLayout(self)
        self.horizontalLayout_32.setSpacing(0)
        self.horizontalLayout_32.setMargin(0)
        self.horizontalLayout_32.setObjectName(("horizontalLayout_32"))
        self.lblIA = QLabel(self)
        self.lblIA.setMinimumSize(QSize(140, 0))
        self.lblIA.setMaximumSize(QSize(100, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.lblIA.setFont(font)
        self.lblIA.setObjectName(("lblIA"))
        self.horizontalLayout_32.addWidget(self.lblIA)
        self.comboBox = QComboBox(self)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.comboBox.sizePolicy().hasHeightForWidth())
        self.comboBox.setSizePolicy(sizePolicy)
        self.comboBox.setMinimumSize(QSize(60, 0))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName(("comboBox"))
        self.horizontalLayout_32.addWidget(self.comboBox)
        self.speedBox = QLineEdit(self)
        sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding,
                                 QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.speedBox.sizePolicy().hasHeightForWidth())
        self.speedBox.setSizePolicy(sizePolicy)
        self.speedBox.setMinimumSize(QSize(70, 0))
        self.speedBox.setMaximumSize(QSize(16777215, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.speedBox.setFont(font)
        self.speedBox.setObjectName(("speedBox"))
        self.horizontalLayout_32.addWidget(self.speedBox)

        self.altitude = Altitude.NaN()
        self.customValue = Speed(30).Knots
        self.comboBox.addItems(["ICAO", "UK", "Custom"])
        self.comboBox.currentIndexChanged.connect(self.changeWindType)
        self.comboBox.setCurrentIndex(0)
        self.lblIA.setText("Wind (kts):")
        self.speedBox.setEnabled(False)

    def setAltitude(self, value):
        self.altitude = value
        self.method_5()
#     def getValue(self, SpeedUnits_0 = SpeedUnits.KTS):
#         return Speed(float(self.speedBox.text()), SpeedUnits_0)

    def method_3(self, altitude_0):
        altitude = Altitude(float(self.speedBox.text()), AltitudeUnits.FT)
        if (self.comboBox.currentIndex() != 0):
            return altitude
        return Altitude(altitude.Feet - altitude_0.Feet, AltitudeUnits.FT)

    def method_5(self):
        if self.comboBox.currentIndex() == 0:
            self.speedBox.setText(
                str(round(Speed.smethod_1(self.altitude).Knots, 1)))
        elif self.comboBox.currentIndex() == 1:
            self.speedBox.setText(
                str(round(Speed.smethod_2(self.altitude).Knots, 1)))
        else:
            self.speedBox.setText(str(self.customValue))
        if self.comboBox.currentIndex() != 2:
            self.speedBox.setEnabled(False)
        else:
            self.speedBox.setEnabled(True)

    def changeWindType(self):
        self.method_5()

    def method_7(self, string_0):
        # object[] string0 = new object[] { string_0, this.captionLabel.Caption, this.speedBox.ToString(), this.comboBox.Items[this.comboBox.SelectedIndex] };
        return "%s%s\t%s (%s)" % (string_0, "Wind: ", self.speedBox.text(),
                                  self.comboBox.currentText())

    def get_speed(self):
        try:
            return Speed(float(self.speedBox.text()))
        except:
            return None

    Value = property(get_speed, None, None, None)

    def get_isEmpty(self):
        try:
            num = float(self.speedBox.text())
            return False
        except:
            return True

    IsEmpty = property(get_isEmpty, None, None, None)
Exemplo n.º 6
0
class RecordingWidget(QWidget):
    """Widget containing main recording UI for Freeseer"""
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        icon = QIcon()
        icon.addPixmap(QPixmap(":/freeseer/logo.png"), QIcon.Normal, QIcon.Off)
        self.setWindowIcon(icon)
        self.resize(400, 400)

        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        boldFont = QFont()
        boldFont.setBold(True)

        # Control bar
        self.controlRow = QHBoxLayout()
        self.mainLayout.addLayout(self.controlRow)

        self.standbyIcon = QIcon.fromTheme("system-shutdown")
        recordFallbackIcon = QIcon(":/multimedia/record.png")
        self.recordIcon = QIcon.fromTheme("media-record", recordFallbackIcon)
        stopFallbackIcon = QIcon(":/multimedia/stop.png")
        self.stopIcon = QIcon.fromTheme("media-playback-stop",
                                        stopFallbackIcon)
        self.pauseIcon = QIcon.fromTheme("media-playback-pause")
        self.resumeIcon = QIcon.fromTheme("media-playback-start")
        self.headphoneIcon = QIcon()
        self.headphoneIcon.addPixmap(QPixmap(":/multimedia/headphones.png"),
                                     QIcon.Normal, QIcon.Off)

        self.standbyPushButton = QPushButton("Standby")
        self.standbyPushButton.setToolTip("Standby")
        self.standbyPushButton.setMinimumSize(QSize(0, 40))
        self.standbyPushButton.setSizePolicy(QSizePolicy.Minimum,
                                             QSizePolicy.Fixed)
        self.standbyPushButton.setIcon(self.standbyIcon)
        self.standbyPushButton.setCheckable(True)
        self.standbyPushButton.setObjectName("standbyButton")
        self.controlRow.addWidget(self.standbyPushButton)

        self.autoRecordPushButton = QPushButton("Auto Record")
        self.autoRecordPushButton.setToolTip("Automated Recording")
        self.autoRecordPushButton.setMinimumSize(QSize(40, 40))
        self.autoRecordPushButton.setMaximumSize(QSize(120, 40))
        self.autoRecordPushButton.setCheckable(True)
        self.autoRecordPushButton.setObjectName("autoRecordButton")
        self.controlRow.addWidget(self.autoRecordPushButton)

        self.recordPushButton = QPushButton("Record")
        self.recordPushButton.setToolTip("Record")
        self.recordPushButton.setMinimumSize(QSize(0, 40))
        self.recordPushButton.setSizePolicy(QSizePolicy.Minimum,
                                            QSizePolicy.Fixed)
        self.recordPushButton.setIcon(self.recordIcon)
        self.recordPushButton.setHidden(True)
        self.recordPushButton.setEnabled(False)
        self.recordPushButton.setCheckable(True)
        self.recordPushButton.setObjectName("recordButton")
        self.controlRow.addWidget(self.recordPushButton)
        self.connect(self.recordPushButton, SIGNAL("toggled(bool)"),
                     self.setRecordIcon)

        self.pauseToolButton = QToolButton()
        self.pauseToolButton.setText("Pause")
        self.pauseToolButton.setToolTip("Pause")
        self.pauseToolButton.setIcon(self.pauseIcon)
        self.pauseToolButton.setMinimumSize(QSize(40, 40))
        self.pauseToolButton.setSizePolicy(QSizePolicy.Maximum,
                                           QSizePolicy.Fixed)
        self.pauseToolButton.setHidden(True)
        self.pauseToolButton.setEnabled(False)
        self.pauseToolButton.setCheckable(True)
        self.controlRow.addWidget(self.pauseToolButton)
        self.connect(self.pauseToolButton, SIGNAL("toggled(bool)"),
                     self.setPauseIcon)

        playbackIcon = QIcon.fromTheme("video-x-generic")
        self.playPushButton = QPushButton()
        self.playPushButton.setText("Play Video")
        self.playPushButton.setToolTip("Play last recorded Video")
        self.playPushButton.setIcon(playbackIcon)
        self.playPushButton.setMinimumSize(QSize(40, 40))
        self.playPushButton.setMaximumSize(QSize(120, 40))
        self.playPushButton.setHidden(True)
        self.playPushButton.setEnabled(False)
        self.playPushButton.setCheckable(True)
        self.controlRow.addWidget(self.playPushButton)

        # Filter bar
        self.filterBarLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.filterBarLayout)

        self.filterBarLayoutRow_1 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_1)
        self.eventLabel = QLabel("Event")
        self.eventLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.eventComboBox = QComboBox()
        self.eventLabel.setBuddy(self.eventComboBox)
        self.roomLabel = QLabel("Room")
        self.roomLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.roomComboBox = QComboBox()
        self.roomLabel.setBuddy(self.roomComboBox)
        self.dateLabel = QLabel("Date")
        self.dateLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.dateComboBox = QComboBox()
        self.dateLabel.setBuddy(self.dateComboBox)
        self.filterBarLayoutRow_1.addWidget(self.eventLabel)
        self.filterBarLayoutRow_1.addWidget(self.eventComboBox)
        self.filterBarLayoutRow_1.addWidget(self.roomLabel)
        self.filterBarLayoutRow_1.addWidget(self.roomComboBox)
        self.filterBarLayoutRow_1.addWidget(self.dateLabel)
        self.filterBarLayoutRow_1.addWidget(self.dateComboBox)

        self.filterBarLayoutRow_2 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_2)
        self.talkLabel = QLabel("Talk ")
        self.talkLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.talkComboBox = QComboBox()
        self.talkComboBox.setFont(boldFont)
        self.talkComboBox.setSizePolicy(QSizePolicy.Minimum,
                                        QSizePolicy.Maximum)
        self.talkComboBox.setSizeAdjustPolicy(
            QComboBox.AdjustToMinimumContentsLength)
        self.filterBarLayoutRow_2.addWidget(self.talkLabel)
        self.filterBarLayoutRow_2.addWidget(self.talkComboBox)

        # Preview Layout
        self.previewLayout = QHBoxLayout()
        self.mainLayout.addLayout(self.previewLayout)

        self.previewWidget = QWidget()
        self.audioSlider = QSlider()
        self.audioSlider.setSizePolicy(QSizePolicy.Fixed,
                                       QSizePolicy.Expanding)
        self.audioSlider.setEnabled(False)
        self.previewLayout.addWidget(self.previewWidget)
        self.previewLayout.addWidget(self.audioSlider)

        self.statusLabel = QLabel()
        self.mainLayout.addWidget(self.statusLabel)

        # Audio Feedback Checkbox
        self.audioFeedbackCheckbox = QCheckBox()
        self.audioFeedbackCheckbox.setLayoutDirection(Qt.RightToLeft)
        self.audioFeedbackCheckbox.setIcon(self.headphoneIcon)
        self.audioFeedbackCheckbox.setToolTip("Enable Audio Feedback")
        self.mainLayout.addWidget(self.audioFeedbackCheckbox)

    def setRecordIcon(self, state):
        if state:
            self.recordPushButton.setIcon(self.stopIcon)
        else:
            self.recordPushButton.setIcon(self.recordIcon)

    def setPauseIcon(self, state):
        if state:
            self.pauseToolButton.setIcon(self.resumeIcon)
        else:
            self.pauseToolButton.setIcon(self.pauseIcon)
Exemplo n.º 7
0
class QuestionDlg(QDialog):
    def __init__(self, parent=None):
        super(QuestionDlg,self).__init__(parent)
        # self.setStyleSheet("background-image:url('image/panelbg.jpg'); border: 2px; border-radius 2px;")
        # self.createDb()
        # return

        self.db = QSqlDatabase.addDatabase("QSQLITE");  
        self.db.setDatabaseName("studentNew.db")
        if not self.db.open():
            QMessageBox.warning(None, "错误",  "数据库连接失败: %s" % self.db.lastError().text())
            sys.exit(1)

        self.g_curClassName = ""
        self.deleteTmpdata()

        self.setWindowFlags(Qt.CustomizeWindowHint)
        # self.setStyleSheet("border: 2px; border-radius 2px;")
        # self.setWindowFlags(Qt.FramelessWindowHint)
        self.setStyleSheet("background-color: rgba(132, 171, 208, 200);")

        self.tabWidget=QTabWidget(self)
        self.tabWidget.currentChanged.connect(self.changeTab)
        # tabWidget.setTabShape(QTabWidget.Triangular)
        self.tabWidget.setStyleSheet("QTabWidget::pane{border-width:1px;border-color:rgb(48, 104, 151);\
            border-style: outset;background-color: rgb(132, 171, 208);\
            background: transparent;} \
            QTabWidget::tab-bar{border-width:0px;}\
            QTabBar::tab { height: 60px; width: 260px; color:rgb(0, 0, 255); font-size:20px; font-weight:bold;} \
            QTabBar::tab:hover{background:rgb(255,255, 255, 100);} \
            QTabBar::tab:selected{border-color:green;background-color:white;color:green;}")
        # tabWidget.setStyleSheet("QTabBar::tab:hover{background:rgb(255,255, 255, 100);}")
        self.btngroup = QButtonGroup()
        self.popMenu = QMenu(self)
        entry1 = self.popMenu.addAction("正确")
        self.connect(entry1,SIGNAL('triggered()'), lambda : self.answerRight())
        entry2 = self.popMenu.addAction("错误")
        self.connect(entry2,SIGNAL('triggered()'), lambda : self.answerWrong())
        entry3 = self.popMenu.addAction("替换")
        self.connect(entry3,SIGNAL('triggered()'), lambda : self.resetStudent())

        # Create the first tab page.
        self.w1=QWidget()
        self.w1.setAccessibleName("w1tab")
        self.genOneTab()
        
        # Create the second tab page.
        self.w2=QWidget()
        self.w2.setAccessibleName("w2tab")        
        self.genTwoTab()

        self.tabWidget.addTab(self.w1,"")
        self.tabWidget.addTab(self.w2,"班级学生信息管理")
        self.tabWidget.resize(940,700)

        btnclose = QPushButton(self)
        btnclose.setToolTip("关闭")
        btnclose.setText("╳")
        btnclose.setGeometry(915, 5, 20, 20)
        btnclose.setStyleSheet("background-color:rgb(0,100,0); color:rgb(255,255,255)")
        btnclose.clicked.connect(self.close)
        btnMinimized = QPushButton(self)
        btnMinimized.setToolTip("最小化")
        btnMinimized.setText("▁")
        btnMinimized.setGeometry(890, 5, 20, 20)
        btnMinimized.setStyleSheet("background-color:rgb(0,100,0); color:rgb(255,255,255)")
        btnMinimized.clicked.connect(lambda: self.showMinimized())
        self.btnSysMenu = QPushButton(self)
        # self.btnSysMenu.setText("▼")
        self.btnSysMenu.setGeometry(865, 5, 20, 20)
        self.btnSysMenu.setToolTip("系统设置")
        self.btnSysMenu.clicked.connect(lambda: self.showMinimized())
        menufont = QFont("宋体", 10)
        popMenu = QMenu(self)
        entry1 = popMenu.addAction("所有学生提问信息清零")
        entry1.setFont(menufont)
        self.connect(entry1,SIGNAL('triggered()'), self.initStudent)
        entry2 = popMenu.addAction("清除本堂课提问人员")
        entry2.setFont(menufont)
        self.connect(entry2,SIGNAL('triggered()'), self.deleteTmpdata)
        entry3 = popMenu.addAction("关于...")
        entry3.setFont(menufont)
        self.connect(entry3,SIGNAL('triggered()'), self.aboutMe)
        entry4 = popMenu.addAction("导出...")
        entry4.setFont(menufont)
        self.connect(entry4,SIGNAL('triggered()'), self.exportNotice)

        self.btnSysMenu.setMenu(popMenu)
        self.btnSysMenu.setStyleSheet("QPushButton::menu-indicator {image: url('image/sysmenu.png');subcontrol-position: right center;} ")
        # self.btnSysMenu.setStyleSheet("background-color:rgb(0,100,0); color:rgb(255,255,255);")

        authorinfo = QLabel(self.tabWidget)
        # authorinfo.setToolTip("关闭")
        authorinfo.setText("程序设计:汕头市大华路第一小学 赵小娜,有任何问题请反馈至[email protected]。")
        authorinfo.setGeometry(20, 665, 470, 26)
        authorinfo.setFont(QFont('Courier New'))
        authorinfo.setStyleSheet("background-color:rgba(255, 255, 255,160); font-size:12px;border: 1px solid rgb(60,200,255,200);color:rgba(0,0,0,220);border-radius:12px;")

        self.setWindowTitle("课堂随机提问")
        self.setWindowIcon(QIcon("image/start.ico"))
        self.setGeometry(100, 20, 940, 700)

        # self.changeTab()

        screen = QDesktopWidget().screenGeometry()
        size = self.geometry()
        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)

        self.btn_start.setMyarg('start')
        
        # print(self.btn_start.getMyarg())

        self.connect(self.btn_start, SIGNAL("clicked()"), self.startChoice)
        # self.connect(self.w1title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
        # self.connect(self.btn_start2, SIGNAL("clicked()"), self.startChoice)
        # self.connect(self.w2title, SIGNAL("currentIndexChanged(int)"), self.changeTitle)
        self.btngroup.buttonClicked[int].connect(self.btns_click)
        # self.connect(self.btn_start,  SIGNAL("myslot(PyQt_PyObject)"), self.myslot)  
        # self.connect(self.btngroup, SIGNAL("buttonClicked(int)"), lambda:self.btns_click())

    def myslot(self, text):  
        # print(text, self.dict_choices)
        self.g_curbtn = text
        if self.g_curbtn not in self.dict_choices:
            self.btnSysMenu.setFocus()
            return

        # print(self.btngroup.button(int(self.g_curbtn)).parent())
        # print(type(self.btngroup.button(int(self.g_curbtn)).parentWidget()))
        pos = self.btngroup.button(int(self.g_curbtn)).parent().mapToGlobal(self.btngroup.button(int(self.g_curbtn)).pos())
        width = self.btngroup.button(int(self.g_curbtn)).rect().height()
        # print("-----", pos, width)
        pos.setY(pos.y()+width-5)

        indx = 0
        for istate in self.dict_choices[self.g_curbtn]:
            if istate == '1':
                self.popMenu.actions()[indx].setEnabled(True)
            elif istate == '0':
                self.popMenu.actions()[indx].setEnabled(False)
            indx += 1
        self.popMenu.exec_(pos)
        self.btnSysMenu.setFocus()
    # def on_context_menu(self, point):
    #     print(point)
    #     self.popMenu.exec_(self.button.mapToGlobal(point)) 

    def btns_click(self, btnid):
        # curclassname = self.tabWidget.tabText(0)
        query = QSqlQuery(self.db)
        # cur = conn.cursor()
        today = datetime.date.today()
        self.g_curbtn = str(btnid).zfill(2)
        if self.g_curbtn not in self.dict_choices:
            self.btngroup.button(int(self.g_curbtn)).setStyleSheet(stylesheetstr_new)
            query.exec_("select count(*) from tmprecord where stusn='" + str(self.g_curbtn) + "'")
            query.next()            
            if query.value(0) == 0:
                query.prepare("insert into tmprecord (classname, stusn, datequestion) values (:classname, :stusn, :datequestion)")
                query.bindValue(":classname", self.g_curClassName)
                query.bindValue(":stusn", self.g_curbtn)
                query.bindValue(":datequestion", today)
                query.exec_() 
                
            self.dict_choices[self.g_curbtn] = "111"
        else:
            self.btngroup.button(int(self.g_curbtn)).setStyleSheet(stylesheetstr_old)
            self.btngroup.button(int(self.g_curbtn)).setIcon(QIcon())            
            query.exec_("delete from tmprecord where stusn='"+ str(self.g_curbtn) + "'")            
            self.dict_choices.pop(self.g_curbtn)

        self.btnSysMenu.setFocus()

    def exportNotice(self):
        query = QSqlQuery(self.db)
        query.exec_("select stusn, stuname, classname, rightquestions, wrongquestions from student" ) 
        lstInfo = [["学号","姓名", "班级", "回答正确次数", "回答错误次数"]]
        while(query.next()):
            lstInfo.append([query.value(0),query.value(1),query.value(2),query.value(3),query.value(4)])

        from xlwt import Workbook,easyxf
        book = Workbook(encoding='ascii')
            # 'pattern: pattern solid,  fore_colour white;'
        style = easyxf(
            'font: height 280, name 黑体;'
            'align: vertical center, horizontal center;'
            )
        style2 = easyxf('font: height 260, name 仿宋_GB2312, bold True; align: vertical center, horizontal left;')
        style3 = easyxf('font: height 260, name 仿宋_GB2312, bold True; align: vertical center, horizontal left, wrap True;')

        sheet1 = book.add_sheet('学生提问情况汇总',cell_overwrite_ok=True)
        # sheet1.write(0,7,flagtxt, easyxf('font: height 200, name 黑体;align: vertical center, horizontal right;'))
        sheet1.write_merge(0,0,0,4, '学生提问情况汇总表',style)
        sheet1.row(0).height_mismatch = 1
        sheet1.row(0).height = 5*256

        sheet1.col(0).width = 10*256
        sheet1.col(1).width = 25*256
        sheet1.col(2).width = 25*256
        sheet1.col(3).width = 20*256
        sheet1.col(4).width = 20*256
        
        tmprows = 1
        for item in lstInfo:
            stusn               = item[0]
            stuname             = item[1]
            classname           = item[2]
            rightquestions      = item[3]
            wrongquestions      = item[4]

            sheet1.write(tmprows,0,stusn, style2)
            sheet1.write(tmprows,1,stuname, style2)
            sheet1.write(tmprows,2,classname, style2)
            sheet1.write(tmprows,3,rightquestions, style2)
            sheet1.write(tmprows,4,wrongquestions, style2)
            tmprows += 1
        # print(tmprows)
        sheet1.header_str = "".encode()
        sheet1.footer_str = "".encode()

        # book.save('d:/simple.xls')
        # print(QDir.home().dirName() , QDir.homePath ())
        filename = QDir.homePath () + "\学生提问情况汇总表.xls" 
        try:
            book.save(filename)
        except  Exception as e:
            QMessageBox.warning(self, "写入错误", "错误号:"+str(e.errno)+"\n错误描述:"+e.strerror+"\n请关闭已经打开的%s文档!" % filename)
        QMessageBox.about (self, "导出成功", "请查看文档:%s" % filename)

    def aboutMe(self):
        strinfo = """本软件采用python3.4编写,界面采用qt4.8的python绑定。
                    \n版本所有:汕头市大华路第一小学赵小娜老师。
                    \n有任何问题请反馈至[email protected]。
                    """
        QMessageBox.information(None, "关于", strinfo)
        
    def initStudent(self):
        query = QSqlQuery(self.db)
        ret = query.exec_("update student set wrongquestions=0") 
        ret = query.exec_("update student set rightquestions=0")  
        QMessageBox.information(None, "提示", "已清除所有学生的累计提问情况。")


    def deleteTmpdata(self):
        query = QSqlQuery(self.db)
        ret = query.exec_("delete from tmprecord where 1=1" )   
        if self.g_curClassName != "":     
            QMessageBox.information(None, "提示", "已清除本次软件启动后的所有已提问过的学生。")
  
    def changeTab(self):
        # pass
        curtab = self.tabWidget.currentIndex()
        # print(curtab, "-")
        if curtab == 1:  ## when click the second tab page ,then pass.
            return
            
        # cur = conn.cursor()
        query = QSqlQuery(self.db)

        ## if current classname is null, then set current tabpage display the first class of classtable
        if self.g_curClassName == "":
            ret = query.exec_("select classname from classtable")
            query.next()
            self.g_curClassName = query.value(0)
            
        self.tabWidget.setTabText(0, self.g_curClassName)
        # print(1)
        strwhere = " and classname like '" + self.g_curClassName + "' ORDER BY stusn"

        self.g_curbtn = ""
        self.dict_choices = {}
        self.studentSnlst = []

        ## clearn the question data of temp record .
        ret= query.exec_("delete from tmprecord where 1=1")
        ret = query.exec_("select stusn, stuname from student where 1=1 " + strwhere)

        ## now update the global data "self.btngroup"
        for indx in range(0, 56):
            self.btngroup.button(indx+1).setText("")
            self.btngroup.button(indx+1).setMyarg(None)       
            self.btngroup.button(indx+1).setStyleSheet(stylesheetstr_old)
            self.btngroup.button(indx+1).setIcon(QIcon())
            self.btngroup.button(indx+1).setEnabled(False)
            self.studentSnlst.append([indx+1,])

        inum = 0
        while (query.next()): 
            inum += 1            
            self.btngroup.button(inum).setText(query.value(1))
            self.btngroup.button(inum).setMyarg(query.value(0))       
            self.btngroup.button(inum).setStyleSheet(stylesheetstr_old)
            self.btngroup.button(inum).setIcon(QIcon())
            self.btngroup.button(inum).setEnabled(True)

        # print(inum, len(self.btngroup.buttons()))        

        self.group_animation = groupAnimation(self.studentSnlst, self.btngroup)

    def mousePressEvent(self, event):
        # print('a')
        if event.button() == Qt.RightButton:
            QDialog.mousePressEvent(self,event)
            return
        # print(event.sender(), event.button())
        self.offset = event.pos()
        # print(self.offset)

    def mouseMoveEvent(self, event):
        # print('sss')
        if hasattr(self, 'offset'):
            x=event.globalX()
            y=event.globalY()
            x_w = self.offset.x()
            y_w = self.offset.y()
            self.move(x-x_w, y-y_w)
        else:
            pass

    #######======= studentModel ============###############
    def newStudent(self):
        # Calc the missing number:
        row = self.StudentModel.rowCount()

        if row > 0:
            oldNumList = []
            for i in range(0, row):
                oldNumList.append(int(self.StudentModel.index(i,2).data()))
            
            allNumberList = list(range(1, oldNumList[-1]+1))
            for i in range(0, allNumberList[-1]):
                if oldNumList[i] != allNumberList[i]:
                    missingNum = allNumberList[i]
                    break
            if len(oldNumList) == len(allNumberList):
                missingNum = allNumberList[i] +1
        else:
            missingNum = 1

        self.StudentModel.insertRow(row)
        self.StudentView.scrollToBottom()
        self.StudentModel.setData(self.StudentModel.index(row, 1), self.g_curClassName)
        self.StudentModel.setData(self.StudentModel.index(row, 2), str(missingNum).zfill(2))
        self.StudentModel.setData(self.StudentModel.index(row, 4), 0)
        self.StudentModel.setData(self.StudentModel.index(row, 5), 0)

    def removeStudent(self):
        index = self.StudentView.currentIndex()
        row = index.row()             
        if QMessageBox.question(self, "删除确认", "是否要删除当前选中记录?", "确定", "取消") == 0:
            self.StudentModel.removeRows(row, 1)
            self.StudentModel.submitAll()
            self.StudentModel.database().commit()

    def revertStudent(self):
        self.StudentModel.revertAll()
        self.StudentModel.database().rollback()

    def saveStudent(self):
        self.StudentModel.database().transaction()
        if self.StudentModel.submitAll():
            self.StudentModel.database().commit()
            # print("save success!  ->commit")
        else:
            self.StudentModel.revertAll()
            self.StudentModel.database().rollback()

    #######======= classModel ============###############
    def newClass(self):
        row = self.ClassnameModel.rowCount()
        self.ClassnameModel.insertRow(row)

    def removeClass(self):
        index = self.ClassnameView.currentIndex()
        row = index.row()   
        curClassname =  index.sibling(index.row(),0).data()
        strwhere = "classname like '" + curClassname + "'"
        self.StudentModel.setFilter(strwhere)
        self.StudentModel.select()
        # print(self.StudentModel.rowCount(), "----", )
        if QMessageBox.question(self, "删除确认", "删除班级意味着会删除本班所有人员信息。是否要删除当前选中记录?", "确定", "取消") == 0:
            self.ClassnameModel.removeRows(row, 1)
            self.ClassnameModel.submitAll()
            self.ClassnameModel.database().commit()

            self.StudentModel.removeRows(0, self.StudentModel.rowCount())
            self.StudentModel.submitAll()
            self.StudentModel.database().commit()

    def revertClass(self):
        self.ClassnameModel.revertAll()
        self.ClassnameModel.database().rollback()

    def saveClass(self):
        query = QSqlQuery(self.db)

        # record the old class name
        lstOldClassName = {}
        lstOldClassid = []
        query.exec_("select rowid, classname from classtable" )        
        while(query.next()):
            lstOldClassName[query.value(0)] = query.value(1)
            lstOldClassid.append(query.value(0))
        # print(lstOldClassName)

        # Update the class Table
        self.ClassnameModel.database().transaction()
        if self.ClassnameModel.submitAll():
            self.ClassnameModel.database().commit()
            # print("save success!  ->commit")
        else:
            QMessageBox.warning(None, "错误",  "请检查班级中名称,不能出现同名班级!")
            self.ClassnameModel.revertAll()
            self.ClassnameModel.database().rollback()

        # print(lstOldClassid)

        lstNewClassName = {}
        query.exec_("select rowid, classname from classtable where rowid in " + str(tuple(lstOldClassid)) )        
        while(query.next()):
            lstNewClassName[query.value(0)] = query.value(1)            

        # print(lstOldClassName, '=========')
        # print(lstNewClassName, '~~~~~~~~~')

        for i in lstOldClassName:
            oldclassname = lstOldClassName[i]
            newclassname = lstNewClassName[i]
            if oldclassname != newclassname:
                # print(oldclassname, newclassname, '++++++++')
                # print("update student set classname=" + newclassname + " where classname='" + oldclassname + "'")
                query.exec_("update student set classname='" + newclassname + "' where classname='" + oldclassname + "'")
                self.StudentModel.setFilter("classname = '" + newclassname + "'")
                self.StudentModel.select()

        lstClassName = []      
        query.exec_("select classname from classtable" ) 
        while(query.next()):
            lstClassName.append(query.value(0))
        self.StudentView.setItemDelegateForColumn(1,  ComboBoxDelegate(self, lstClassName, self.db))

    def dbclick(self, indx):
        if type(indx.sibling(indx.row(),0).data()) != QPyNullVariant:
            classname = indx.sibling(indx.row(),0).data()
            
            strwhere = "classname like '" + classname + "'"
            self.StudentModel.setFilter(strwhere)
            self.StudentModel.setSort(2, Qt.AscendingOrder)
            self.StudentModel.select()
            
            self.g_curClassName = classname
            self.tabWidget.setTabText(0, self.g_curClassName)

    def dbclick2(self, indx):
        if indx.column() == 2:
            self.StudentView.setEditTriggers(QAbstractItemView.NoEditTriggers)
        else:
            self.StudentView.setEditTriggers(QAbstractItemView.DoubleClicked)
        

    def genTwoTab(self, tabtitle=""):
        # Create the tab title sytle.
        tabtitle = QLabel()
        tabtitle.setFont(QFont('Courier New', 20))
        tabtitle.setText("班级学生信息管理")
        tabtitle.setStyleSheet("border: 1px solid blue; color:rgba(0,0,255, 220);\
            background-color:rgba(201,201,201,60);\
            border-radius: 6px; \
            padding: 1px 18px 1px 20px;\
            min-width: 8em;")
        tabtitle.setMinimumHeight(50);
        titleLayout = QHBoxLayout()
        titleLayout.addWidget(tabtitle)
        titleLayout.setAlignment(tabtitle, Qt.AlignCenter)

       
        # Create the classnameView
        self.ClassnameView = QTableView()
        self.ClassnameModel = QSqlTableModel(self.ClassnameView)
        self.ClassnameModel.setTable("classtable")
        # self.ClassnameModel.setRelation(2, QSqlRelation("mentalmodel", "id", "name"));
        self.ClassnameModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
        self.ClassnameModel.select()

        self.ClassnameModel.setHeaderData(0, Qt.Horizontal, "班级名称")

        # for indx, iheader in enumerate(["classid", "classname"]):
        #     self.ClassnameModel.setHeaderData(indx+1, Qt.Horizontal, iheader)
    
        self.ClassnameView.setModel(self.ClassnameModel)
        # self.ClassnameView.setColumnHidden(0, True)
        # self.ClassnameView.show()
        self.ClassnameView.verticalHeader().setFixedWidth(30)
        self.ClassnameView.verticalHeader().setStyleSheet("color: red;font-size:20px; ");
        self.ClassnameView.setStyleSheet("QTableView{background-color: rgb(250, 250, 200, 0);"  
                    "alternate-background-color: rgb(141, 163, 0);}"
                    "QTableView::item:hover {background-color: rgba(100,200,220,100);} ") 
        self.ClassnameView.setStyleSheet("font-size:16px; ");
        self.ClassnameView.setSelectionMode(QAbstractItemView.SingleSelection)
        # self.ClassnameView.dataChanged.connect(self.dataChanged)

        # self.ClassnameView.setSizePolicy(QSizePolicy.Expanding,     QSizePolicy.Expanding)

        # the second list
        self.StudentView = QTableView()
        self.StudentModel = QSqlTableModel(self.StudentView)
        self.StudentModel.setTable("student")
        # self.StudentModel.setRelation(2, QSqlRelation("mentalmodel", "id", "name"));
        self.StudentModel.setEditStrategy(QSqlTableModel.OnManualSubmit)
        # self.StudentModel.select()

        query = QSqlQuery(self.db)
        strwhere = " 1=1 "
        if self.g_curClassName == "":
            ret = query.exec_("select classname from classtable")
            query.next()
            firstClassName = query.value(0)
            strwhere += " and classname like '" + firstClassName + "'"
            
        self.StudentModel.setFilter(strwhere)
        self.StudentModel.select()

        for indx, iheader in enumerate(["班级名称", "学生编号", "学生姓名", "答对次数", "答错次数"]):
            self.StudentModel.setHeaderData(indx+1, Qt.Horizontal, iheader)
    
        self.StudentView.setModel(self.StudentModel)
        self.StudentView.setColumnHidden(0, True)

        # query = QSqlQuery(self.db)  
        lstClassName = []      
        query.exec_("select classname from classtable" ) 
        while(query.next()):
            lstClassName.append(query.value(0))

        self.StudentView.setItemDelegateForColumn(1,  ComboBoxDelegate(self, lstClassName, self.db))
        # self.StudentView.show()
        self.StudentView.verticalHeader().setFixedWidth(30)
        self.StudentView.verticalHeader().setStyleSheet("color: red;font-size:20px; background-color: rgb(250, 250, 200, 100)");
        self.StudentView.setStyleSheet("QTableView{background-color: rgb(250, 250, 200, 0);"  
                    "alternate-background-color: rgb(141, 163, 250);}"
                    "QTableView::item:hover {background-color: rgba(10,200,100,200);} "
                    ) 
        self.StudentView.setStyleSheet("font-size:16px;")
        self.StudentView.setSelectionMode(QAbstractItemView.SingleSelection)
        self.StudentView.doubleClicked.connect(self.dbclick2)

        btn_lst1_layout = QGridLayout()
        newusrbtn       = QPushButton("新增")
        savebtn         = QPushButton("保存")
        revertbtn       = QPushButton("撤销")
        removebtn       = QPushButton("删除")
        btn_lst1_layout.addWidget(newusrbtn, 0, 0)
        btn_lst1_layout.addWidget(savebtn, 0, 1)
        btn_lst1_layout.addWidget(revertbtn, 1, 0)
        btn_lst1_layout.addWidget(removebtn, 1, 1)

        newusrbtn.clicked.connect(self.newClass)
        savebtn.clicked.connect(self.saveClass)
        revertbtn.clicked.connect(self.revertClass)
        removebtn.clicked.connect(self.removeClass)

        self.ClassnameView.doubleClicked.connect(self.dbclick)
        

        btnbox2 = QDialogButtonBox(Qt.Horizontal)
        newusrbtn2       = QPushButton("新增")
        savebtn2         = QPushButton("保存")
        revertbtn2       = QPushButton("撤销")
        removebtn2       = QPushButton("删除")
        btnbox2.addButton(newusrbtn2, QDialogButtonBox.ActionRole);
        btnbox2.addButton(savebtn2, QDialogButtonBox.ActionRole);
        btnbox2.addButton(revertbtn2, QDialogButtonBox.ActionRole);
        btnbox2.addButton(removebtn2, QDialogButtonBox.ActionRole);

        newusrbtn2.clicked.connect(self.newStudent)
        savebtn2.clicked.connect(self.saveStudent)
        revertbtn2.clicked.connect(self.revertStudent)
        removebtn2.clicked.connect(self.removeStudent)

        # left list layout
        lst_layout_1 = QVBoxLayout()
        lst_layout_1.addWidget(self.ClassnameView)
        lst_layout_1.addLayout(btn_lst1_layout)

        lst_layout_2 = QVBoxLayout()
        lst_layout_2.addWidget(self.StudentView)
        lst_layout_2.addWidget(btnbox2)
        
        lstlayout = QHBoxLayout()
        lstlayout.setMargin(5)
        # lstlayout.addLayout(findbox)
        lstlayout.addLayout(lst_layout_1, 2)
        lstlayout.setMargin(5)
        lstlayout.addLayout(lst_layout_2, 5)
            
        labelClass = QLabel("")
        labelClass.setStyleSheet("background-color:rgba(255, 255, 255,0); color:rgba(0,0,0,0);")
        labelClass.setFixedHeight(40)
        # labelClass.setFixedWidth(100)
        # labelClass.setFont(QFont('宋体', 10))

        bottomlayout = QHBoxLayout()        
        bottomlayout.addWidget(labelClass)        

        tab2layout = QVBoxLayout()
        tab2layout.addLayout(titleLayout)       
        tab2layout.addLayout(lstlayout)
        tab2layout.addLayout(bottomlayout)
        self.w2.setLayout(tab2layout)
        self.w2.setStyleSheet("background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffffff, stop: 1 #228888);")
      
    def genOneTab(self):

        tabtitle = QLabel()
        # tabtitle.setFixedHeight(40)
        # tabtitle.setFixedWidth(160)        
        self.btn_start = MyButton("开始")
        self.choicenum_text = QComboBox()
        self.choicenum_text.setObjectName('w1combonums')
        # self.w1title.setStyleSheet("background-image:url('image/panelbg.jpg');")
        
        # Set the title style                
        tabtitle.setFont(QFont('Courier New', 20))
        tabtitle.setText("随堂提问演板")
        tabtitle.setStyleSheet("border: 1px solid blue; color:rgba(0,0,255, 220);\
            background-color:rgba(201,201,201,60);\
            border-radius: 6px; \
            padding: 1px 18px 1px 20px;\
            min-width: 8em;")
        tabtitle.setMinimumHeight(50);
        titleLayout = QHBoxLayout()
        titleLayout.addWidget(tabtitle)
        titleLayout.setAlignment(tabtitle, Qt.AlignCenter)
       
        btnlayout = QGridLayout()
        tmpnum = 0
        for inum in range(0,56):
            irow = tmpnum // g_cols
            icol = tmpnum % g_cols
            tmpnum += 1
            btnlayout.setRowMinimumHeight(irow, 80)
            tmpbtn = MyButton("")
            tmpbtn.setMyarg(None)
            # tmpbtn.setFixedHeight(20)
            tmpbtn.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding))
            tmpbtn.setStyleSheet("border: 1px solid rgb(55,55,255,100);background-color: rgba(255,255,255,20);font-size:16px;")
            self.connect(tmpbtn,  SIGNAL("myslot(PyQt_PyObject)"), self.myslot)
            tmpbtn.setAutoDefault(False)
            self.btngroup.addButton(tmpbtn, inum+1) # stusn is from 1 start

            btnlayout.addWidget(tmpbtn, irow, icol)


        self.btn_start.setIcon(QIcon("image/start.png"))
        self.btn_start.setStyleSheet("border: 1px solid yellow;")
        self.btn_start.setFixedHeight(40)
        self.btn_start.setFixedWidth(100)
        self.btn_start.setFont(QFont('宋体', 18))
        # self.choicenum_text.setFixedHeight(45)
        # self.choicenum_text.setFixedWidth(60)

        ## Set the combox number style
        self.choicenum_text.setFont(QFont('Courier New', 20))
        self.choicenum_text.setFixedHeight(45)
        self.choicenum_text.setStyleSheet("border: 2px solid blue; color:red;font-weight:light;font-size:26px;\
            border-radius: 6px; \
            min-width: 2em; ")
        self.choicenum_text.setEditable(True)
        self.choicenum_text.lineEdit().setReadOnly(True);
        self.choicenum_text.lineEdit().setAlignment(Qt.AlignCenter);

        model = self.choicenum_text.model()
        for row in list(range(1, 7)):
            item = QStandardItem(str(row))
            item.setTextAlignment(Qt.AlignCenter)
            item.setForeground(QColor('red'))
            item.setBackground(QColor(0,200,50, 130))
            model.appendRow(item)
        self.choicenum_text.setCurrentIndex(2)
        # self.choicenum_text.setStyleSheet ("QComboBox::drop-down {border-width: 100px;}")
        # self.choicenum_text.setStyleSheet ("QComboBox::down-arrow {image: url(image/downarrow.png);top: 10px;left: 1px;}")

        bottomlayout = QHBoxLayout()
        bottomlayout.setSizeConstraint(QLayout.SetFixedSize)
        bottomlayout.addStretch(10)
        bottomlayout.addWidget(self.btn_start)
        bottomlayout.setSpacing(5)
        bottomlayout.addWidget(self.choicenum_text)

        tab1layout = QVBoxLayout()
        tab1layout.addLayout(titleLayout)       
        tab1layout.addLayout(btnlayout)
        tab1layout.addLayout(bottomlayout)
                
        self.w1.setLayout(tab1layout)
        self.w1.setStyleSheet("background-color: QLinearGradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffffff, stop: 1 #228888);")
         
    def startChoice(self, usernum="", oldbtn=""): 
        # print(oldbtn, 1)

        if oldbtn == "":
            self.dict_choices = {}

        strwhere = " and classname like '" + self.g_curClassName + "'"

        allstudent = []
        lstrecord = []
        query = QSqlQuery(self.db)        
        query.exec_("select stusn from tmprecord where 1=1 " + strwhere) 
        while(query.next()):
            lstrecord.append(query.value(0))
        # print(lstrecord, 'record', "select stusn from student where stusn not in " + str(tuple(lstrecord)))

        query.exec_("select stusn from student where stusn not in " + str(tuple(lstrecord)) + strwhere)
        while(query.next()):
            allstudent.append(query.value(0))

        if usernum == "":
            nums = int(self.choicenum_text.currentText())
        else:
            nums = usernum
        if nums >= len(allstudent):
            query.exec_("delete from tmprecord where 1=1 " + strwhere) #delete tmp date no today            
            allstudent = []
            query.exec_("select stusn from student where 1=1 " + strwhere)
            while(query.next()):
                allstudent.append(query.value(0))
        
        if oldbtn == "":
            random.seed()
            lstchoices = random.sample(allstudent, nums)
            for ibtn in lstchoices:
                self.dict_choices[ibtn] = "111"

            self.group_animation.start()
            QTimer.singleShot(1200, self.stopmovie)
        else:
            random.seed()
            otherbtn = random.sample(allstudent, 1)[0]
            # self.btngroup.button(int(otherbtn)).setFocus()
            self.dict_choices.pop(oldbtn)
            self.dict_choices[otherbtn] = '111'
            self.stopmovie()
        self.btnSysMenu.setFocus()

    def stopmovie(self):
        self.group_animation.stop()
        for isn in self.studentSnlst:
            # print(isn)
            self.btngroup.button(int(isn[0])).setStyleSheet(stylesheetstr_old)
            self.btngroup.button(int(isn[0])).setIcon(QIcon())
        
        classname = self.tabWidget.tabText(0)
        query = QSqlQuery(self.db)        
        today = datetime.date.today()
        for ibtn in self.dict_choices:
            self.btngroup.button(int(ibtn)).setStyleSheet(stylesheetstr_new)
            query.exec_("select count(*) from tmprecord where stusn='" + str(ibtn) + "'")
            query.next()
            if query.value(0) == 0:               
                query.prepare("insert into tmprecord (classname, stusn, datequestion) values (:classname, :stusn, :datequestion)")
                query.bindValue(":classname", classname)
                query.bindValue(":stusn", ibtn)
                query.bindValue(":datequestion", today)
                query.exec_()
    
    def answerRight(self):
        # print(self.g_curbtn)
        value = self.g_curbtn
        if value not in self.dict_choices:
            return

        self.btngroup.button(int(value)).setIcon(QIcon("image/smile.png"))
        self.btngroup.button(int(value)).setIconSize(QSize(20,20))
        
        query = QSqlQuery(self.db)
        query.exec_("select rightquestions from student where stusn='" + value + "'")
        query.next()
        studentRightQuestions = query.value(0) + 1
        query.exec_("update student set rightquestions=" + str(studentRightQuestions) + " where stusn='" + value + "'")
                
        ###########
        if self.dict_choices[value] == "101":
            query.exec_("select wrongquestions from student where stusn='" + value + "'")
            query.next()
            studentWrongQuestions = query.value(0) - 1
            query.exec_("update student set wrongquestions=" + str(studentWrongQuestions) + " where stusn='" + value + "'")
            
        self.dict_choices[value] = "011"

    def answerWrong(self):
        value = self.g_curbtn
        if value not in self.dict_choices:
            return

        self.btngroup.button(int(value)).setIcon(QIcon("image/cry.png"))
        self.btngroup.button(int(value)).setIconSize(QSize(20,20))
        # self.btngroup.button(int(value)).setStyleSheet("border-image: url(image/ex_stu.png);")
        
        query = QSqlQuery(self.db)
        query.exec_("select wrongquestions from student where stusn='" + value + "'")
        query.next()
        studentWrongQuestions = query.value(0) + 1
        query.exec_("update student set wrongquestions=" + str(studentWrongQuestions) + " where stusn='" + value + "'")
        
        if self.dict_choices[value] == "011":
            query.exec_("select rightquestions from student where stusn='" + value + "'")
            query.next()
            studentRightQuestions = query.value(0) - 1
            query.exec_("update student set rightquestions=" + str(studentRightQuestions) + " where stusn='" + value + "'")
            
        self.dict_choices[value] = "101"

    def resetStudent(self):
        value = self.g_curbtn
        if value not in self.dict_choices:
            return

        query = QSqlQuery(self.db)

        if self.dict_choices[value] == "011":        
            query.exec_("select rightquestions from student where stusn='" + value + "'")
            query.next()
            studentRightQuestions = query.value(0) - 1
            query.exec_("update student set rightquestions=" + str(studentRightQuestions) + " where stusn='" + value + "'")

        if self.dict_choices[value] == "101":
            query.exec_("select wrongquestions from student where stusn='" + value + "'")
            query.next()
            studentWrongQuestions = query.value(0) - 1
            query.exec_("update student set wrongquestions=" + str(studentWrongQuestions) + " where stusn='" + value + "'")
            
        self.startChoice(usernum=1, oldbtn=value)
        # print("---reset___")

        # curmenu.actions()[0].setEnabled(True)
        # curmenu.actions()[1].setEnabled(True)
        # self.choiceOneStudent(value)

    def createDb(self):
        conn = sqlite3.connect("studentNew.db") 
        cur = conn.cursor()
        sqlstr = 'create table student (id integer primary key, \
            classname varchar(20), \
            stusn varchar(20), \
            stuname varchar(20), \
            rightquestions integer, \
            wrongquestions integer, \
            FOREIGN KEY(classname) REFERENCES classtable(classname))'
        # print(sqlstr)

        sqlstr2 = 'create table tmprecord (id integer primary key, \
            classname varchar(20), \
            stusn varchar(20), \
            datequestion date)'

        sqlstr3 = 'create table classtable (classname varchar(20) PRIMARY KEY)'
        
        cur.execute(sqlstr3)
        conn.commit()
        cur.execute(sqlstr2)
        conn.commit()
        cur.execute(sqlstr)
        conn.commit()

        strdelete = "delete from student where 1=1"
        cur.execute(strdelete)
        conn.commit()
        strdelete = "delete from tmprecord where 1=1"
        cur.execute(strdelete)
        conn.commit()
        # print(sqlstr2)

        # cur.execute(sqlstr) 
        # conn.commit()
        # cur.execute(sqlstr2) 
        # conn.commit()

        # insert example data
        strsql = "insert into classtable values (?)"
        cur.execute(strsql, ("三(3)班",))
        conn.commit()
        cur.execute(strsql, ("三(4)班",))
        conn.commit()


        a03lst = ["曾忆谊","赵佳泉","翁文秀","林珑","郑铭洁","林泽思","吴崇霖","陈思嘉","欧阳月孜","郭展羽","詹伟哲","黄佳仪","杨秋霞","周奕子","林楚杰","欧伊涵","许腾誉","陈唯凯","陈树凯","林彦君","张钰佳","高锴","杨博凯","林妙菲","林楚鸿","陈展烯","姚静茵","吴欣桐","范思杰","肖佳","马思广","许一帆","姚奕帆","陈海珣","吴黛莹","吴育桐","肖凯帆","林欣阳","叶茂霖","姚楷臻","陈嘉豪","陈琦","杨子楷","陈炎宏","陈幸仪","杨景畅","罗暖婷","郑馨"]
        a04lst = ["罗恩琪","王可","曾祥威","谢濡婷","温嘉凯","许洁仪","肖欣淇","陈凯佳","林天倩","李乐海","吴文慧","黄文婷","万誉","陈进盛","张裕涵","陈振嘉","王巧玲","林珮琪","陈炜楷","杨健","赵泽锴","张凤临","蔡子丹","陈烨杰","廖妍希","林树超","夏培轩","陈锦森","李星","蔡依婷","姚容创","姚凯扬","沈嘉克","周凡","张玉川","邱金迅","陈菲敏","陈星翰","朱煜楷","郑泽洪","钱剑非","罗奕丰","陈杜炜","林知钦"]
        strsql = "insert into student values (?, ?, ?, ?,?,?)" 
        for i in list(range(0,len(a03lst))):
            cur.execute(strsql, (None, "三(3)班", str(i+1).zfill(2), a03lst[i], 0, 0))
            conn.commit()
        strsql = "insert into student values (?, ?, ?, ?,?,?)" 
        for i in list(range(0,len(a04lst))):
            cur.execute(strsql, (None, "三(4)班", str(i+1).zfill(2), a04lst[i], 0, 0))
            conn.commit()
        cur.close()
Exemplo n.º 8
0
class RecordingWidget(QWidgetWithDpi):
    """Widget containing main recording UI for Freeseer"""

    def __init__(self, parent=None):
        super(RecordingWidget, self).__init__(parent)

        icon = QIcon()
        icon.addPixmap(QPixmap(":/freeseer/logo.png"), QIcon.Normal, QIcon.Off)
        self.setWindowIcon(icon)
        self.resize(400, 400)

        self.mainLayout = QVBoxLayout()
        self.setLayout(self.mainLayout)

        self.setStyleSheet("""
            QToolButton {
                background-color: #D1D1D1;
                border-style: solid;
                border-width: 1px;
                border-radius: 10px;
                border-color: #969696;
                padding: 6px;
            }

            QToolButton:pressed {
                background-color: #A3A2A2;
                border-width: 2px;
                border-color: #707070;
            }

            QToolButton:checked {
                background-color: #A3A2A2;
                border-width: 2px;
                border-color: #707070;
            }

            QToolButton:disabled {
                background-color: #EDEDED;
                border-color: #BFBDBD;
            }

            QToolButton:hover {
                border-width: 2px;
            }
        """)

        boldFont = QFont()
        boldFont.setBold(True)

        fontSize = self.font().pixelSize()
        fontUnit = "px"
        if fontSize == -1:  # Font is set as points, not pixels.
            fontUnit = "pt"
            fontSize = self.font().pointSize()

        # Control bar
        self.controlRow = QHBoxLayout()
        self.mainLayout.addLayout(self.controlRow)

        self.recordIcon = QIcon(":/multimedia/record.png")
        self.stopIcon = QIcon(":/multimedia/stop.png")
        pauseIcon = QIcon(":/multimedia/pause.png")
        playIcon = QIcon(":/multimedia/play.png")
        self.headphoneIcon = QIcon()
        self.headphoneIcon.addPixmap(QPixmap(":/multimedia/headphones.png"), QIcon.Normal, QIcon.Off)

        self.is_recording = False
        self.recordButton = QToolButtonWithDpi()
        self.recordButton.setToolTip("Record")
        self.recordButton.setFixedSize(QSize(60, 40))
        self.recordButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.recordButton.setIcon(self.recordIcon)
        self.recordButton.setEnabled(False)
        self.recordButton.setObjectName("recordButton")
        self.controlRow.addWidget(self.recordButton, 0, Qt.AlignLeft)
        self.connect(self.recordButton, SIGNAL("clicked()"), self.setRecordIcon)

        self.playButton = QToolButtonWithDpi()
        self.playButton.setToolTip("Play last recorded Video")
        self.playButton.setFixedSize(QSize(60, 40))
        self.playButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.playButton.setIcon(playIcon)
        self.playButton.setEnabled(False)
        self.controlRow.addWidget(self.playButton, 0, Qt.AlignLeft)

        self.pauseButton = QToolButtonWithDpi()
        self.pauseButton.setToolTip("Pause")
        self.pauseButton.setIcon(pauseIcon)
        self.pauseButton.setFixedSize(QSize(60, 40))
        self.pauseButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.pauseButton.setEnabled(False)
        self.pauseButton.setCheckable(True)
        self.controlRow.addWidget(self.pauseButton, 0, Qt.AlignLeft)

        self.controlRow.addSpacerItem(self.qspacer_item_with_dpi(30, 40))
        self.controlRow.addStretch(1)

        self.standbyButton = QPushButtonWithDpi("Standby")
        self.standbyButton.setStyleSheet("""
            QPushButton {{
                color: white;
                background-color: #47a447;
                border-style: solid;
                border-width: 0px;
                border-radius: 10px;
                border-color: #398439;
                font: bold {}{};
                padding: 6px;
            }}

            QPushButton:pressed {{
                background-color: #3E8A3E;
                border-color: #327532;
            }}

            QPushButton:hover {{
                border-width: 2px;
            }}
        """.format(fontSize + 3, fontUnit))
        self.standbyButton.setToolTip("Standby")
        self.standbyButton.setFixedSize(QSize(180, 40))
        self.standbyButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.standbyButton.setCheckable(True)
        self.standbyButton.setObjectName("standbyButton")
        self.controlRow.addWidget(self.standbyButton)

        self.disengageButton = QPushButtonWithDpi("Leave record-mode")
        self.disengageButton.setStyleSheet("""
            QPushButton {{
                color: white;
                background-color: #D14343;
                border-style: solid;
                border-width: 0px;
                border-radius: 10px;
                border-color: #B02C2C;
                font: bold {}{};
                padding: 6px;
            }}

            QPushButton:pressed {{
                background-color: #AD2B2B;
                border-color: #8C2929;
            }}

            QPushButton:hover {{
                border-width: 2px;
            }}

            QPushButton:disabled {{
                background-color: #B89E9E;
        }}
        """.format(fontSize + 3, fontUnit))
        self.disengageButton.setToolTip("Leave record-mode")
        self.disengageButton.setFixedSize(QSize(180, 40))
        self.disengageButton.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.disengageButton.setHidden(True)
        self.disengageButton.setObjectName("disengageButton")
        self.controlRow.addWidget(self.disengageButton)

        # Filter bar
        self.filterBarLayout = QVBoxLayout()
        self.mainLayout.addLayout(self.filterBarLayout)

        self.filterBarLayoutRow_1 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_1)
        self.eventLabel = QLabel("Event")
        self.eventLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.eventComboBox = QComboBox()
        self.eventLabel.setBuddy(self.eventComboBox)
        self.roomLabel = QLabel("Room")
        self.roomLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.roomComboBox = QComboBox()
        self.roomLabel.setBuddy(self.roomComboBox)
        self.dateLabel = QLabel("Date")
        self.dateLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.dateComboBox = QComboBox()
        self.dateLabel.setBuddy(self.dateComboBox)
        self.filterBarLayoutRow_1.addWidget(self.eventLabel)
        self.filterBarLayoutRow_1.addWidget(self.eventComboBox)
        self.filterBarLayoutRow_1.addWidget(self.roomLabel)
        self.filterBarLayoutRow_1.addWidget(self.roomComboBox)
        self.filterBarLayoutRow_1.addWidget(self.dateLabel)
        self.filterBarLayoutRow_1.addWidget(self.dateComboBox)

        self.filterBarLayoutRow_2 = QHBoxLayout()
        self.filterBarLayout.addLayout(self.filterBarLayoutRow_2)
        self.talkLabel = QLabel("Talk ")
        self.talkLabel.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed)
        self.talkComboBox = QComboBox()
        self.talkComboBox.setFont(boldFont)
        self.talkComboBox.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)
        self.talkComboBox.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength)
        self.filterBarLayoutRow_2.addWidget(self.talkLabel)
        self.filterBarLayoutRow_2.addWidget(self.talkComboBox)

        # Preview Layout
        self.previewLayout = QHBoxLayout()
        self.mainLayout.addLayout(self.previewLayout)

        self.previewWidget = QWidget()
        self.audioSlider = QSlider()
        self.audioSlider.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
        self.audioSlider.setEnabled(False)
        self.previewLayout.addWidget(self.previewWidget)
        self.previewLayout.addWidget(self.audioSlider)

        self.statusLabel = QLabel()
        self.mainLayout.addWidget(self.statusLabel)

        # Audio Feedback Checkbox
        self.audioFeedbackCheckbox = QCheckBox()
        self.audioFeedbackCheckbox.setLayoutDirection(Qt.RightToLeft)
        self.audioFeedbackCheckbox.setIcon(self.headphoneIcon)
        self.audioFeedbackCheckbox.setToolTip("Enable Audio Feedback")
        self.mainLayout.addWidget(self.audioFeedbackCheckbox)

    def setRecordIcon(self):
        self.is_recording = not self.is_recording
        if self.is_recording:
            self.recordButton.setIcon(self.stopIcon)
        else:
            self.recordButton.setIcon(self.recordIcon)
Exemplo n.º 9
0
class OCAHPanel(QFrame):
    def __init__(self, parent):
        QFrame.__init__(self, parent)
        while not isinstance(parent, QDialog):
            parent = parent.parent()
        self.setObjectName("OCAHPanel" + str(len(parent.findChildren(OCAHPanel))))

#         self.frame_WindIA = QFrame(parent)
        sizePolicy = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
        self.setSizePolicy(sizePolicy)
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Raised)
        self.setObjectName(("frame_WindIA"))
        self.hLayout = QHBoxLayout(self)
        self.hLayout.setSpacing(0)
        self.hLayout.setMargin(0)
        self.hLayout.setObjectName(("hLayout"))

        self.basicFrame = Frame(self, "HL")
        self.basicFrame.layoutBoxPanel.setSpacing(0)
        # self.basicFrame.layoutBoxPanel.setMargin(0)
        self.hLayout.addWidget(self.basicFrame)

        self.lblIA = QLabel(self.basicFrame)
        self.lblIA.setMinimumSize(QSize(200, 0))
        self.lblIA.setMaximumSize(QSize(200, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.lblIA.setFont(font)
        self.lblIA.setObjectName(("lblIA"))
        self.basicFrame.Add = self.lblIA
        self.cmbType = QComboBox(self.basicFrame)
        self.cmbType.setMinimumSize(QSize(70, 0))
        self.cmbType.setMaximumWidth(70)
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.cmbType.setFont(font)
        self.cmbType.setObjectName(("cmbType"))
        self.basicFrame.Add = self.cmbType



        self.txtAltitudeM = QLineEdit(self.basicFrame)
        self.txtAltitudeM.setEnabled(True)
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.txtAltitudeM.setFont(font)
        self.txtAltitudeM.setObjectName(self.objectName() + "_txtAltitudeM")
        self.txtAltitudeM.setText("0.0")
        self.txtAltitudeM.setMinimumWidth(70)
        self.txtAltitudeM.setMaximumWidth(70)
        self.basicFrame.Add = self.txtAltitudeM

        labelM = QLabel(self.basicFrame)
        labelM.setObjectName(("labelM"))
        labelM.setText(" m ")
        self.basicFrame.Add = labelM

        self.txtAltitude = QLineEdit(self.basicFrame)
        sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.txtAltitude.sizePolicy().hasHeightForWidth())
        self.txtAltitude.setSizePolicy(sizePolicy)
        self.txtAltitude.setMinimumSize(QSize(70, 0))
        self.txtAltitude.setMaximumSize(QSize(70, 16777215))
        font = QFont()
        font.setFamily(("Arial"))
        font.setBold(False)
        font.setWeight(50)
        self.txtAltitude.setFont(font)
        self.txtAltitude.setObjectName(self.objectName() + "_txtAltitude")
        self.basicFrame.Add = self.txtAltitude

        labelFt = QLabel(self.basicFrame)
        labelFt.setObjectName(("labelFt"))
        labelFt.setText(" ft")
        self.basicFrame.Add = labelFt

        spacerItem = QSpacerItem(10,10,QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.hLayout.addItem(spacerItem)
        
        self.altitude = Altitude.NaN()
        self.customValue = Speed(30).Knots
        self.cmbType.addItems(["OCA", "OCH"])
        # self.cmbType.currentIndexChanged.connect(self.changeType)
        self.cmbType.setCurrentIndex(0)
        self.lblIA.setText("Intermediate Segment Minimum:")
        # self.txtAltitude.setEnabled(False)
        self.txtAltitudeM.textChanged.connect(self.txtAltitudeMChanged)
        self.txtAltitude.textChanged.connect(self.txtAltitudeChanged)
        
        self.captionUnits = "ft"

        self.flag = 0
        self.txtAltitudeM.setText("0.0")
        self.txtAltitude.setText("0.0")
    def txtAltitudeChanged(self):
        try:
            test = float(self.txtAltitude.text())
            if self.flag==0:
                self.flag=1;
            if self.flag==2:
                self.flag=0;
            if self.flag==1:
                try:
                    self.txtAltitudeM.setText(str(round(Unit.ConvertFeetToMeter(float(self.txtAltitude.text())), 4)))
                except:
                    self.txtAltitudeM.setText("0.0")
                self.emit(SIGNAL("Event_0"), self)
        except:
            str0 = "You must input the float type in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitudeM.setText("0.0")
            self.txtAltitude.setText("0.0")


    def txtAltitudeMChanged(self):
        try:
            test = float(self.txtAltitudeM.text())
            if self.flag==0:
                self.flag=2;
            if self.flag==1:
                self.flag=0;
            if self.flag==2:
                try:
                    self.txtAltitude.setText(str(round(Unit.ConvertMeterToFeet(float(self.txtAltitudeM.text())), 4)))
                except:
                    self.txtAltitude.setText("0.0")
                self.emit(SIGNAL("Event_0"), self)
        except:
            str0 = "You must input the float type in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitude.setText("0.0")
            self.txtAltitudeM.setText("0.0")

        try:
            self.altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            self.altitude = Altitude.NaN()
    # def txtAltitudeChanged(self):
    #     try:
    #         self.altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
    #     except:
    #         self.altitude = Altitude.NaN()
    # def setAltitude(self, value):
    #     self.altitude = value

#     def getValue(self, SpeedUnits_0 = SpeedUnits.KTS):    
#         return Speed(float(self.txtAltitude.text()), SpeedUnits_0)
    def method_2(self, altitude_0):
        altitude = Altitude(0)
        try:
            altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            altitude = Altitude(0)
        if (self.cmbType.currentIndex() == 0):
            return altitude
        return Altitude(altitude.Feet + altitude_0.Feet, AltitudeUnits.FT);

    def method_3(self, altitude_0):
        altitude = Altitude(0)
        try:
            altitude = Altitude(float(self.txtAltitude.text()), AltitudeUnits.FT)
        except:
            altitude = Altitude(0)
        if (self.cmbType.currentIndex() != 0):
            return altitude
        return Altitude(altitude.Feet - altitude_0.Feet, AltitudeUnits.FT);


    
    def changeType(self):
        pass
        
    # def get_altitude(self):
    #     return self.altitude
    # Value = property(get_altitude, setAltitude, None, None)

    def get_isEmpty(self):
        try:
            num = float(self.txtAltitude.text())
            return False
        except:
            return True
    IsEmpty = property(get_isEmpty, None, None, None)
    
    def get_CaptionUnits(self):
        return self.captionUnits
    def set_CaptionUnits(self, captionUnits):
        self.captionUnits = captionUnits
    CaptionUnits = property(get_CaptionUnits, set_CaptionUnits, None, None)

    def get_Caption(self):
        caption = self.lblIA.text()
        val = caption.left(caption.length() - 1)
        return val
    def set_Caption(self, captionStr):
        self.lblIA.setText(captionStr + ":")
    Caption = property(get_Caption, set_Caption, None, None)



    def get_Value(self):
        try:
            return Altitude(float(self.txtAltitudeM.text()))
        except:
            return Altitude(0.0)

    def set_Value(self, altitude):
        if isinstance(altitude, Altitude):
            if self.captionUnits == "m":
                self.txtAltitudeM.setText(str(altitude.Metres))
            else:
                self.txtAltitude.setText(str(altitude.Feet))
        else:
            str0 = "You must input the type \"Altitude\" in \"%s\"."%(self.Caption)
            QMessageBox.warning(self, "Warning" , str0)
            self.txtAltitudeM.setText("0.0")
    Value = property(get_Value, set_Value, None, None)

    

    def set_LabelWidth(self, width):
        self.lblIA.setMinimumSize(QSize(width, 0))
        self.lblIA.setMaximumSize(QSize(width, 16777215))
    LabelWidth = property(None, set_LabelWidth, None, None)

    def get_ReadOnly(self):
        return self.txtAltitudeM.isReadOnly()
    def set_ReadOnly(self, bool):
        self.txtAltitudeM.setReadOnly(bool)
        self.txtAltitude.setReadOnly(bool)
    ReadOnly = property(get_ReadOnly, set_ReadOnly, None, None)

    def get_Enabled(self):
        return self.txtAltitudeM.isEnabled()
    def set_Enabled(self, bool):
        self.txtAltitudeM.setEnabled(bool)
        self.txtAltitude.setEnabled(bool)
    Enabled = property(get_Enabled, set_Enabled, None, None)
Exemplo n.º 10
0
class ComboBoxPanel(QWidget):
    def __init__(self, parent, editable=False, spacerItemMove=False):
        QWidget.__init__(self, parent)
        while not isinstance(parent, QDialog):
            parent = parent.parent()
        self.setObjectName("ComboBoxPanel" +
                           str(len(parent.findChildren(ComboBoxPanel))))

        self.hLayoutBoxPanel = QHBoxLayout(self)
        self.hLayoutBoxPanel.setSpacing(0)
        self.hLayoutBoxPanel.setContentsMargins(0, 0, 0, 0)
        self.hLayoutBoxPanel.setObjectName(("hLayoutBoxPanel"))
        self.frameBoxPanel = QFrame(self)
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.frameBoxPanel.sizePolicy().hasHeightForWidth())
        self.frameBoxPanel.setSizePolicy(sizePolicy)
        self.frameBoxPanel.setFrameShape(QFrame.NoFrame)
        self.frameBoxPanel.setFrameShadow(QFrame.Raised)
        self.frameBoxPanel.setObjectName(("frameBoxPanel"))
        self.hLayoutframeBoxPanel = QHBoxLayout(self.frameBoxPanel)
        self.hLayoutframeBoxPanel.setSpacing(0)
        self.hLayoutframeBoxPanel.setMargin(0)
        self.hLayoutframeBoxPanel.setObjectName(("hLayoutframeBoxPanel"))
        self.captionLabel = QLabel(self.frameBoxPanel)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.captionLabel.sizePolicy().hasHeightForWidth())
        self.captionLabel.setSizePolicy(sizePolicy)
        self.captionLabel.setMinimumSize(QSize(200, 0))
        self.captionLabel.setMaximumSize(QSize(200, 16777215))
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.captionLabel.setFont(font)
        self.captionLabel.setObjectName(("captionLabel"))
        self.hLayoutframeBoxPanel.addWidget(self.captionLabel)

        self.comboBox = QComboBox(self.frameBoxPanel)
        self.comboBox.setEnabled(True)
        font = QFont()
        font.setBold(False)
        font.setWeight(50)
        self.comboBox.setFont(font)
        self.comboBox.setObjectName(self.objectName() + "_comboBox")
        self.comboBox.setMinimumWidth(70)
        # self.comboBox.setMaximumWidth(70)

        # self.hLayoutframeBoxPanel.addWidget(self.lineEdit)
        self.hLayoutframeBoxPanel.addWidget(self.comboBox)

        self.imageButton = QToolButton(self.frameBoxPanel)
        self.imageButton.setText((""))
        icon = QIcon()
        icon.addPixmap(QPixmap(("Resource/convex_hull.png")), QIcon.Normal,
                       QIcon.Off)
        self.imageButton.setIcon(icon)
        self.imageButton.setObjectName(("imageButton"))
        self.imageButton.setVisible(False)
        self.hLayoutframeBoxPanel.addWidget(self.imageButton)

        self.hLayoutBoxPanel.addWidget(self.frameBoxPanel)
        if not spacerItemMove:
            spacerItem = QSpacerItem(10, 10, QSizePolicy.Expanding,
                                     QSizePolicy.Minimum)
            self.hLayoutBoxPanel.addItem(spacerItem)

        self.comboBox.currentIndexChanged.connect(self.comboBoxChanged)
        # self.comboBox.editTextChanged.connect(self.comboBoxEditTextChanged)
        self.imageButton.clicked.connect(self.imageButtonClicked)

        self.captionUnits = ""

        self.hasObject = False

        self.objectList = []
        if editable == True:
            self.lineEdit = QLineEdit(self.frameBoxPanel)
            self.lineEdit.setObjectName("lineEdit")
            self.hLayoutframeBoxPanel.insertWidget(1, self.lineEdit)
            self.comboBox.setLineEdit(self.lineEdit)
            self.lineEdit.returnPressed.connect(self.comboBoxEditTextChanged)

    def FindString(self, string):
        return self.comboBox.findText(string)

    def comboBoxEditTextChanged(self):
        self.comboBox.showPopup()

    def get_Count(self):
        return self.comboBox.count()

    Count = property(get_Count, None, None, None)

    def method_0(self):
        return self.comboBox.currentIndex(
        ) >= 0 and self.SelectedItem != None and self.SelectedItem != ""

    def method_3(self, string_0):
        return self.comboBox.findText(string_0)

    def method_11(self, string_0):
        if (self.IsEmpty):
            return "%s%s\t" % (string_0, self.Caption)
        return "%s%s\t%s %s" % (string_0, self.Caption, self.Value,
                                self.CaptionUnits)

    def comboBoxChanged(self):
        self.emit(SIGNAL("Event_0"), self)

    def IndexOf(self, item):
        if isinstance(item, str) or isinstance(item, QString):
            return self.comboBox.findText(item)
        else:
            return self.comboBox.findText(item.ToString())

    def Contains(self, item):
        compStr = None
        if isinstance(item, str):
            compStr = item
        elif isinstance(item, float) or isinstance(item, int):
            compStr = str(item)
        else:
            compStr = item.ToString()
        for i in range(self.comboBox.count()):
            comboItemstr = self.comboBox.itemText(i)
            if compStr == comboItemstr:
                return True
        return False

    def Clear(self):
        self.comboBox.clear()
        self.objectList = []
        self.hasObject = False

    def Add(self, item):
        if not isinstance(item, str) and not isinstance(item, QString):
            self.comboBox.addItem(item.ToString())
            self.objectList.append(item)
            self.hasObject = True
            return
        self.comboBox.addItem(item)
        self.hasObject = False

    def Insert(self, index, item):
        if not isinstance(item, str) and not isinstance(item, QString):
            self.comboBox.insertItem(index, item.ToString())
            self.objectList.insert(index, item)
            self.hasObject = True
            return
        self.comboBox.insertItem(index, item)
        self.hasObject = False

    def imageButtonClicked(self):
        self.emit(SIGNAL("Event_3"), self)

    def get_Caption(self):
        caption = self.captionLabel.text()
        findIndex = caption.indexOf("(")
        if findIndex > 0:
            val = caption.left(findIndex)
            return val
        return caption

    def set_Caption(self, captionStr):
        if captionStr == "":
            self.captionLabel.setText("")
            self.LabelWidth = 0
            return
        if self.CaptionUnits != "" and self.CaptionUnits != None:
            self.captionLabel.setText(captionStr + "(" +
                                      QString(self.CaptionUnits) + ")" + ":")
        else:
            self.captionLabel.setText(captionStr + ":")

    Caption = property(get_Caption, set_Caption, None, None)

    def get_CaptionUnits(self):
        return self.captionUnits

    def set_CaptionUnits(self, captionUnits):
        self.captionUnits = captionUnits

    CaptionUnits = property(get_CaptionUnits, set_CaptionUnits, None, None)

    def set_ButtonVisible(self, bool):
        self.imageButton.setVisible(bool)

    ButtonVisible = property(None, set_ButtonVisible, None, None)

    # def get_Value(self):
    #     return self.comboBox.currentIndex()

    # def set_Value(self, value):
    #     try:
    #         self.comboBox.setCurrentIndex(value)
    #     except:
    #         self.textBox.setText("")
    # Value = property(get_Value, set_Value, None, None)

    def get_IsEmpty(self):
        return self.comboBox.currentText() == "" or self.comboBox.currentIndex(
        ) == -1

    IsEmpty = property(get_IsEmpty, None, None, None)

    def get_ReadOnly(self):
        return self.textBox.isReadOnly()

    # def set_ReadOnly(self, bool):
    #     self.comboBox.setR.setReadOnly(bool)
    # ReadOnly = property(get_ReadOnly, set_ReadOnly, None, None)

    def set_LabelWidth(self, width):
        self.captionLabel.setMinimumSize(QSize(width, 0))
        self.captionLabel.setMaximumSize(QSize(width, 16777215))

    LabelWidth = property(None, set_LabelWidth, None, None)

    def set_Width(self, width):
        self.comboBox.setMinimumSize(QSize(width, 0))
        self.comboBox.setMaximumSize(QSize(width, 16777215))

    Width = property(None, set_Width, None, None)

    def set_Button(self, imageName):
        if imageName == None or imageName == "":
            self.imageButton.setVisible(False)
            return
        icon = QIcon()
        icon.addPixmap(QPixmap(("Resource/" + imageName)), QIcon.Normal,
                       QIcon.Off)
        self.imageButton.setIcon(icon)
        self.imageButton.setVisible(True)

    Button = property(None, set_Button, None, None)

    def get_SelectedIndex(self):
        return self.comboBox.currentIndex()

    def set_SelectedIndex(self, index):
        if self.comboBox.count() == 0:
            return
        if index > self.comboBox.count() - 1:
            self.comboBox.setCurrentIndex(0)
        else:
            self.comboBox.setCurrentIndex(index)

    SelectedIndex = property(get_SelectedIndex, set_SelectedIndex, None, None)

    def get_Value(self):
        return self.comboBox.currentIndex()

    def set_Value(self, valueStr):
        if self.comboBox.count() == 0:
            return
        if valueStr == None:
            self.SelectedIndex = -1
            return
        self.comboBox.setCurrentIndex(self.comboBox.findText(str(valueStr)))

    Value = property(get_Value, set_Value, None, None)

    def get_Items(self):
        # if self.hasObject:
        #     return self.objectList
        itemList = []
        if self.comboBox.count() > 0:
            for i in range(self.comboBox.count()):
                itemList.append(self.comboBox.itemText(i))
        return itemList

    def set_AddItems(self, strList):
        self.Clear()
        if len(strList) != 0 and (not isinstance(strList[0], str)
                                  and not isinstance(strList[0], QString)):
            for obj in strList:
                self.comboBox.addItem(obj.ToString())
                self.objectList.append(obj)
            self.hasObject = True
            return
        self.comboBox.addItems(strList)

    Items = property(get_Items, set_AddItems, None, None)

    def get_Enabled(self):
        return self.comboBox.isEnabled()

    def set_Enabled(self, bool):
        self.comboBox.setEnabled(bool)

    Enabled = property(get_Enabled, set_Enabled, None, None)

    def get_Visible(self):
        return self.isVisible()

    def set_Visible(self, bool):
        self.setVisible(bool)

    Visible = property(get_Visible, set_Visible, None, None)

    def get_Editable(self):
        return self.comboBox.isEditable()

    def set_Editable(self, bool):
        self.comboBox.setEditable(bool)

    Editable = property(get_Editable, set_Editable, None, None)

    def get_SelectedItem(self):
        if self.comboBox.count() == 0:
            return None
        if self.hasObject:
            return self.objectList[self.SelectedIndex]
        return self.comboBox.currentText()

    def set_SelectedItem(self, val):
        index = self.comboBox.findText(val)
        self.comboBox.setCurrentIndex(index)

    SelectedItem = property(get_SelectedItem, set_SelectedItem, None, None)