示例#1
0
class TaskTableElem:
    def __init__(self, id, status, task_name):
        self.id = id
        self.status = status
        self.progress = 0.0
        self.id_item = None
        self.progress_bar = None
        self.progressBarInBoxLayoutWidget = None
        self.status_item = None
        self.task_name = task_name
        self.name_item = None
        self.timer_item = None
        self.cost_item = None
        self.__build_row()

    def __build_row(self):
        self.name_item = QTableWidgetItem()
        self.name_item.setText(self.task_name)

        self.id_item = QTableWidgetItem()
        self.id_item.setText(self.id)

        self.progress_bar = QProgressBar()
        self.progress_bar.geometry().setHeight(20)
        self.progress_bar.setProperty("value", 50)

        self.progressBarInBoxLayoutWidget = QWidget()
        box_layout = QVBoxLayout()
        #box_layout.setMargin(3)
        box_layout.addWidget(self.progress_bar)

        self.progressBarInBoxLayoutWidget.setLayout(box_layout)

        self.status_item = QTableWidgetItem()
        self.status_item.setText(self.status)

        self.timer_item = QTableWidgetItem()
        self.timer_item.setText("00:00:00")

        self.cost_item = QTableWidgetItem()
        self.cost_item.setText("0.000000")

    def setProgress(self, val):
        if 0.0 <= val <= 1.0:
            self.progress = val
        else:
            raise ValueError("Wrong progress setting {}".format(val))

    def get_column_item(self, col):
        if col == 0:
            return self.name_item
        if col == 1:
            return self.id_item
        if col == 2:
            return self.status_item
        if col == 3:
            return self.timer_item
        if col == 4:
            return self.cost_item

        raise ValueError("Wrong column index {}".format(col))
示例#2
0
class SubtaskTableElem:
    def __init__(self, node_name, subtask_id, status):
        self.node_name = node_name
        self.node_name_item = None
        self.subtask_id = subtask_id
        self.subtask_id_item = None
        self.status = status
        self.remaining_time = 0
        self.remaining_timeItem = None
        self.progress = 0.0
        self.node_name_item = None
        self.progress_bar = None
        self.progressBarInBoxLayoutWidget = None
        self.subtask_status_item = None
        self.__build_row()

    def __build_row(self):

        self.node_name_item = QTableWidgetItem()
        self.node_name_item.setText(self.node_name)

        self.subtask_id_item = QTableWidgetItem()
        self.subtask_id_item.setText(self.subtask_id)

        self.remaining_timeItem = QTableWidgetItem()

        self.subtask_status_item = QTableWidgetItem()

        self.progress_bar = QProgressBar()
        self.progress_bar.geometry().setHeight(20)
        self.progress_bar.setProperty("value", 50)

        self.progressBarInBoxLayoutWidget = QWidget()
        boxLayout = QVBoxLayout()
        #boxLayout.setMargin(3)
        boxLayout.addWidget(self.progress_bar)

        self.progressBarInBoxLayoutWidget.setLayout(boxLayout)

    def update(self, progress, status, remTime):
        self.setProgress(progress)
        self.setRemainingTime(remTime)
        self.setStatus(status)

    def setProgress(self, val):
        if 0.0 <= val <= 1.0:
            self.progress = val
            self.progress_bar.setProperty("value", int(val * 100))
        else:
            raise ValueError("Wrong progress setting {}".format(val))

    def setStatus(self, status):
        self.status = status
        self.subtask_status_item.setText(status)

    def setRemainingTime(self, time):
        self.remaining_time = time
        self.remaining_timeItem.setText(str(datetime.timedelta(seconds=time)))

    def get_column_item(self, col):
        if col == 0:
            return self.node_name_item
        if col == 1:
            return self.subtask_id_item
        if col == 2:
            return self.remaining_timeItem
        if col == 3:
            return self.subtask_status_item

        raise ValueError("Wrong column index")
