Beispiel #1
0
    def init_ui(self):
        self.textFrame = QFrame(self)
        self.hTextLayout = QHBoxLayout(self.textFrame)
        self.hTextLayout.setContentsMargins(10, 0, 10, 0)
        self.hTextLayout.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)

        self.label = ElideLabel(self.textFrame)
        self.hTextLayout.addWidget(self.label)

        self.popupFrame = QFrame(self.parent)
        self.popupFrame.setObjectName("PComboBoxPopup")

        self.lsWidget = PListWidget(self.parent)

        self.hPopuplayout = QHBoxLayout(self.popupFrame)
        self.hPopuplayout.setContentsMargins(0, 0, 0, 0)
        self.hPopuplayout.addWidget(self.lsWidget)

        self.popupFrame.hide()

        self.lsWidget.currentTextChanged.connect(self.set_current_text)
        self.lsWidget.itemClicked.connect(self.hide_popup)
        self.lsWidget.focusOut.connect(self.hide_popup)

        self.setFocusProxy(self.lsWidget)

        self.set_font(QFont("Arial", 14))

        self.set_border_radius(self.border_radius)
Beispiel #2
0
    def __init__(self, parent=None, text=""):
        super().__init__(parent)

        self.mList = []
        self.mListFont = QFont("SegeoUI", 10, QFont.Light)

        self.mListLayout = QVBoxLayout()
        self.mListLayout.setContentsMargins(0, 0, 0, 0)
        self.mListLayout.setSpacing(5)

        self.mLayout = QVBoxLayout(self)
        self.mLayout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.mLayout.setContentsMargins(0, 5, 0, 5)
        self.mLayout.setSpacing(5)

        self.mCaption = ElideLabel(self, text)
        self.mCaption.setObjectName("Caption")
        self.mCaption.setFont(QFont("SegeoUI", 15, QFont.Light))

        self.mLayout.addWidget(self.mCaption)
        self.mLayout.addLayout(self.mListLayout)

        self.setObjectName("LinkList")
        self.setStyleSheet("#LinkList{background-color: white}")
        self.setAutoFillBackground(True)
        self.setContentsMargins(0, 0, 0, 0)
Beispiel #3
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.is_checked = False
        self.direction = 1  # 0: LeftToRight, 1: RightToLeft
        self.spacing = 5

        self.between = True

        self.label = ElideLabel(self)
        self.label.setObjectName("checkBoxText")
        self.check = PCheck(self)
        self.check.stateChanged.connect(self.stateChanged)
Beispiel #4
0
    def init_ui(self):

        self.pic_label = QLabel(self)
        self.pic_label.setObjectName("PCardPicture")
        self.pic_label.setAutoFillBackground(True)
        self.pic_label.setScaledContents(True)
        self.pic_label.setPixmap(QPixmap(self.pictures[0]))

        self.title_label = ElideLabel(self)
        self.title_label.setObjectName("PCardTitle")
        self.title_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.title_label.setText(self.title)
        self.title_label.setWordWrap(True)
        self.set_style_label(self.title_label, 1)

        self.homename_label = QLabel(self)
        self.homename_label.setObjectName("PCardHomeName")
        self.homename_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.homename_label.setText(self.homename)
        self.set_style_label(self.homename_label, 0)

        self.rooms_label = QLabel(self)
        self.rooms_label.setObjectName("PCardRooms")
        self.rooms_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.rooms_label.setText(self.rooms)
        self.set_style_label(self.rooms_label, 0)

        self.posteddate_label = QLabel(self)
        self.posteddate_label.setObjectName("PCardPostedDate")
        self.posteddate_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.posteddate_label.setText("posted " + self.posteddate)
        self.set_style_label(self.posteddate_label, 0)

        self.description_label = ElideLabel(self)
        self.description_label.setObjectName("PCardDescription")
        self.description_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.description_label.setText(self.description)
        self.set_style_label(self.description_label, 0)

        self.price_label = QLabel(self)
        self.price_label.setObjectName("PCardPrice")
        self.price_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.price_label.setText(self.price)
        self.set_style_label(self.price_label, 1)

        self.set_font(self.font)
