ember/ui/welcome/recent_project.py

72 lines
2.3 KiB
Python
Raw Normal View History

2018-07-28 20:56:23 +00:00
from PyQt5.QtWidgets import QWidget, QHBoxLayout, QLabel, QToolButton, QLayout
from PyQt5.QtCore import pyqtSignal
2018-07-28 20:56:23 +00:00
from PyQt5.QtGui import QFont
class RecentProjectWidget(QWidget):
deleted = pyqtSignal()
pinned = pyqtSignal(bool)
2018-07-28 20:56:23 +00:00
def __init__(self, recentProject):
super().__init__()
self.project = recentProject
self.__selected = False
2018-07-28 20:56:23 +00:00
self.setupUi()
self.setupActions()
self.__setProject(recentProject)
self.setSelected(False)
2018-07-28 20:56:23 +00:00
def setupUi(self):
layout = QHBoxLayout()
# label
self.__text = QLabel()
layout.addWidget(self.__text)
# space
layout.addStretch()
# pin button
self.__pin_button = QToolButton()
self.__pin_button.setFont(QFont("Font Awesome 5 Free"))
self.__pin_button.setText("\uf08d")
self.__pin_button.setCheckable(True)
layout.addWidget(self.__pin_button)
# delete button
self.__del_button = QToolButton()
self.__del_button.setFont(QFont("Font Awesome 5 Free"))
self.__del_button.setText("\uf2ed")
layout.addWidget(self.__del_button)
# pin indicator
self.__pin_indicator = QLabel()
self.__pin_indicator.setFont(QFont("Font Awesome 5 Free"))
self.__pin_indicator.setText("\uf08d")
layout.addWidget(self.__pin_indicator)
2018-07-28 20:56:23 +00:00
# done
layout.setSizeConstraint(QLayout.SetMinimumSize)
self.setLayout(layout)
def setupActions(self):
self.__pin_button.toggled.connect(self.__pinnedToggled)
self.__del_button.pressed.connect(self.deleted)
def setSelected(self, selected = True):
self.__selected = selected
self.__pin_button.setVisible(selected)
self.__del_button.setVisible(selected)
self.__pin_indicator.setVisible(not self.__selected and self.__pin_button.isChecked())
def setPinned(self, isPinned = True):
self.__pin_button.setChecked(isPinned)
def __setProject(self, project):
2018-07-28 20:56:23 +00:00
self.__text = project['name']
self.setPinned(project['pinned'])
def __pinnedToggled(self, isPinned):
self.__pin_indicator.setVisible(not self.__selected and isPinned)
if (isPinned != self.project['pinned']):
self.pinned.emit(isPinned)