示例#3
0
文件: splash.py 项目: metgem/metgem
class SplashScreen(QSplashScreen):
    def __init__(self):
        self.splash_pix = QPixmap(
            os.path.join(os.path.dirname(__file__), 'splash.png'))
        super().__init__(self.splash_pix,
                         Qt.WindowStaysOnTopHint | Qt.SplashScreen)

        self.setMask(self.splash_pix.mask())
        self.setAttribute(Qt.WA_TranslucentBackground)

        self.__message = ""
        self.__color = Qt.white
        self.__alignment = Qt.AlignBottom | Qt.AlignLeft
        self.__msgrect = self.rect().adjusted(355, 5, -270, -270)

        self.pbar = QProgressBar(self)
        self.pbar.setMaximum(100)
        self.pbar.setGeometry(350,
                              self.splash_pix.height() - 265,
                              self.splash_pix.width() - 680, 15)
        self.pbar.setAlignment(Qt.AlignCenter)
        self.pbar.setStyleSheet("""
            QProgressBar {
                border: 1px solid black;
                text-align: center;
                font-size: 10px;
                padding: 1px;
                border-radius: 5px;
                background: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1,
                stop: 0 #fff,
                stop: 0.4999 #eee,
                stop: 0.5 #ddd,
                stop: 1 #eee );
                height: 15px;
            }

            QProgressBar::chunk {
                background: QLinearGradient( x1: 0, y1: 0, x2: 1, y2: 0,
                stop: 0 #ffadad,
                stop: 1 #ff6666);
                border-radius: 5px;
                border: 1px solid black;
            }""")

        self.version = QLabel(self)
        self.version.setAlignment(Qt.AlignLeft)
        self.version.setStyleSheet("""
            QLabel {
                color : white;
            }""")

    def setValue(self, value):
        self.pbar.setValue(value)

    def setVersion(self, version):
        text = f"Version {version}"
        self.version.setText(text)
        self.version.move(
            self.splash_pix.width() - self.fontMetrics().width(text) - 332,
            self.splash_pix.height() - 265)
        geom = self.pbar.geometry()
        geom.setWidth(geom.width() - self.fontMetrics().width(text) - 10)
        self.pbar.setGeometry(geom)

    def show(self):
        super().show()
        qApp.processEvents()

    def showMessage(self,
                    message: str,
                    alignment: int = Qt.AlignBottom | Qt.AlignLeft,
                    color=Qt.white):
        self.__message = message
        self.__alignment = alignment
        self.__color = color
        self.messageChanged.emit(message)
        self.repaint()
        qApp.processEvents()

    def drawContents(self, painter: QPainter):
        painter.setPen(self.__color)
        painter.drawText(self.__msgrect, self.__alignment, self.__message)
示例#4
0
class VideoPlayer(QWidget):
    def __init__(self, parent=None):
        super(VideoPlayer, self).__init__(parent)

        self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface)
        self.video_backend = None
        self.final_clip = None
        videoWidget = QVideoWidget()

        openButton = QPushButton("Open...")
        openButton.clicked.connect(self.openFile)
        self.processButton = QPushButton("Cut")
        self.processButton.clicked.connect(self.process)
        self.playButton = QPushButton()
        self.playButton.setEnabled(False)
        self.playButton.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay))
        self.playButton.clicked.connect(self.play)

        self.positionSlider = QSlider(Qt.Horizontal)
        self.positionSlider.setRange(0, 0)
        self.positionSlider.sliderMoved.connect(self.setPosition)

        self.errorLabel = QLabel()
        self.errorLabel.setSizePolicy(QSizePolicy.Preferred,
                                      QSizePolicy.Maximum)
        self.errorLabel.setVisible(False)
        self.progressBar = QProgressBar()

        controlLayout = QHBoxLayout()
        controlLayout.setContentsMargins(0, 0, 0, 0)
        controlLayout.addWidget(openButton)
        controlLayout.addWidget(self.playButton)
        controlLayout.addWidget(self.processButton)
        controlLayout.addWidget(self.positionSlider)

        stateLayout = QHBoxLayout()
        stateLayout.setContentsMargins(0, 0, 0, 0)
        stateLayout.addWidget(self.errorLabel)
        stateLayout.addWidget(self.progressBar)
        print(self.progressBar.geometry())

        layout = QVBoxLayout()
        layout.addWidget(videoWidget)
        layout.addLayout(controlLayout)
        layout.addLayout(stateLayout)

        self.setLayout(layout)

        self.mediaPlayer.setVideoOutput(videoWidget)
        self.mediaPlayer.stateChanged.connect(self.mediaStateChanged)
        self.mediaPlayer.positionChanged.connect(self.positionChanged)
        self.mediaPlayer.durationChanged.connect(self.durationChanged)
        self.mediaPlayer.error.connect(self.handleError)

        self.cutter_start = 0
        self.cutter_end = 0

    def openFile(self):
        fileName, _ = QFileDialog.getOpenFileName(self, "Open Movie",
                                                  QDir.homePath())

        if fileName != '':
            self.mediaPlayer.setMedia(
                QMediaContent(QUrl.fromLocalFile(fileName)))
            self.playButton.setEnabled(True)
            self.video_backend = VideoFileClip(fileName)

    def process(self):
        self.final_clip = self.video_backend.subclip(
            t_end=self.mediaPlayer.position() / 1000)
        self.final_clip.write_videofile(
            f'./output/{time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())}.mp4',
            fps=30,
            codec='mpeg4',
            bitrate="8000k",
            audio_codec="libmp3lame",
            threads=4,
        )

    def play(self):
        if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
            self.mediaPlayer.pause()
        else:
            self.mediaPlayer.play()

    def mediaStateChanged(self, state):
        if self.mediaPlayer.state() == QMediaPlayer.PlayingState:
            self.playButton.setIcon(self.style().standardIcon(
                QStyle.SP_MediaPause))
        else:
            self.playButton.setIcon(self.style().standardIcon(
                QStyle.SP_MediaPlay))

    def positionChanged(self, position):
        self.positionSlider.setValue(position)

    def durationChanged(self, duration):
        self.positionSlider.setRange(0, duration)

    def setPosition(self, position):
        self.mediaPlayer.setPosition(position)

    def handleError(self):
        self.playButton.setEnabled(False)
        self.errorLabel.setText("Error: " + self.mediaPlayer.errorString())