Beispiel #5
0
	def __init__(self, parent=None):
		QFrame.__init__(self, parent)

		self.setFixedSize(200, 300)

		self.setObjectName("Card")
		
		self.setAutoFillBackground(True)

		self.appId = -1
		self.appIcon = "./img/card/bird.png"
		self.appBack = "./img/card/card_back.png"
		self.appName = "PROS Smart CPQ for Manufacturing"
		self.appDev = "By PROS\nWeb apps"
		self.appRating = 0
		self.appFeedback = 0
		self.appState = 0
		self.style_str = "border: 1px solid #ddd; background: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(225, 225, 225, 225));"
		self.appDesc = "Deliver Sales Automation and Profits Through Personalized Selling"
		self.setBackgroundImage(self.appBack)

		self.iconSize = 48, 48
		self.iconMargins = 10, 10, 10, 10
		self.iconFrameStyle = STYLES.STYLE_DEFAULT

		self.iconFrame = QLabel(self)
		self.iconFrame.setAutoFillBackground(True)
		self.iconFrame.setObjectName("IconFrame")
		self.iconFrame.setStyleSheet(self.iconFrameStyle)

		self.imgIcon = QLabel(self.iconFrame)
		self.imgIcon.setPixmap(QPixmap(self.appIcon))
		self.imgIcon.setFixedSize(48, 48)
		self.imgIcon.setScaledContents(True)

		self.iconLayout = QHBoxLayout(self.iconFrame)
		self.iconLayout.setContentsMargins(10, 10, 10, 10)
		self.iconLayout.setAlignment(Qt.AlignLeft)
		self.iconLayout.addWidget(self.imgIcon, Qt.AlignLeft)
		self.iconFrame.setLayout(self.iconLayout)

		self.txtName = ElideLabel("", self)
		self.txtName.setText(self.appName)
		self.txtName.setFont(QFont("Roboto", 15))
		self.txtName.setElideMode(1)
		self.txtName.setWordWrap(True)

		self.txtDev = ElideLabel("", self)
		self.txtDev.setWordWrap(True)
		self.txtDev.setText(self.appDev)
		self.txtDev.setFont(QFont("Roboto", 8))

		self.txtDesc = ElideLabel("", self)
		self.txtDesc.setText(self.appDesc)
		self.txtDesc.setAlignment(Qt.AlignTop)
		self.txtDesc.setFont(QFont("Roboto", 10))
		self.txtDesc.setElideMode(1)
		self.txtDesc.setWordWrap(True)	

		self.starRating = StarRating(self)

		self.feedbackGiven = QLabel(self)
		self.feedbackGiven.setObjectName("Feedback")
		self.feedbackGiven.setStyleSheet("#Feedback{color: #ababab}")
		self.feedbackGiven.setFont(QFont("Roboto", 12))
		self.feedbackGiven.setAlignment(Qt.AlignVCenter)
		self.feedbackGiven.setText("(" + str(self.appFeedback) + ")")

		self.btnInstall = Button('Install', self)
		self.btnInstall.clicked.connect(self.onInstallClicked)

		self.btnLaunch = Button('Launch', self)
		self.btnLaunch.setButtonType(Button.BUTTON_TYPE.LAUNCH)
		self.btnLaunch.clicked.connect(self.onLaunchClicked)
		self.btnLaunch.hide()

		self.btnUninstall = Button('Uninstall', self)
		self.btnUninstall.setButtonType(Button.BUTTON_TYPE.DELETE)
		self.btnUninstall.clicked.connect(self.onUninstallClicked)
		self.btnUninstall.hide()

		self.shadowEffect = QGraphicsDropShadowEffect(self)
		self.shadowEffect.setBlurRadius(9)
		self.shadowEffect.setColor(QColor(225, 225, 225))
		self.shadowEffect.setOffset(5, 5)
		self.setGraphicsEffect(self.shadowEffect)

		self.frameLayout = QVBoxLayout(self)
		self.frameLayout.setContentsMargins(0, 0, 0, 0)

		self.mainLayout = QVBoxLayout()
		self.mainLayout.setSpacing(5)
		self.mainLayout.setContentsMargins(10, 0, 10, 15)

		self.ratingLayout = QHBoxLayout()
		self.ratingLayout.setSpacing(5)
		self.ratingLayout.addWidget(self.starRating, 1, Qt.AlignLeft)
		self.ratingLayout.addWidget(self.feedbackGiven, 1, Qt.AlignLeft)

		self.separator = QFrame(self)
		self.separator.setObjectName("line")
		self.separator.setFixedHeight(2)
		self.separator.setFixedWidth(self.width())
		self.separator.setFrameShape(QFrame.HLine)
		self.separator.setFrameShadow(QFrame.Sunken)

		self.btnLayout = QHBoxLayout()
		self.btnLayout.setContentsMargins(5, 5, 5, 10)
		self.btnLayout.setSpacing(20)
		self.btnLayout.setAlignment(Qt.AlignHCenter)
		self.btnLayout.addWidget(self.btnInstall)
		self.btnLayout.addWidget(self.btnUninstall)
		self.btnLayout.addWidget(self.btnLaunch)

		self.mainLayout.addWidget(self.txtName, 1, Qt.AlignLeft)
		self.mainLayout.addWidget(self.txtDev, 1, Qt.AlignLeft)
		self.mainLayout.addWidget(self.txtDesc, 3, Qt.AlignLeft)
		self.mainLayout.addLayout(self.ratingLayout, Qt.AlignLeft)

		self.frameLayout.addWidget(self.iconFrame, 1)
		self.frameLayout.addLayout(self.mainLayout)
		self.frameLayout.addWidget(self.separator)
		self.frameLayout.addLayout(self.btnLayout)

		self.setLayout(self.frameLayout)
		self.setAppState(self.appState)
		self.show()
