Advertisement
Guest User

Untitled

a guest
May 27th, 2015
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. import os
  2. import sys
  3. import traceback
  4.  
  5. from PyQt5 import QtCore, QtGui, QtWidgets
  6. Qt = QtCore.Qt
  7.  
  8.  
  9.  
  10. class Window(QtWidgets.QMainWindow):
  11. def __init__(self, parent=None):
  12. super(Window, self).__init__(parent)
  13. self.setWindowTitle('FVRL')
  14. self.setCentralWidget(BookItemWidget())
  15. self.setStyleSheet('QMainWindow {background-color: white;}')
  16.  
  17.  
  18.  
  19.  
  20. class BookItemWidget(QtWidgets.QWidget):
  21. """
  22. The widget that displays book entries in the list view
  23. """
  24. def __init__(self, parent=None):
  25. super(BookItemWidget, self).__init__(parent)
  26.  
  27. self.title = QtWidgets.QLabel('Of Mice And Men')
  28. self.author = QtWidgets.QLabel('John Steinbeck')
  29. self.cover = QtWidgets.QLabel()
  30. self.cover.setPixmap(QtGui.QPixmap('of_mice_and_men.jpg').scaled(80, 80, QtCore.Qt.KeepAspectRatio))
  31. self.cover.setAlignment(Qt.AlignTop)
  32. self.description = ElideTextLabel('A controversial tale of friendship and tragedy during the Great Depression, in a deluxe centennial edition Over seventy-five years since its first publication, Steinbeck\'s tale of commitment, loneliness, hope, and loss remains one of America\'s most widely read and taught novels. An unlikely pair, George and Lennie, two migrant workers in California during the Great Depression, grasp for their American Dream. They hustle work when they can, living a hand-to-mouth existence. For George and Lennie have a plan: to own an acre of land and a shack they can call their own. When they land jobs on a ranch in the Salinas Valley, the fulfillment of their dream seems to be within their grasp. But even George cannot guard Lennie from the provocations, nor predict the consequences of Lennie\'s unswerving obedience to the things George taught him. Of Mice and Men represents an experiment in form, which Steinbeck described as "a kind of playable novel, written in a novel form but so scened and set that it can be played as it stands." A rarity in American letters, it achieved remarkable success as a novel, a Broadway play, and three acclaimed films. This Centennial edition, specially designed to commemorate one hundred years of Steinbeck, features french flaps and deckle-edged pages. For more than sixty-five years, Penguin has been the leading publisher of classic literature in the English-speaking world. With more than 1,500 titles, Penguin Classics represents a global bookshelf of the best works throughout history and across genres and disciplines. Readers trust the series to provide authoritative texts enhanced by introductions and notes by distinguished scholars and contemporary authors, as well as up-to-date translations by award-winning translators.') # whew
  33.  
  34. self.description.setWordWrap(True)
  35. self.holdButton = QtWidgets.QPushButton('HOLD')
  36. self.holdButton.setMinimumWidth(100)
  37. self.holdButton.setMaximumWidth(100)
  38. self.holdButton.clicked.connect(self.placeHold)
  39. self.holdButton.setStyleSheet('QPushButton {background-color: white; color: #1369ff; border: 2px solid #1369ff; border-radius: 6px; height: 25px;} QPushButton::pressed {background-color: #1369ff; color: white; border: 2px solid #1369ff; border-radius: 6px;}')
  40.  
  41. self.bookitemLayout_Root = QtWidgets.QHBoxLayout() ## for everything (put cover in as 1, title/author/desc widget as 2, hold button as 3)
  42. self.bookitemLayout_Root.addWidget(self.cover)
  43.  
  44. self.bookitemLayout_Info = QtWidgets.QVBoxLayout()
  45. self.bookitemLayout_Info.addWidget(self.title)
  46. self.bookitemLayout_Info.addWidget(self.author)
  47. self.bookitemLayout_Info.addWidget(self.description)
  48. self.bookitemLayout_Root.setAlignment(Qt.AlignTop)
  49.  
  50. self.description.setAlignment(Qt.AlignTop)
  51.  
  52. self.bookitemLayout_InfoWidget = QtWidgets.QWidget()
  53. self.bookitemLayout_InfoWidget.setLayout(self.bookitemLayout_Info)
  54. self.bookitemLayout_Root.addWidget(self.bookitemLayout_InfoWidget)
  55.  
  56. self.bookitemLayout_Root.addWidget(self.holdButton)
  57.  
  58. self.setLayout(self.bookitemLayout_Root)
  59.  
  60. self.setStyleSheet('{border: 3px solid grey; border-radius: 7px; background-color: white;}')
  61. self.show()
  62.  
  63. def placeHold(self):
  64. self.holdButton.setStyleSheet('QPushButton {background-color: white; color: #00cb0e; border: 2px solid #00cb0e; border-radius: 6px; height: 25px;}')
  65. self.holdButton.setText('HOLD PLACED')
  66. self.holdButton.setEnabled(False)
  67.  
  68.  
  69. class ElideTextLabel(QtWidgets.QLabel):
  70. def paintEvent( self, event ):
  71. painter = QtGui.QPainter(self)
  72.  
  73. metrics = QtGui.QFontMetrics(self.font())
  74. elided = metrics.elidedText(self.text(), Qt.ElideRight, self.width())
  75.  
  76. painter.drawText(self.rect(), self.alignment(), elided)
  77.  
  78.  
  79.  
  80. if __name__ == '__main__':
  81. global app, window
  82. app = QtWidgets.QApplication(sys.argv)
  83.  
  84. window = Window()
  85. window.show()
  86. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement