def __init__(self,
                 app,
                 action,
                 tasknumber,
                 parent=None,
                 isdeb=False,
                 dftext="",
                 uiname=""):
        QWidget.__init__(self, parent)
        self.isdeb = isdeb
        self.tasknumber = tasknumber
        self.ui_init()
        self.app = app
        self.parent = parent
        self.action = action
        self.uiname = uiname
        self.finish = False

        # self.ui.size.setAlignment(Qt.AlignCenter)
        self.ui.btnCancel.setFocusPolicy(Qt.NoFocus)
        self.ui.status.setAlignment(Qt.AlignTop)
        self.ui.status.setWordWrap(True)
        self.ui.progressBar.lower()
        self.ui.size.setFocusPolicy(Qt.NoFocus)
        self.ui.size.setStyleSheet(
            "QLabel{background-color: transparent;font-size:12px; }")

        self.ui.progresslabel.setFocusPolicy(Qt.NoFocus)
        self.ui.progresslabel.setStyleSheet(
            "QLabel{background-color: transparent;font-size:13px;color:#888888;}"
        )
        self.ui.progresslabel.setText("")

        self.ui.name.setStyleSheet(
            "QLabel{background-color: transparent;font-size:14px;color:#000000}"
        )

        #self.ui.status.setStyleSheet("QLabel{font-size:12px;font-weight:bold;background-color:#EAF0F3;}")
        self.ui.status.setStyleSheet(
            "QLabel{font-size:12px;background-color:transpare nt;}")
        self.ui.btnCancel.setStyleSheet(
            "QPushButton{background-image:url('res/delete-normal.png');border:0px;}QPushButton:hover{background:url('res/delete-hover.png');}QPushButton:pressed{background:url('res/delete-pressed.png');}"
        )
        self.ui.progressBar.setStyleSheet(
            "QProgressBar{background-color:#ffffff;border-radius:0px;color:#1E66A4;}"
            "QProgressBar:chunk{background-color:#5DC4FE;}"
        )  #text-align:right;

        self.ui.btnCancel.clicked.connect(self.slot_click_cancel)

        self.ui.btnCancel.hide()

        if app.status == PkgStates.INSTALLING:  #"installing":
            #self.ui.name.setText("安装 "+app.name)
            try:
                self.ui.progressBarsmall.setValue(self.app.percent)
            except AttributeError as e:
                pass
            text = setLongTextToElideFormat(self.ui.name, "安装 " + app.name)
            self.uiname = "安装 " + app.name
            self.ui.progressBar.setStyleSheet(
                "QProgressBar{background-color:#ffffff;border-radius:0px;color:#1E66A4;}"
                "QProgressBar:chunk{background-color:rgba(45,138,225,20%);}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{background-color:#ffffff;color:#2d8ae1;}")
            self.ui.progressBarsmall.setStyleSheet(
                "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                "QProgressBar:chunk{background-color:#2d8ae1;}")
            self.ui.progressBar.setWindowOpacity(0.8)
            if str(text).endswith("…") is True:
                self.ui.name.setToolTip("安装 " + app.name)
            else:
                self.ui.name.setToolTip("")
        if app.status == PkgStates.REMOVING:  #"uninstalling":
            #self.ui.name.setText("卸载 "+app.name)
            try:
                self.ui.progressBarsmall.setValue(self.app.percent)
            except AttributeError as e:
                pass
            text = setLongTextToElideFormat(self.ui.name, "卸载 " + app.name)
            self.uiname = "卸载 " + app.name
            self.ui.progressBar.setStyleSheet(
                "QProgressBar{background-color:#ffffff;border-radius:0px;color:#1E66A4;}"
                "QProgressBar:chunk{background-color:rgba(233,83,33,20%);}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{background-color:#ffffff;color:#e95421;}")
            self.ui.progressBarsmall.setStyleSheet(
                "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                "QProgressBar:chunk{background-color:#e95421;}")

            if str(text).endswith("…") is True:
                self.ui.name.setToolTip("卸载 " + app.name)
            else:
                self.ui.name.setToolTip("")
        if app.status == PkgStates.UPGRADING:  #"upgrading":
            try:
                self.ui.progressBarsmall.setValue(self.app.percent)
            except AttributeError as e:
                pass
            #self.ui.name.setText("升级 "+app.name)
            text = setLongTextToElideFormat(self.ui.name, "升级 " + app.name)
            self.uiname = "升级 " + app.name
            self.ui.progressBar.setStyleSheet(
                "QProgressBar{background-color:#ffffff;border-radius:0px;color:#1E66A4;}"
                "QProgressBar:chunk{background-color:rgba(7,195,11,20%);}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{background-color:#ffffff;color:#07c30b;}")

            self.ui.progressBarsmall.setStyleSheet(
                "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                "QProgressBar:chunk{background-color:#07c30b;}")
            if str(text).endswith("…") is True:
                self.ui.name.setToolTip("升级 " + app.name)
            else:
                self.ui.name.setToolTip("")

        # this is deb file task
        if (isdeb == True or isinstance(app, DebFile)):

            sizek = app.installedsize
            sizek = round(sizek, 4)
            if (sizek <= 1024):
                self.ui.size.setText(str(sizek) + " KB")
            else:
                self.ui.size.setText(str('%.3f' % (sizek / 1024.0)) + " MB")
            img = QPixmap(UBUNTUKYLIN_RES_ICON_PATH + "default.png")
            # img = img.scaled(32, 32)
            self.ui.icon.setPixmap(img)
        else:
            iconpath = commontools.get_icon_path(app.name)
            img = QPixmap(iconpath)
            # img = img.scaled(32, 32)
            self.ui.icon.setPixmap(img)

            size = app.packageSize
            sizek = size / 1024
            sizek = round(sizek, 4)
            if (sizek == 0):
                self.ui.size.setText("未知")
            elif (sizek < 1024):
                self.ui.size.setText(str('%.1f' % sizek) + " KB")
            else:
                self.ui.size.setText(str('%.2f' % (sizek / 1024.0)) + " MB")

        self.ui.progressBar.setRange(0, 100)
        self.ui.progressBar.reset()
        self.ui.progresslabel.setText("")
        self.ui.status.setText("等待中")
        if (dftext):
            self.ui.status.setText(dftext)
        if (uiname):
            text = setLongTextToElideFormat(self.ui.name, uiname)
            self.ui.progressBar.setStyleSheet(
                "QProgressBar{background-color:#ffffff;border-radius:0px;color:#1E66A4;}"
                "QProgressBar:chunk{background-color:#FDD99A;}")
            self.ui.name.setToolTip(uiname)
        # self.ui.progressBar.hide()
        self.ui.progresslabel.hide()
        self.ui.status.show()
Ejemplo n.º 2
0
    def __init__(self, app, messageBox, parent=None):
        QWidget.__init__(self, parent)
        self.ui_init()
        self.app = app
        self.messageBox = messageBox

        self.switchTimer = QTimer(self)
        # self.switchTimer.timeout.connect(self.slot_switch_animation_step)

        # add by kobe: delay show animation
        self.showDelay = False
        # self.delayTimer = QTimer(self)
        # self.delayTimer.timeout.connect(self.slot_show_delay_animation)

        self.ui.btn.setFocusPolicy(Qt.NoFocus)
        self.ui.btnDetail.setFocusPolicy(Qt.NoFocus)
        self.ui.btnDetail.setStyleSheet(
            "QPushButton{border:0px;background-color:transparent;}")

        self.ui.btnCancel.setFocusPolicy(Qt.NoFocus)
        self.ui.btnCancel.setStyleSheet(
            "QPushButton{background-image:url('res/cancel_1.png');border:0px;}QPushButton:hover{background:url('res/cancel_2.png');}QPushButton:pressed{background:url('res/cancel_2.png');}"
        )
        self.ui.btnCancel.raise_()
        self.ui.btnCancel.clicked.connect(self.slot_click_cancel)

        # self.ui.btnDetail.setCursor(Qt.PointingHandCursor)

        # self.ui.description.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        # self.ui.description.setReadOnly(True)

        # self.ui.baseWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # palette.setColor(QPalette.Background, QColor(245, 248, 250))
        # self.ui.baseWidget.setPalette(palette)

        self.ui.baseWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # img = QPixmap("res/ncard-base.png")
        # palette.setBrush(QPalette.Window, QBrush(img))
        # self.ui.baseWidget.setPalette(palette)

        # self.ui.detailWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # palette.setColor(QPalette.Background, QColor(245, 248, 250))
        # self.ui.detailWidget.setPalette(palette)

        # self.ui.detailWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # img = QPixmap("res/ncard-base.png")
        # palette.setBrush(QPalette.Window, QBrush(img))
        # self.ui.detailWidget.setPalette(palette)

        # palette = QPalette()
        # palette.setBrush(QPalette.Base, QBrush(QColor(255,0,0,0)))
        # self.ui.description.setPalette(palette)

        # component shadow
        # shadowe = QGraphicsDropShadowEffect(self)
        # shadowe.setOffset(-2, 2)    # direction
        # shadowe.setColor(Qt.gray)
        # shadowe.setBlurRadius(4)
        # self.setGraphicsEffect(shadowe)

        iconpath = commontools.get_icon_path(self.app.name)
        self.ui.icon.setStyleSheet("QLabel{background-image:url('" + iconpath +
                                   "');background-color:transparent;}")
        self.ui.progressBar_icon.setStyleSheet(
            "QLabel{background-color:transparent;background-image:url('" +
            iconpath + "')}")
        self.ui.baseWidget.setStyleSheet(
            ".QWidget{border:1px solid #e5e5e5;background-color:#ffffff;}.QWidget:hover{border:1px solid #2d8ae1}"
        )

        # self.ui.baseWidget.setStyleSheet("QWidget{border:0px;}")
        self.ui.name.setStyleSheet(
            "QLabel{font-size:14px;color:#000000;background-color:transparent;}"
        )
        self.ui.progressBarname.setStyleSheet(
            "QLabel{font-size:14px;color:#000000;background-color:transparent;}"
        )
        # self.ui.named.setStyleSheet("QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        self.ui.size.setStyleSheet(
            "QLabel{font-size:13px;color:#888888;background-color:transparent;}"
        )
        self.ui.progresslabel.setStyleSheet(
            "QLabel{font-size:13px;color:#888888;background-color:transparent;}"
        )
        # self.ui.isInstalled.setStyleSheet("QLabel{font-size:13px;color:#888888;}")
        # self.ui.description.setStyleSheet("QTextEdit{border:0px;font-size:13px;color:#888888;}")

        # letter spacing
        # font = QFont()
        # font.setLetterSpacing(QFont.PercentageSpacing, 90.0)
        # self.ui.name.setFont(font)
        # self.ui.description.setFont(font)
        # if(len(self.app.displayname) > 20):
        #     font2 = QFont()
        #     font2.setLetterSpacing(QFont.PercentageSpacing, 80.0)
        #     self.ui.name.setFont(font2)
        #     self.ui.name.setStyleSheet("QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        # if(len(self.app.displayname) > 24):
        #     font2 = QFont()
        #     font2.setLetterSpacing(QFont.PercentageSpacing, 80.0)
        #     self.ui.name.setFont(font2)
        #     self.ui.name.setStyleSheet("QLabel{font-size:12px;font-weight:bold;color:#666666;}")

        # convert size
        # installedsize = self.app.installedSize
        installedsize = self.app.installedSize
        if installedsize == 0:
            installedsize = app.packageSize
        installedsizek = installedsize / 1024
        if (installedsizek == 0):
            #self.ui.size.setText("未知")
            self.ui.size.setText(_("unknown"))
        elif (installedsizek < 1024):
            self.ui.size.setText(str('%.1f' % installedsizek) + " KB")
        else:
            self.ui.size.setText(
                str('%.2f' % (installedsizek / 1024.0)) + " MB")

        # self.ui.name.setText(self.app.displayname)
        # self.ui.named.setText(self.app.displayname)
        # add by kobe
        if self.app.displayname_cn != '' and self.app.displayname_cn is not None and self.app.displayname_cn != 'None':
            setLongTextToElideFormat(self.ui.name, self.app.displayname_cn)
            setLongTextToElideFormat(self.ui.progressBarname,
                                     self.app.displayname_cn)
            # setLongTextToElideFormat(self.ui.named, self.app.displayname_cn)
        else:
            setLongTextToElideFormat(self.ui.name, self.app.displayname)
            setLongTextToElideFormat(self.ui.progressBarname,
                                     self.app.displayname)
            # setLongTextToElideFormat(self.ui.named, self.app.displayname)
        # if self.app.summary is not None and self.app.summary != 'None' and self.app.summary != '':
        # self.ui.description.setText(self.app.summary)
        # else:
        #     self.ui.description.setText(self.app.orig_summary)

        # rating star
        # self.star = StarWidget("small", self.app.ratings_average, self.ui.baseWidget)
        # self.star.move(75, 56)

        # add by kobe
        # self.ui.isInstalled.setText("已安装")
        if self.app.status in (PkgStates.INSTALLING, PkgStates.REMOVING,
                               PkgStates.UPGRADING):
            # self.star.hide()
            self.ui.progressBar.setVisible(True)
            self.ui.progresslabel.setVisible(True)
            self.ui.progressBar_icon.setVisible(True)
            self.ui.progressBar.setValue(self.app.percent)
            self.ui.progressBarsmall.setValue(self.app.percent)
            self.ui.progresslabel.setText(str('%.0f' % self.app.percent) + '%')

        if self.app.status == PkgStates.INSTALLING:
            self.ui.btn.setEnabled(False)
            # if self.app.percent > 0:
            #     self.ui.btn.setText("正在安装")
            # else:
            #     self.ui.btn.setText("等待安装")
            if (Globals.MIPS64):
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                )
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                )
            else:
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#d5e8f9;}")
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#2d8ae1;}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{font-size:12px;color:#2d8ae1;background-color:transparent;}"
            )
            # self.ui.btn.setStyleSheet("QPushButton{color:white;border:0px;background-image:url('res/ncard-install-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-install-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-install-btn-3.png');}")
            # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-install-border.png');}")
        elif self.app.status == PkgStates.REMOVING:
            self.ui.btn.setEnabled(False)
            # if self.app.percent > 0:
            #     self.ui.btn.setText("正在卸载")
            # else:
            #     self.ui.btn.setText("等待卸载")
            if (Globals.MIPS64):
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                )
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                )
            else:
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#ffe0d6;}")
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#e95421;}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{font-size:12px;color:#e95421;background-color:transparent;}"
            )
            # self.ui.btn.setStyleSheet("QPushButton{color:white;border:0px;background-image:url('res/ncard-un-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-un-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-un-btn-3.png');}")
            # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-un-border.png');}")

        elif self.app.status == PkgStates.UPGRADING:
            self.ui.btn.setEnabled(False)
            # if self.app.percent > 0:
            #     self.ui.btn.setText("正在升级")
            # else:
            #     self.ui.btn.setText("等待升级")
            if (Globals.MIPS64):
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                )
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                )
            else:
                self.ui.progressBar.setStyleSheet(
                    "QProgressBar{background-color:#ffffff;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#d1f8d1;}")
                self.ui.progressBarsmall.setStyleSheet(
                    "QProgressBar{background-color:#e5e5e5;border:0px;border-radius:0px;}"
                    "QProgressBar:chunk{background-color:#07c30b;}")
            self.ui.progresslabel.setStyleSheet(
                "QLabel{font-size:12px;color:#07c30b;background-color:transparent;}"
            )
            # self.ui.btn.setStyleSheet("QPushButton{color:white;border:0px;background-image:url('res/ncard-up-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-up-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-up-btn-3.png');}")
            # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-up-border.png');}")

        elif (self.app.is_installed):
            # add by kobe
            # self.star.hide()
            # self.ui.isInstalled.setVisible(True)

            if (run.get_run_command(self.app.name) == ""):
                self.app.status = PkgStates.NORUN
                #self.ui.btn.setText("已安装")
                self.ui.btn.setText(_("Aldy install"))
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-un-border.png');}")
                self.ui.btn.setEnabled(False)
            else:
                self.app.status = PkgStates.RUN
                #self.ui.btn.setText("启动")
                self.ui.btn.setText(_("Start"))
                self.ui.btn.setEnabled(True)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-run-border.png');}")
        else:
            # star = StarWidget("small", self.app.ratings_average, self.ui.baseWidget)
            # star.move(75, 56)
            # init app.status
            self.app.status = PkgStates.INSTALL
            # self.star.show()
            # self.ui.isInstalled.setVisible(False)
            # self.ui.btn.setText("安装")
            self.ui.btn.setText(_("Install"))
            self.ui.btn.setEnabled(True)
            self.ui.btn.setStyleSheet(
                "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
            )
            # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-install-border.png');}")

        if isinstance(self.app, ApkInfo):
            if not Globals.APK_EVNRUN:
                #self.ui.btn.setText("启动安卓环境")
                self.ui.btn.setText(_("Start the Android environment"))
        self.connect = self.ui.btn.clicked.connect(self.slot_btn_click)
        self.ui.btnDetail.clicked.connect(self.slot_emit_detail)