Beispiel #6
0
class AppCard(QFrame):
	"""A Card widget derived from QFrame contains app icon, 
	app name, app developer, app description, app rating, etc"""

	STYLES = STYLES
	Q_ENUM(STYLES)

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

		self.setFixedSize(200, 300)

		self.setObjectName("Card")
		
		self.setAutoFillBackground(True)

		self.appId = -1
		self.appIcon = "./img/card/bird.png"
		self.appBack = "./img/card/card_back.png"
		self.appName = "PROS Smart CPQ for Manufacturing"
		self.appDev = "By PROS\nWeb apps"
		self.appRating = 0
		self.appFeedback = 0
		self.appState = 0
		self.style_str = "border: 1px solid #ddd; background: qlineargradient(spread:pad, x1:0 y1:0, x2:1 y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(225, 225, 225, 225));"
		self.appDesc = "Deliver Sales Automation and Profits Through Personalized Selling"
		self.setBackgroundImage(self.appBack)

		self.iconSize = 48, 48
		self.iconMargins = 10, 10, 10, 10
		self.iconFrameStyle = STYLES.STYLE_DEFAULT

		self.iconFrame = QLabel(self)
		self.iconFrame.setAutoFillBackground(True)
		self.iconFrame.setObjectName("IconFrame")
		self.iconFrame.setStyleSheet(self.iconFrameStyle)

		self.imgIcon = QLabel(self.iconFrame)
		self.imgIcon.setPixmap(QPixmap(self.appIcon))
		self.imgIcon.setFixedSize(48, 48)
		self.imgIcon.setScaledContents(True)

		self.iconLayout = QHBoxLayout(self.iconFrame)
		self.iconLayout.setContentsMargins(10, 10, 10, 10)
		self.iconLayout.setAlignment(Qt.AlignLeft)
		self.iconLayout.addWidget(self.imgIcon, Qt.AlignLeft)
		self.iconFrame.setLayout(self.iconLayout)

		self.txtName = ElideLabel("", self)
		self.txtName.setText(self.appName)
		self.txtName.setFont(QFont("Roboto", 15))
		self.txtName.setElideMode(1)
		self.txtName.setWordWrap(True)

		self.txtDev = ElideLabel("", self)
		self.txtDev.setWordWrap(True)
		self.txtDev.setText(self.appDev)
		self.txtDev.setFont(QFont("Roboto", 8))

		self.txtDesc = ElideLabel("", self)
		self.txtDesc.setText(self.appDesc)
		self.txtDesc.setAlignment(Qt.AlignTop)
		self.txtDesc.setFont(QFont("Roboto", 10))
		self.txtDesc.setElideMode(1)
		self.txtDesc.setWordWrap(True)	

		self.starRating = StarRating(self)

		self.feedbackGiven = QLabel(self)
		self.feedbackGiven.setObjectName("Feedback")
		self.feedbackGiven.setStyleSheet("#Feedback{color: #ababab}")
		self.feedbackGiven.setFont(QFont("Roboto", 12))
		self.feedbackGiven.setAlignment(Qt.AlignVCenter)
		self.feedbackGiven.setText("(" + str(self.appFeedback) + ")")

		self.btnInstall = Button('Install', self)
		self.btnInstall.clicked.connect(self.onInstallClicked)

		self.btnLaunch = Button('Launch', self)
		self.btnLaunch.setButtonType(Button.BUTTON_TYPE.LAUNCH)
		self.btnLaunch.clicked.connect(self.onLaunchClicked)
		self.btnLaunch.hide()

		self.btnUninstall = Button('Uninstall', self)
		self.btnUninstall.setButtonType(Button.BUTTON_TYPE.DELETE)
		self.btnUninstall.clicked.connect(self.onUninstallClicked)
		self.btnUninstall.hide()

		self.shadowEffect = QGraphicsDropShadowEffect(self)
		self.shadowEffect.setBlurRadius(9)
		self.shadowEffect.setColor(QColor(225, 225, 225))
		self.shadowEffect.setOffset(5, 5)
		self.setGraphicsEffect(self.shadowEffect)

		self.frameLayout = QVBoxLayout(self)
		self.frameLayout.setContentsMargins(0, 0, 0, 0)

		self.mainLayout = QVBoxLayout()
		self.mainLayout.setSpacing(5)
		self.mainLayout.setContentsMargins(10, 0, 10, 15)

		self.ratingLayout = QHBoxLayout()
		self.ratingLayout.setSpacing(5)
		self.ratingLayout.addWidget(self.starRating, 1, Qt.AlignLeft)
		self.ratingLayout.addWidget(self.feedbackGiven, 1, Qt.AlignLeft)

		self.separator = QFrame(self)
		self.separator.setObjectName("line")
		self.separator.setFixedHeight(2)
		self.separator.setFixedWidth(self.width())
		self.separator.setFrameShape(QFrame.HLine)
		self.separator.setFrameShadow(QFrame.Sunken)

		self.btnLayout = QHBoxLayout()
		self.btnLayout.setContentsMargins(5, 5, 5, 10)
		self.btnLayout.setSpacing(20)
		self.btnLayout.setAlignment(Qt.AlignHCenter)
		self.btnLayout.addWidget(self.btnInstall)
		self.btnLayout.addWidget(self.btnUninstall)
		self.btnLayout.addWidget(self.btnLaunch)

		self.mainLayout.addWidget(self.txtName, 1, Qt.AlignLeft)
		self.mainLayout.addWidget(self.txtDev, 1, Qt.AlignLeft)
		self.mainLayout.addWidget(self.txtDesc, 3, Qt.AlignLeft)
		self.mainLayout.addLayout(self.ratingLayout, Qt.AlignLeft)

		self.frameLayout.addWidget(self.iconFrame, 1)
		self.frameLayout.addLayout(self.mainLayout)
		self.frameLayout.addWidget(self.separator)
		self.frameLayout.addLayout(self.btnLayout)

		self.setLayout(self.frameLayout)
		self.setAppState(self.appState)
		self.show()

	#automatically adjust child widgets' sizes based on the frame's geometry
	#this might affect widgets' sizes
	def autoAdjust(self):
		self.starRating.adjustWidthByHeight(self.height()/15)
		self.feedbackGiven.setFixedHeight(self.height()/16)
		self.iconFrame.setFixedHeight(self.height()/5)
		self.setIconSize(self.iconFrame.height() * 4 / 5, self.iconFrame.height() *4 / 5)
		mm = self.iconFrame.height() / (5 * 2)
		self.setIconMargins(mm, mm, mm, mm)

	#set fixed size for the icon, maybe called logo or brand
	def setIconSize(self, aw, ah):
		self.iconSize = aw, ah
		self.imgIcon.setFixedSize(self.iconSize[0], self.iconSize[1])

	#set icon margins within the icon frame
	def setIconMargins(self, ml, mt = 0, mr = 0, mb = 0):
		self.iconMargins = ml, mt, mr, mb
		mml, mmt, mmr, mmb = self.mainLayout.getContentsMargins()
		self.iconLayout.setContentsMargins(mml, mt, mmr, mb)
	#set icon frame's style, you can stylize background(single color, gradient or image), border, etc
	def setIconFrameStyle(self, style):
		self.iconFrameStyle = style
		self.iconFrame.setStyleSheet(self.iconFrameStyle)

	@pyqtSlot()
	def onInstallClicked(self):
		QMessageBox.information(None, "ID: " + str(self.appId), "Install button clicked")

	@pyqtSlot()
	def onUninstallClicked(self):
		QMessageBox.information(None, "ID: " + str(self.appId), "Gonna uninstall the app?")

	@pyqtSlot()
	def onLaunchClicked(self):
		QMessageBox.information(None, "ID: " + str(self.appId), "Launch is not ready yet!")

	#set whether the app is already installed or not, accordingly show or hide appropriate buttons
	def setAppState(self, state):
		if state == 0:
			self.btnInstall.show()
			self.btnUninstall.hide()
			self.btnLaunch.hide()
		elif state == 1:
			self.btnInstall.hide()
			self.btnUninstall.show()
			self.btnLaunch.show()
		self.autoAdjust()

	#return current app state
	def getAppState(self):
		return self.appState

	#set applicaton name
	def setAppName(self, name):
		if name != self.appName:
			self.appName = name
			self.txtName.setText(self.appName)
	#return application name
	def getAppName(self):
		return self.appName

	#set developer name, or could be company name
	def setAppDevName(self, name):
		if name != self.appDev:
			self.appDev = name
			self.txtDev.setText(self.appDev)

	#return developer name
	def getAppDevName(self):
		return self.appDev

	#set description about application
	def setAppDesc(self, desc):
		if desc != self.appDesc:
			self.appDesc = desc
			self.txtDesc.setText(self.appDesc)

	#return description of application
	def getAppDesc(self):
		return self.appDesc

	#set application icon with appropriate file path
	def setAppIcon(self, imgPath):
		if imgPath != self.appIcon:
			self.appIcon = imgPath
			self.imgIcon.setPixmap(QPixmap(self.appIcon))

	#return QPixmap of icon
	def getAppIconPixmap(self):
		return QPixmap(self.appIcon)

	#return path to icon
	def getAppIconPath(self):
		return self.appIcon

	#set applicaiton star rating and count of given feedbacks
	def setAppRating(self, rating, feedback):
		if rating != self.appRating or feedback != self.appFeedback:
			self.appRating, self.appFeedback = rating, feedback
			self.starRating.setRating(rating)
			self.feedbackGiven.setText("(" + str(feedback) + ")")

	#return star rating value and the count of given feedbacks
	def getAppRating(self):
		return (self.appRating, self.appFeedback)

	#set path to background would be embedded into stylesheet string
	def setBackgroundImage(self, img):
		self.appBack = img
		self.setStyleSheet("#Card{" + self.style_str + " background-image: url(" + self.appBack + ")}")

	#set application ID
	def setAppId(self, id):
		self.appId = id

	#return app ID
	def getAppId(self):
		return self.appId

	#set blur radius of frame's shadow effect
	def setShadowBlurRadius(self, radius):
		self.shadowEffect.setBlurRadius(radius)

	#set shadow offset of frame's shadow effect
	def setShadowOffset(self, offX, offY):
		self.shadowEffect.setOffset(offX, offY)

	#set shadow color of frame's shadow effect
	def setShadowColor(self, color):
		self.shadowEffect.setColor(color)

	#set font of application name
	def setAppNameFont(self, font):
		self.txtName.setFont(font)

	#set font of developer name
	def setAppDevFont(self, font):
		self.txtDev.setFont(font)

	#set font of description to the app
	def setAppDescFont(self, font):
		self.txtDesc.setFont(font);
    def __init__(self, parent=None):
        super().__init__(parent)

        self.mShowAll = False

        self.mRatingFrame = QFrame(self)
        self.mRatingFrame.setFixedWidth(200)

        self.mRating = StarRating(self.mRatingFrame)
        self.mRating.adjustWidthByHeight(21)
        self.mRatedDate = QLabel("Sat, Jun 17, 2017", self.mRatingFrame)
        self.mRatedDate.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mRater = QLabel("Anonymous", self.mRatingFrame)
        self.mRater.setFont(QFont("SegeoUI", 12, QFont.Light))

        self.mRatingLayout = QVBoxLayout(self.mRatingFrame)
        self.mRatingLayout.setContentsMargins(10, 5, 10, 5)
        self.mRatingLayout.setAlignment(Qt.AlignTop)
        self.mRatingLayout.setSpacing(15)
        self.mRatingLayout.addWidget(self.mRating, 0,
                                     Qt.AlignLeft | Qt.AlignTop)
        self.mRatingLayout.addWidget(self.mRatedDate, 0,
                                     Qt.AlignLeft | Qt.AlignTop)
        self.mRatingLayout.addWidget(self.mRater, 0,
                                     Qt.AlignLeft | Qt.AlignTop)

        self.mTxtFrame = QFrame(self)

        self.mTitle = ElideLabel(self.mTxtFrame, "Undefined")
        self.mTitle.setContentsMargins(0, 0, 0, 0)
        self.mTitle.setFont(QFont("SegeoUI", 14, QFont.Light))

        self.mComment = AutoTextView(self.mTxtFrame)
        self.mComment.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mComment.lessThanLimit.connect(self.onLessThanLimit)
        self.mComment.moreThanLimit.connect(self.onMoreThanLimit)
        self.mComment.setAutoFillBackground(True)

        self.mBtnMore = Link(self.mTxtFrame, "Read More")
        self.mBtnMore.setHoverColor("rgba(25, 55, 155, 255);")
        self.mBtnMore.setHoverStyle("")
        self.mBtnMore.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mBtnMore.setContentsMargins(0, 0, 0, 0)
        self.mBtnMore.clicked.connect(self.onReadMore)

        self.mBtnReport = Link(self.mTxtFrame, "Report this review")
        self.mBtnReport.setDefaultColor("rgba(0, 0, 0, 255);")
        self.mBtnReport.clicked.connect(self.onReport)

        self.mCaptionLayout = QHBoxLayout()
        self.mCaptionLayout.setContentsMargins(0, 0, 0, 0)
        self.mCaptionLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mCaptionLayout.addWidget(self.mTitle)

        self.mTxtLayout = QVBoxLayout(self.mTxtFrame)
        self.mTxtLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mTxtLayout.setContentsMargins(5, 5, 5, 5)
        self.mTxtLayout.setSpacing(5)
        self.mTxtLayout.addLayout(self.mCaptionLayout, 0)
        self.mTxtLayout.addWidget(self.mComment)
        self.mTxtLayout.addWidget(self.mBtnMore, 0, Qt.AlignLeft | Qt.AlignTop)
        self.mTxtLayout.addWidget(self.mBtnReport, 0,
                                  Qt.AlignLeft | Qt.AlignTop)

        self.mLayout = QHBoxLayout(self)
        self.mLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mLayout.addWidget(self.mRatingFrame)
        self.mLayout.addWidget(self.mTxtFrame)

        self.setObjectName("ReviewCard")
class ReviewCard(QFrame):
    """ Review Card widget derived from QFrame which contains star rating, reviewed date, reviewer, title, comment and two text buttons"""
    def __init__(self, parent=None):
        super().__init__(parent)

        self.mShowAll = False

        self.mRatingFrame = QFrame(self)
        self.mRatingFrame.setFixedWidth(200)

        self.mRating = StarRating(self.mRatingFrame)
        self.mRating.adjustWidthByHeight(21)
        self.mRatedDate = QLabel("Sat, Jun 17, 2017", self.mRatingFrame)
        self.mRatedDate.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mRater = QLabel("Anonymous", self.mRatingFrame)
        self.mRater.setFont(QFont("SegeoUI", 12, QFont.Light))

        self.mRatingLayout = QVBoxLayout(self.mRatingFrame)
        self.mRatingLayout.setContentsMargins(10, 5, 10, 5)
        self.mRatingLayout.setAlignment(Qt.AlignTop)
        self.mRatingLayout.setSpacing(15)
        self.mRatingLayout.addWidget(self.mRating, 0,
                                     Qt.AlignLeft | Qt.AlignTop)
        self.mRatingLayout.addWidget(self.mRatedDate, 0,
                                     Qt.AlignLeft | Qt.AlignTop)
        self.mRatingLayout.addWidget(self.mRater, 0,
                                     Qt.AlignLeft | Qt.AlignTop)

        self.mTxtFrame = QFrame(self)

        self.mTitle = ElideLabel(self.mTxtFrame, "Undefined")
        self.mTitle.setContentsMargins(0, 0, 0, 0)
        self.mTitle.setFont(QFont("SegeoUI", 14, QFont.Light))

        self.mComment = AutoTextView(self.mTxtFrame)
        self.mComment.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mComment.lessThanLimit.connect(self.onLessThanLimit)
        self.mComment.moreThanLimit.connect(self.onMoreThanLimit)
        self.mComment.setAutoFillBackground(True)

        self.mBtnMore = Link(self.mTxtFrame, "Read More")
        self.mBtnMore.setHoverColor("rgba(25, 55, 155, 255);")
        self.mBtnMore.setHoverStyle("")
        self.mBtnMore.setFont(QFont("SegeoUI", 12, QFont.Light))
        self.mBtnMore.setContentsMargins(0, 0, 0, 0)
        self.mBtnMore.clicked.connect(self.onReadMore)

        self.mBtnReport = Link(self.mTxtFrame, "Report this review")
        self.mBtnReport.setDefaultColor("rgba(0, 0, 0, 255);")
        self.mBtnReport.clicked.connect(self.onReport)

        self.mCaptionLayout = QHBoxLayout()
        self.mCaptionLayout.setContentsMargins(0, 0, 0, 0)
        self.mCaptionLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mCaptionLayout.addWidget(self.mTitle)

        self.mTxtLayout = QVBoxLayout(self.mTxtFrame)
        self.mTxtLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mTxtLayout.setContentsMargins(5, 5, 5, 5)
        self.mTxtLayout.setSpacing(5)
        self.mTxtLayout.addLayout(self.mCaptionLayout, 0)
        self.mTxtLayout.addWidget(self.mComment)
        self.mTxtLayout.addWidget(self.mBtnMore, 0, Qt.AlignLeft | Qt.AlignTop)
        self.mTxtLayout.addWidget(self.mBtnReport, 0,
                                  Qt.AlignLeft | Qt.AlignTop)

        self.mLayout = QHBoxLayout(self)
        self.mLayout.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.mLayout.addWidget(self.mRatingFrame)
        self.mLayout.addWidget(self.mTxtFrame)

        self.setObjectName("ReviewCard")

    @pyqtSlot()
    def onLessThanLimit(self):
        self.mBtnMore.hide()

    @pyqtSlot()
    def onMoreThanLimit(self):
        self.mBtnMore.show()

    def setReviewRating(self, rating):
        self.mRating.setRating(float(rating))

    # set rated text with formatted QDateTime variable
    def setReviewDate(self, date):
        self.mRatedDate.setText(date.toString("ddd, MMM d, yyyy"))

    # set rated text with pure string
    def setReviewDateString(self, str):
        self.mRatedDate.setText(str)

    def setReviewTitle(self, str):
        self.mTitle.setText(str)

    def setReviewComment(self, str):
        self.mComment.setText(str)

    def showComment(self, showAll=False):
        if showAll:
            self.mComment.showAll()
            self.mBtnMore.setText("Read Less")
        else:
            self.mComment.showLess()
            self.mBtnMore.setText("Read More")

    def onReadMore(self):
        self.mShowAll = not self.mShowAll
        self.showComment(self.mShowAll)

    def onReport(self):
        QMessageBox.information(self, "", "User reported the review")