Ejemplo n.º 3
0
    def __init__(self, app, messageBox, parent=None):
        QWidget.__init__(self, parent)
        self.ui_init()

        self.app = app
        self.messageBox = messageBox

        self.switchTimer = QTimer(self)
        self.switchTimer.timeout.connect(self.slot_switch_animation_step)

        # add by kobe: delay show animation
        self.showDelay = False
        self.delayTimer = QTimer(self)
        self.delayTimer.timeout.connect(self.slot_show_delay_animation)

        self.ui.btn.setFocusPolicy(Qt.NoFocus)
        self.ui.btnDetail.setFocusPolicy(Qt.NoFocus)

        self.ui.btnDetail.setCursor(Qt.PointingHandCursor)

        self.ui.description.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.ui.description.setReadOnly(True)

        self.ui.baseWidget.setAutoFillBackground(True)
        palette = QPalette()
        img = QPixmap("res/ncard-base.png")
        palette.setBrush(QPalette.Window, QBrush(img))
        self.ui.baseWidget.setPalette(palette)

        self.ui.detailWidget.setAutoFillBackground(True)
        palette = QPalette()
        img = QPixmap("res/ncard-base.png")
        palette.setBrush(QPalette.Window, QBrush(img))
        self.ui.detailWidget.setPalette(palette)

        palette = QPalette()
        palette.setBrush(QPalette.Base, QBrush(QColor(255, 0, 0, 0)))
        self.ui.description.setPalette(palette)

        iconpath = commontools.get_icon_path(self.app.name)
        self.ui.icon.setStyleSheet("QLabel{background-image:url('" + iconpath +
                                   "');background-color:transparent;}")

        # self.ui.baseWidget.setStyleSheet("QWidget{border:0px;}")
        self.ui.name.setStyleSheet(
            "QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        self.ui.named.setStyleSheet(
            "QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        self.ui.size.setStyleSheet("QLabel{font-size:13px;color:#888888;}")
        self.ui.description.setStyleSheet(
            "QTextEdit{border:0px;font-size:13px;color:#888888;}")

        # letter spacing
        font = QFont()
        font.setLetterSpacing(QFont.PercentageSpacing, 90.0)
        self.ui.name.setFont(font)
        self.ui.description.setFont(font)
        if (len(self.app.displayname) > 20):
            font2 = QFont()
            font2.setLetterSpacing(QFont.PercentageSpacing, 80.0)
            self.ui.name.setFont(font2)
            self.ui.name.setStyleSheet(
                "QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        if (len(self.app.displayname) > 24):
            font2 = QFont()
            font2.setLetterSpacing(QFont.PercentageSpacing, 80.0)
            self.ui.name.setFont(font2)
            self.ui.name.setStyleSheet(
                "QLabel{font-size:12px;font-weight:bold;color:#666666;}")

        # convert size
        # installedsize = self.app.installedSize
        installedsize = self.app.packageSize
        installedsizek = installedsize / 1024
        if (installedsizek == 0):
            self.ui.size.setText("未知")
        elif (installedsizek < 1024):
            self.ui.size.setText(str('%.1f' % installedsizek) + " KB")
        else:
            self.ui.size.setText(
                str('%.2f' % (installedsizek / 1024.0)) + " MB")

        # self.ui.name.setText(self.app.displayname)
        # self.ui.named.setText(self.app.displayname)
        # add by kobe
        if self.app.displayname_cn != '' and self.app.displayname_cn is not None and self.app.displayname_cn != 'None':
            setLongTextToElideFormat(self.ui.name, self.app.displayname_cn)
            setLongTextToElideFormat(self.ui.named, self.app.displayname_cn)
        else:
            setLongTextToElideFormat(self.ui.name, self.app.displayname)
            setLongTextToElideFormat(self.ui.named, self.app.displayname)

        if self.app.summary is not None and self.app.summary != 'None' and self.app.summary != '':
            self.ui.description.setText(self.app.summary)
        else:
            self.ui.description.setText(self.app.orig_summary)

        # rating star
        star = StarWidget("small", self.app.ratings_average,
                          self.ui.baseWidget)
        star.move(75, 56)

        # btn & border
        if (app.is_installed):
            if (run.get_run_command(self.app.name) == ""):
                self.app.status = PkgStates.NORUN
                self.ui.btn.setText("已安装")
                self.ui.btn.setEnabled(False)
                self.ui.btn.setStyleSheet(
                    "QPushButton{color:white;border:0px;background-image:url('res/ncard-un-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-un-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-un-btn-3.png');}"
                )
                self.ui.btnDetail.setStyleSheet(
                    "QPushButton{border:0px;background-image:url('res/ncard-un-border.png');}"
                )
            else:
                self.app.status = PkgStates.RUN
                self.ui.btn.setText("启动")
                self.ui.btn.setEnabled(True)
                self.ui.btn.setStyleSheet(
                    "QPushButton{color:white;border:0px;background-image:url('res/ncard-run-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-run-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-run-btn-3.png');}"
                )
                self.ui.btnDetail.setStyleSheet(
                    "QPushButton{border:0px;background-image:url('res/ncard-run-border.png');}"
                )
        else:
            self.app.status = PkgStates.INSTALL
            self.ui.btn.setText("安装")
            self.ui.btn.setEnabled(True)
            self.ui.btn.setStyleSheet(
                "QPushButton{color:white;border:0px;background-image:url('res/ncard-install-btn-1.png');}QPushButton:hover{border:0px;background-image:url('res/ncard-install-btn-2.png');}QPushButton:pressed{border:0px;background-image:url('res/ncard-install-btn-3.png');}"
            )
            self.ui.btnDetail.setStyleSheet(
                "QPushButton{border:0px;background-image:url('res/ncard-install-border.png');}"
            )

        self.ui.btn.clicked.connect(self.slot_btn_click)
        self.ui.btnDetail.clicked.connect(self.slot_emit_detail)
    def status_change(self, processtype, percent, msg):
        if (self.finish == False):
            text = ''
            if (processtype == 'fetch'):
                self.ui.btnCancel.show()
                # self.ui.btnCancel.show()
                #text = "正在下载: "
                text = _("downloading")
                #self.ui.name.setText( "下载 " + self.app.name)
                self.ui.name.setText(
                    _("download") + " " + self.app.displayname_cn)
                if isinstance(self.app, Application):
                    self.ui.btnCancel.hide()
                else:
                    self.ui.btnCancel.show()

                if percent >= 100:
                    #text = "下载完成,开始安装..."
                    self.ui.progressBar.reset()
                    self.ui.progresslabel.setText("")
                    # self.ui.progressBar.hide()
                    self.ui.progresslabel.show()
                    self.ui.btnCancel.hide()
                    self.ui.status.show()
                    #self.ui.status.setText("正在安装")
                    self.ui.status.setText(_("Installing"))
                    return
                else:
                    self.ui.progresslabel.show()
                    self.ui.status.hide()
                    self.ui.progressBar.hide()
                    self.ui.progressBar.hide()
                    self.ui.progressBar.setValue(percent)
                    self.ui.progressBar.show()
                    try:
                        self.ui.progressBarsmall.hide()
                        self.ui.progressBarsmall.setValue(self.app.percent)
                        self.ui.progressBarsmall.show()
                    except AttributeError as e:
                        pass
                    self.ui.progressBar.show()
                    # self.ui.progresslabel.setText(self.ui.progressBar.value())
                    self.ui.progresslabel.hide()
                    self.ui.progresslabel.setText(str('%.0f' % percent) + '%')
                    self.ui.progresslabel.show()
            elif (processtype == 'apt'):
                #text = "正在执行: "
                text = _("Running")
                #if "下载" in self.ui.name.text():
                if _("download") in self.ui.name.text():
                    #self.ui.name.setText("安装 " + self.app.name)
                    self.ui.name.setText(
                        _("Install") + " " + self.app.displayname_cn)
                    text = setLongTextToElideFormat(
                        self.ui.name,
                        _("Install") + " " + self.app.displayname_cn)
                    if str(text).endswith("…") is True:
                        # self.ui.name.setToolTip("安装 "+app.name)
                        self.ui.name.setToolTip(
                            _("Install") + " " + self.app.displayname_cn)
                    else:
                        self.ui.name.setToolTip("")

                if percent < float(0.0):
                    #print percent
                    # self.ui.progressBar.hide()
                    self.ui.progresslabel.hide()
                    if int(percent) == int(-7):
                        #self.ui.status.setText("完成")
                        self.ui.status.setText(_("perfection"))
                    else:
                        #self.ui.status.setText("失败")
                        self.ui.status.setText(_("failure"))

                        self.ui.progressBar.setValue(0)
                        self.ui.progressBarsmall.setValue(0)
                        self.ui.progressBarsmall.hide()
                        self.ui.progressBar.hide()
                    self.ui.status.show()
                    self.finish = True
                elif percent >= 100:
                    #text = "安装完成"
                    text = _("The installation is complete")

                    # self.ui.progressBar.hide()
                    self.ui.progresslabel.hide()
                    #self.ui.status.setText("完成")
                    self.ui.status.setText(_("perfection"))

                    self.ui.status.show()
                    self.ui.progressBar.hide()
                    self.ui.progressBar.setValue(percent)
                    self.ui.progressBar.show()
                    try:
                        self.ui.progressBarsmall.hide()
                        self.ui.progressBarsmall.setValue(self.app.percent)
                        self.ui.progressBarsmall.show()
                    except AttributeError as e:
                        pass
                    # self.ui.progresslabel.setText(self.ui.progressBar.value())
                    self.ui.progresslabel.setText(str('%.0f' % percent) + '%')
                else:
                    #                    if (self.ui.status.text() != '完成'):
                    if (self.ui.status.text() != _("perfection")):

                        self.ui.progresslabel.show()
                        self.ui.status.hide()
                        self.ui.progressBar.hide()
                        self.ui.progressBar.setValue(percent)
                        self.ui.progressBar.show()
                        try:
                            self.ui.progressBarsmall.hide()
                            self.ui.progressBarsmall.setValue(self.app.percent)
                            self.ui.progressBarsmall.show()
                        except AttributeError as e:
                            pass
                        self.ui.progressBar.show()
                        # self.ui.progresslabel.setText(self.ui.progressBar.value())
                        self.ui.progresslabel.setText(
                            str('%.0f' % percent) + '%')
                    else:
                        self.ui.progresslabel.hide()
                        # self.ui.progressBar.hide()
                        self.ui.status.show()
    def __init__(self, winstat, app, messageBox, parent=None):
        QWidget.__init__(self, parent)
        self.ui_init()
        self.winstat = winstat
        self.app = app
        self.messageBox = messageBox

        self.switchTimer = QTimer(self)
        # self.switchTimer.timeout.connect(self.slot_switch_animation_step)

        # add by kobe: delay show animation
        self.showDelay = False
        self.delayTimer = QTimer(self)
        # self.delayTimer.timeout.connect(self.slot_show_delay_animation)

        self.ui.btn.setFocusPolicy(Qt.NoFocus)
        self.ui.btnDetail.setFocusPolicy(Qt.NoFocus)
        self.ui.btnDetail.setStyleSheet(
            "QPushButton{border:0px;background-color:transparent;}")

        # self.ui.btnDetail.setCursor(Qt.PointingHandCursor)

        # self.ui.description.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        # self.ui.description.setReadOnly(True)

        # self.ui.baseWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # palette.setColor(QPalette.Background, QColor(245, 248, 250))
        # self.ui.baseWidget.setPalette(palette)

        self.ui.baseWidget.setAutoFillBackground(True)
        self.ui.baseWidget.setStyleSheet(
            ".QWidget{border:1px solid #e5e5e5;background-color:#ffffff;}.QWidget:hover{border:1px solid #2d8ae1}"
        )

        # self.ui.detailWidget.setAutoFillBackground(True)
        # palette = QPalette()
        # palette.setColor(QPalette.Background, QColor(245, 248, 250))
        # self.ui.detailWidget.setPalette(palette)

        # self.ui.detailWidget.setAutoFillBackground(True)
        palette = QPalette()
        img = QPixmap("res/wincard-base.png")
        palette.setBrush(QPalette.Window, QBrush(img))
        # self.ui.detailWidget.setPalette(palette)

        palette = QPalette()
        palette.setBrush(QPalette.Base, QBrush(QColor(255, 0, 0, 0)))
        # self.ui.description.setPalette(palette)

        img = QPixmap("res/arrowhead.png")
        self.ui.arronicon.setPixmap(img)
        self.ui.arronicon.setStyleSheet(
            "QLabel{background-color:transparent;}")
        self.ui.winname.setStyleSheet(
            "QLabel{font-size:13px;font-weight:bold;color:#666666;background-color:transparent;}"
        )
        # self.ui.wintext.setStyleSheet("QLabel{font-size:13px;color:#888888;}")
        self.ui.winbake.setStyleSheet(
            "QLabel{font-size:13px;color:#888888;background-color:transparent;}"
        )
        self.ui.name.setStyleSheet(
            "QLabel{font-size:13px;font-weight:bold;color:#666666;background-color:transparent;}"
        )
        # self.ui.named.setStyleSheet("QLabel{font-size:13px;font-weight:bold;color:#666666;}")
        self.ui.size.setStyleSheet(
            "QLabel{font-size:13px;color:#888888;background-color:transparent;}"
        )
        # self.ui.description.setStyleSheet("QTextEdit{border:0px;font-size:13px;color:#888888;}")

        # win frame
        if (os.path.isfile(UBUNTUKYLIN_HTTP_WIN_RES_PATH +
                           str(self.winstat.windows_app_name) + ".png")):
            self.ui.winicon.setStyleSheet(
                ITEM_LABEL_STYLE %
                (UBUNTUKYLIN_HTTP_WIN_RES_PATH +
                 str(self.winstat.windows_app_name) + ".png"))
        elif (os.path.isfile(UBUNTUKYLIN_HTTP_WIN_RES_PATH +
                             str(self.winstat.windows_app_name) + ".jpg")):
            self.ui.winicon.setStyleSheet(
                ITEM_LABEL_STYLE %
                (UBUNTUKYLIN_HTTP_WIN_RES_PATH +
                 str(self.winstat.windows_app_name) + ".jpg"))
        elif (os.path.isfile(UBUNTUKYLIN_RES_WIN_PATH +
                             str(self.winstat.windows_app_name) + ".png")):
            self.ui.winicon.setStyleSheet(
                ITEM_LABEL_STYLE %
                (UBUNTUKYLIN_RES_WIN_PATH +
                 str(self.winstat.windows_app_name) + ".png"))
        elif (os.path.isfile(UBUNTUKYLIN_RES_WIN_PATH +
                             str(self.winstat.windows_app_name) + ".jpg")):
            self.ui.winicon.setStyleSheet(
                ITEM_LABEL_STYLE %
                (UBUNTUKYLIN_RES_WIN_PATH +
                 str(self.winstat.windows_app_name) + ".jpg"))
        else:
            self.ui.winicon.setStyleSheet(
                ITEM_LABEL_STYLE % (UBUNTUKYLIN_RES_WIN_PATH + "default.png"))

        # add by kobe
        #setLongTextToElideFormat(self.ui.winname, self.winstat.windows_app_name)
        #setLongTextToElideFormat(self.ui.wintext, self.winstat.display_name_windows)
        setLongTextToElideFormat(self.ui.winname,
                                 self.winstat.display_name_windows)
        # setLongTextToElideFormat(self.ui.wintext, self.winstat.windows_app_name)
        setLongTextToElideFormat(self.ui.winbake, self.winstat.category)
        # metrics = QFontMetrics(self.ui.winname.font())
        # elidedText = metrics.elidedText(self.winstat.windows_app_name, Qt.ElideRight, self.ui.winname.width())
        # self.ui.winname.setText(elidedText)

        if self.app is None:
            if (self.winstat.app_name == 'wine-qq'
                    or self.winstat.app_name == 'ppstream'):
                iconpath = commontools.get_icon_path(self.winstat.app_name)
                self.ui.icon.setStyleSheet("QLabel{background-image:url('" +
                                           iconpath +
                                           "');background-color:transparent;}")
        else:
            iconpath = commontools.get_icon_path(self.app.name)
            self.ui.icon.setStyleSheet("QLabel{background-image:url('" +
                                       iconpath +
                                       "');background-color:transparent;}")

        # self.ui.baseWidget.setStyleSheet("QWidget{border:0px;}")
        # self.ui.homeline1.setStyleSheet("QLabel{background-color:#CCCCCC;}")

        if self.app is None:
            if (self.winstat.app_name == 'wine-qq'
                    or self.winstat.app_name == 'ppstream'):
                self.ui.size.setText("")
                # self.ui.name.setText(self.winstat.app_name)
                # self.ui.named.setText(self.winstat.app_name)
                setLongTextToElideFormat(self.ui.name, self.winstat.app_name)
                # setLongTextToElideFormat(self.ui.named, self.winstat.app_name)
                # self.ui.description.setText(self.winstat.description)
        else:
            # convert size
            # installedsize = self.app.installedSize
            installedsize = self.app.packageSize
            installedsizek = installedsize / 1024
            if (installedsizek == 0):
                self.ui.size.setText("未知")
            elif (installedsizek < 1024):
                self.ui.size.setText(str('%.1f' % installedsizek) + " KB")
            else:
                self.ui.size.setText(
                    str('%.2f' % (installedsizek / 1024.0)) + " MB")

            # add by kobe
            if self.app.displayname_cn != '' and self.app.displayname_cn is not None and self.app.displayname_cn != 'None':
                setLongTextToElideFormat(self.ui.name, self.app.displayname_cn)
                # setLongTextToElideFormat(self.ui.named, self.app.displayname_cn)
            else:
                setLongTextToElideFormat(self.ui.name, self.app.displayname)
                # setLongTextToElideFormat(self.ui.named, self.app.displayname)
            # if self.app.summary is not None and self.app.summary != 'None' and self.app.summary != '':
            # self.ui.description.setText(self.app.summary)
            # else:
            #     self.ui.description.setText(self.app.orig_summary)

        if self.app is None:
            if (self.winstat.app_name == 'wine-qq'
                    or self.winstat.app_name == 'ppstream'):
                self.ui.btn.setText("安装")
                self.ui.btn.setEnabled(True)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-install-border.png');}")
            else:
                self.ui.btn.setText("无效")
                self.ui.btn.setEnabled(False)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:0px;background-color:#ffffff;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/ncard-un-border.png');}")
        else:
            if app.status == PkgStates.INSTALLING:
                self.ui.btn.setEnabled(False)
                self.ui.btn.setText("正在安装")
                # self.ui.isInstalled.setVisible(False)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-install-border.png');}")
            elif app.status == PkgStates.REMOVING:
                self.ui.btn.setEnabled(False)
                self.ui.btn.setText("正在卸载")
                # self.ui.isInstalled.setVisible(False)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#e95421;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#e95421;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-un-border.png');}")
            elif app.status == PkgStates.UPGRADING:
                self.ui.btn.setEnabled(False)
                self.ui.btn.setText("正在升级")
                # self.ui.isInstalled.setVisible(False)
                self.ui.btn.setStyleSheet(
                    "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#07c30b;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#07c30b;}"
                )
                # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-up-border.png');}")
            else:
                if (self.app.is_installed):
                    if (run.get_run_command(self.app.name) == ""):
                        self.app.status = PkgStates.NORUN
                        self.ui.btn.setText("已安装")
                        self.ui.btn.setEnabled(False)
                        self.ui.btn.setStyleSheet(
                            "QPushButton{font-size:12px;color:#000000;border:0px;background-color:#ffffff;}"
                        )
                        # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-un-border.png');}")
                    else:
                        self.app.status = PkgStates.RUN
                        self.ui.btn.setText("启动")
                        self.ui.btn.setEnabled(True)
                        self.ui.btn.setStyleSheet(
                            "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
                        )
                        # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-run-border.png');}")
                else:
                    self.app.status = PkgStates.INSTALL
                    self.ui.btn.setText("安装")
                    self.ui.btn.setEnabled(True)
                    self.ui.btn.setStyleSheet(
                        "QPushButton{font-size:12px;color:#000000;border:1px solid #d5d5d5;background-color:#ffffff;}QPushButton:hover{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}QPushButton:pressed{font-size:12px;color:#ffffff;border:1px solid #d5d5d5;background-color:#2d8ae1;}"
                    )
                    # self.ui.btnDetail.setStyleSheet("QPushButton{border:0px;background-image:url('res/wincard-install-border.png');}")

        self.ui.btn.clicked.connect(self.slot_btn_click)
        self.ui.btnDetail.clicked.connect(self.slot_emit_detail)