Beispiel #9
0
class LinkList(QFrame):
    """Widget contains list of links, derived from QFrame which contains a caption and list of links"""

    #this signal is emitted when user click one of links
    itemClicked = pyqtSignal(str)

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

        self.mList = []
        self.mListFont = QFont("SegeoUI", 10, QFont.Light)

        self.mListLayout = QVBoxLayout()
        self.mListLayout.setContentsMargins(0, 0, 0, 0)
        self.mListLayout.setSpacing(5)

        self.mLayout = QVBoxLayout(self)
        self.mLayout.setAlignment(Qt.AlignTop | Qt.AlignLeft)
        self.mLayout.setContentsMargins(0, 5, 0, 5)
        self.mLayout.setSpacing(5)

        self.mCaption = ElideLabel(self, text)
        self.mCaption.setObjectName("Caption")
        self.mCaption.setFont(QFont("SegeoUI", 15, QFont.Light))

        self.mLayout.addWidget(self.mCaption)
        self.mLayout.addLayout(self.mListLayout)

        self.setObjectName("LinkList")
        self.setStyleSheet("#LinkList{background-color: white}")
        self.setAutoFillBackground(True)
        self.setContentsMargins(0, 0, 0, 0)

    #add a new link with a given text
    def addLinkByText(self, text, uri=""):
        newLink = Link(self, text, uri)
        self.addLink(newLink)

    #add a new link with an instance of link
    def addLink(self, newLink):
        newLink.setFont(self.mListFont)
        newLink.clicked.connect(self.onItemClicked)
        self.mList.append(newLink)
        self.mListLayout.addWidget(newLink)

    #remove a link by text
    def removeLink(self, text):
        for link in self.mList:
            if text == link.text():
                self.mListLayout.removeWidget(link)
                self.mList.remove(link)
                link.setParent(None)

    #adjust widget height to fit the total height of elements
    def autoAdjust(self):
        ml, mt, mr, mb = self.mLayout.getContentsMargins()
        mLinkHeight = 0
        if len(self.mList) > 0:
            mLinkHeight = QFontMetrics(self.mListFont).height() * len(
                self.mList)
        self.setFixedHeight(mt + mb + self.mCaption.height() + mLinkHeight +
                            self.mLayout.spacing() +
                            self.mListLayout.spacing() * (len(self.mList) - 1))

    #set the alignment of widget
    def setAlignment(self, align):
        self.mLayout.setAlignment(align)

    #set caption on top of links
    def setCaption(self, text):
        self.mCaption.setText(text)

    #set the font of caption
    def setCaptionFont(self, font):
        self.mCaption.setFont(font)

    #set font of links
    def setLinkFont(self, font):
        self.mListFont = font
        for each in self.mList:
            each.setFont(self.mListFont)

    #set spacing between caption and links
    def setSpacing(self, spacing):
        self.mLayout.setSpacing(spacing)

    #this slot is called when a link is clicked
    @pyqtSlot(str)
    def onItemClicked(self, txt):
        self.itemClicked.emit(txt)
Beispiel #10
0
class PCheckBox(QFrame):
    """ Customized check box """

    stateChanged = Signal(bool)

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

        self.is_checked = False
        self.direction = 1  # 0: LeftToRight, 1: RightToLeft
        self.spacing = 5

        self.between = True

        self.label = ElideLabel(self)
        self.label.setObjectName("checkBoxText")
        self.check = PCheck(self)
        self.check.stateChanged.connect(self.stateChanged)

    def set_direction(self, direction_):

        self.direction = direction_

        if self.between:
            if self.direction == 0:
                self.label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
            elif self.direction == 1:
                self.label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)

        self.update_positions()

    def set_text_alignment(self, align):

        self.label.setAlignment(align)

    def set_text_font(self, font):

        self.label.setFont(font)

    def set_text_color(self, color):

        self.label.setStyleSheet(
            f"#checkBoxText {{color: rgb({color.red()}, {color.green()}, {color.blue()})}}"
        )

    def set_text(self, text_):

        self.label.setText(text_)

    def text(self):

        return self.label.text()

    def update_positions(self):

        if self.direction == 0:  # LeftToRight, checkbox on the left
            self.check.setGeometry(0, 0, self.height(), self.height())
            self.label.setGeometry(self.check.width() + self.spacing, 0,
                                   self.width() - self.check.width() - 5,
                                   self.height())
        else:
            self.check.setGeometry(self.width() - self.height() - self.spacing,
                                   0, self.height(), self.height())
            self.label.setGeometry(0, 0,
                                   self.width() - self.check.width() - 5,
                                   self.height())

    def resizeEvent(self, event):

        QFrame.resizeEvent(self, event)

        self.update_positions()
        font = self.label.font()
        font.setPointSize(self.height() / 2)
        self.label.setFont(font)
Beispiel #11
0
class PComboBox(QFrame):
    """ Customized combo box """
    currentChanged = Signal(str)

    def __init__(self, parent):
        super().__init__(parent)

        self.rate = 0.25
        self.back_color = QColor(108, 108, 115)
        self.text_color = QColor(255, 255, 255)
        self.hover = False

        self.label_width = 0
        self.drop_thick = 1.5
        self.border_radius = 8
        self.parent = parent
        self.popup_height = 0

        self.setObjectName("PComboBox")
        self.setCursor(Qt.PointingHandCursor)
        self.setMinimumHeight(25)
        self.setMinimumWidth(50)
        self.init_ui()

    def init_ui(self):
        self.textFrame = QFrame(self)
        self.hTextLayout = QHBoxLayout(self.textFrame)
        self.hTextLayout.setContentsMargins(10, 0, 10, 0)
        self.hTextLayout.setAlignment(Qt.AlignVCenter | Qt.AlignLeft)

        self.label = ElideLabel(self.textFrame)
        self.hTextLayout.addWidget(self.label)

        self.popupFrame = QFrame(self.parent)
        self.popupFrame.setObjectName("PComboBoxPopup")

        self.lsWidget = PListWidget(self.parent)

        self.hPopuplayout = QHBoxLayout(self.popupFrame)
        self.hPopuplayout.setContentsMargins(0, 0, 0, 0)
        self.hPopuplayout.addWidget(self.lsWidget)

        self.popupFrame.hide()

        self.lsWidget.currentTextChanged.connect(self.set_current_text)
        self.lsWidget.itemClicked.connect(self.hide_popup)
        self.lsWidget.focusOut.connect(self.hide_popup)

        self.setFocusProxy(self.lsWidget)

        self.set_font(QFont("Arial", 14))

        self.set_border_radius(self.border_radius)

    def set_border_radius(self, radius):

        self.border_radius = radius
        self.lsWidget.set_border_radius(radius)
        self.update_style()

    def set_background_color(self, color):

        self.back_color = color
        self.lsWidget.set_back_color(color)
        self.update_style()

    def set_text_color(self, color):

        self.text_color = color
        self.lsWidget.set_text_color(color)
        self.update_style()

    def update_style(self):

        self.setStyleSheet(
            f"#PComboBox {{border-radius: {self.border_radius}; "
            f"color: rgb({self.text_color.red()}, {self.text_color.green()}, {self.text_color.blue()});}}"
        )

        self.label.setStyleSheet(
            f"QLabel {{color: rgb({self.text_color.red()}, {self.text_color.green()}, {self.text_color.blue()})}}"
        )

        self.popupFrame.setStyleSheet(
            f"#PComboBoxPopup {{background: rgb({self.back_color.red()}, {self.back_color.green()}, {self.back_color.blue()}); "
            f"border-radius: {self.border_radius}; "
            f"color: rgb({self.text_color.red()}, {self.text_color.green()}, {self.text_color.blue()});}}"
        )

    def set_popup_height(self, height):

        self.popup_height = height

    def add_items(self, texts):

        self.lsWidget.addItems(texts)
        if self.lsWidget.count() > 0:
            self.lsWidget.setCurrentRow(0)

    def clear(self):

        self.lsWidget.clear()
        self.label.setText("")

    def set_current_index(self, row):

        self.lsWidget.setCurrentRow(row)

    def count(self):

        return self.lsWidget.count()

    def current_index(self):

        return self.lsWidget.currentRow()

    def set_current_text(self, text):

        self.hide_popup()
        if self.label.text() != text:
            self.label.setText(text)
            self.currentChanged.emit(text)

    def set_font(self, font):

        self.label.setFont(font)
        self.lsWidget.setFont(font)

    def current_text(self):

        return self.label.text()

    def show_popup(self):

        return

    def hide_popup(self):

        self.popupFrame.hide()

    def set_text_alignment(self, align):

        self.hTextLayout.setAlignment(align)

    def find_text(self, text, flags):

        items = self.lsWidget.findItems(text, flags)
        if len(items) == 0:
            return -1
        else:
            return self.lsWidget.row(items[0])

    def enterEvent(self, event):

        self.hover = True
        self.update()

    def leaveEvent(self, event):

        self.hover = False
        self.update()

    def resizeEvent(self, event):

        self.label_width = self.width() - float(
            self.height() * self.rate) - float(self.height() * 2 / 3)
        self.textFrame.setGeometry(0, 0, self.label_width, self.height())
        self.popupFrame.setGeometry(
            self.mapToParent(QPoint(0, 0)).x(),
            self.mapToParent(QPoint(0, 0)).y() + self.height(), self.width(),
            150)
        self.set_border_radius(self.height() / 4)

    def mousePressEvent(self, event):

        if not self.popupFrame.isHidden():
            self.hide_popup()
            return

        if self.popup_height == 0:
            self.popupFrame.setFixedHeight(
                (self.lsWidget.fontMetrics().height() + 2) *
                self.lsWidget.count())
        else:
            self.popupFrame.setFixedHeight(self.popup_height)

        self.lsWidget.setFocus()
        self.popupFrame.raise_()
        self.popupFrame.show()

    def paintEvent(self, event):

        painter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing)
        if self.label_width <= 0:
            return

        painter.setPen(Qt.NoPen)
        if self.hover:
            painter.setBrush(
                QColor(self.back_color.red() + 30,
                       self.back_color.green() + 30,
                       self.back_color.blue() + 30))
        else:
            painter.setBrush(self.back_color)

        painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()),
                                self.border_radius, self.border_radius)

        x1 = QPointF(self.label_width + float(self.height() / 3),
                     float(self.height() * 0.45))
        x2 = QPointF(
            self.label_width + float(self.height() * (0.66 + self.rate) / 2),
            float(self.height() * 0.55))
        x3 = QPointF(self.width() - float(self.height() / 3),
                     float(self.height() * 0.45))

        check_path = QPainterPath()
        check_path.moveTo(x1)
        check_path.lineTo(x2)
        check_path.lineTo(x3)

        pen = QPen(self.text_color, self.drop_thick, Qt.SolidLine)
        painter.setPen(pen)
        painter.drawPath(check_path)
Beispiel #12
0
class PCard(QFrame):
    def __init__(self, parent=None):

        super().__init__(parent)
        self.setObjectName("PCard")
        self.border_radius = 8
        self.text_color = QColor(255, 255, 255)
        self.lighttext_color = QColor(self.text_color.red() - 30,
                                      self.text_color.green() - 30,
                                      self.text_color.blue() - 30)
        self.back_color = QColor(108, 108, 115)
        self.title = "30 Barry Rise, Bowdon, Altrincham, Greater Manchester"
        self.homename = "Park_Home"
        self.rooms = "5"
        self.fontSize = 11
        self.font = QFont("Roboto", self.fontSize)
        self.posteddate = "12/10/19"
        self.price = "$20, 000 pcm"
        self.description = "Superb opportunity to purchase this bright and spacious two bedroom flat occupying the two bedroom flat occupying the "
        self.pictures = [
            'image1.jpg', 'image2.jpg', 'image1.jpg', 'image2.jpg'
        ]
        self.init_ui()
        self.set_style()

    def init_ui(self):

        self.pic_label = QLabel(self)
        self.pic_label.setObjectName("PCardPicture")
        self.pic_label.setAutoFillBackground(True)
        self.pic_label.setScaledContents(True)
        self.pic_label.setPixmap(QPixmap(self.pictures[0]))

        self.title_label = ElideLabel(self)
        self.title_label.setObjectName("PCardTitle")
        self.title_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.title_label.setText(self.title)
        self.title_label.setWordWrap(True)
        self.set_style_label(self.title_label, 1)

        self.homename_label = QLabel(self)
        self.homename_label.setObjectName("PCardHomeName")
        self.homename_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.homename_label.setText(self.homename)
        self.set_style_label(self.homename_label, 0)

        self.rooms_label = QLabel(self)
        self.rooms_label.setObjectName("PCardRooms")
        self.rooms_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.rooms_label.setText(self.rooms)
        self.set_style_label(self.rooms_label, 0)

        self.posteddate_label = QLabel(self)
        self.posteddate_label.setObjectName("PCardPostedDate")
        self.posteddate_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.posteddate_label.setText("posted " + self.posteddate)
        self.set_style_label(self.posteddate_label, 0)

        self.description_label = ElideLabel(self)
        self.description_label.setObjectName("PCardDescription")
        self.description_label.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
        self.description_label.setText(self.description)
        self.set_style_label(self.description_label, 0)

        self.price_label = QLabel(self)
        self.price_label.setObjectName("PCardPrice")
        self.price_label.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.price_label.setText(self.price)
        self.set_style_label(self.price_label, 1)

        self.set_font(self.font)

    def set_font(self, font):

        self.fontSize = font.pointSize()
        self.homename_label.setFont(font)
        self.rooms_label.setFont(font)
        self.posteddate_label.setFont(font)
        self.description_label.setFont(font)
        self.title_label.setFont(
            QFont(font.family(), self.fontSize + 3, QFont.DemiBold))
        self.price_label.setFont(
            QFont(font.family(), self.fontSize + 3, QFont.DemiBold))

    def set_style_label(self, label, dark):

        if dark == 0:
            color = self.lighttext_color
        else:
            color = self.text_color

        qssString = f"#{label.objectName()} {{background: rgba({self.back_color.red()}, {self.back_color.green()}, {self.back_color.blue()}, 255);" \
                    f"color: rgb({color.red()}, {color.green()}, {color.blue()}); padding: 2px; }}"

        label.setStyleSheet(qssString)

    def set_border_radius(self, rad):

        self.border_radius = rad
        print(rad)
        self.set_style()

    def set_text_color(self, color):
        self.text_color = color
        self.lighttext_color = QColor(self.text_color.red() - 30,
                                      self.text_color.green() - 30,
                                      self.text_color.blue() - 30)
        self.set_style()

    def set_back_color(self, color):
        self.back_color = color
        self.set_style()

    def set_style(self):
        self.setStyleSheet(
            f"#PCard {{border-radius: {self.border_radius}; "
            f"background: rgb({self.back_color.red()}, {self.back_color.green()}, {self.back_color.blue()}); "
            f"color: rgb({self.text_color.red()}, {self.text_color.green()}, {self.text_color.blue()});}}"
        )

    def resizeEvent(self, event):

        self.setFixedHeight(self.width() * 1.2)
        self.pic_label.setGeometry(0, 0, self.width(), self.height() * 0.61)
        self.title_label.setGeometry(0,
                                     self.height() * 0.61,
                                     self.width() * 11 / 12,
                                     self.height() * 0.12)
        self.homename_label.setGeometry(0,
                                        self.height() * 0.73,
                                        self.width() / 3,
                                        self.height() * 0.07)
        self.rooms_label.setGeometry(self.width() / 3,
                                     self.height() * 0.73,
                                     self.width() / 6,
                                     self.height() * 0.07)
        self.posteddate_label.setGeometry(self.width() / 2,
                                          self.height() * 0.73,
                                          self.width() / 2,
                                          self.height() * 0.07)
        self.description_label.setGeometry(5,
                                           self.height() * 0.8,
                                           self.width() - 10,
                                           self.height() * 0.1)
        self.price_label.setGeometry(self.width() * 0.5,
                                     self.height() * 0.9,
                                     self.width() * 0.5 - self.border_radius,
                                     self.height() * 0.1)
        self.set_border_radius(self.height() / 25)

    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHints(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)
        painter.setBrush(self.back_color)
        painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()),
                                self.border_radius, self.border_radius)