Ejemplo n.º 1
0
Archivo: gui.py Proyecto: piotrj/flapy
    def __init__(self, parent=None, flags=0):
        
        QMainWindow.__init__(self, parent)
        self.flakerService = Flaker()
        
        self.resize(400, 500)
        self.centralWidget = QWidget(self)
        self.centralWidget.setObjectName("centralWidget")
        self.setCentralWidget(self.centralWidget)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
        self.setSizePolicy(sizePolicy)
     
        layout = QGridLayout(self.centralWidget)
        layout.setMargin(0)
        
        
        self.top = TopWidget()
        self.top.setMinimumWidth(400)
        self.top.setObjectName("top")
        self.top.adjustSize()
        self.connect(self.top, QtCore.SIGNAL("goBack"), self.goBack)
        self.connect(self.top, QtCore.SIGNAL("reload"), self.reload)
        layout.addWidget(self.top)
        
        self.scrollArea = QtGui.QScrollArea()
        layout.addWidget(self.scrollArea)
        
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        
        self.loginWidget = LoginWidget(self.flakerService)
        self.connect(self.loginWidget, QtCore.SIGNAL("loggedon"), self.login)
        self.scrollArea.setWidget(self.loginWidget)
        
        self.writeWidget = WriteWidget()
        layout.addWidget(self.writeWidget)
        
        self.connect(self.writeWidget, QtCore.SIGNAL("send(str)"), self.send)
        self.writeWidget.hide()

        f = open("entry.css", "r")
        stylesheet = f.read()
        f.close
        self.setStyleSheet(stylesheet)
Ejemplo n.º 2
0
Archivo: gui.py Proyecto: piotrj/flapy
class Ui_MainWindow(QMainWindow):
    def __init__(self, parent=None, flags=0):
        
        QMainWindow.__init__(self, parent)
        self.flakerService = Flaker()
        
        self.resize(400, 500)
        self.centralWidget = QWidget(self)
        self.centralWidget.setObjectName("centralWidget")
        self.setCentralWidget(self.centralWidget)
        sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred)
        self.setSizePolicy(sizePolicy)
     
        layout = QGridLayout(self.centralWidget)
        layout.setMargin(0)
        
        
        self.top = TopWidget()
        self.top.setMinimumWidth(400)
        self.top.setObjectName("top")
        self.top.adjustSize()
        self.connect(self.top, QtCore.SIGNAL("goBack"), self.goBack)
        self.connect(self.top, QtCore.SIGNAL("reload"), self.reload)
        layout.addWidget(self.top)
        
        self.scrollArea = QtGui.QScrollArea()
        layout.addWidget(self.scrollArea)
        
        self.scrollArea.setWidgetResizable(True)
        self.scrollArea.setObjectName("scrollArea")
        
        self.loginWidget = LoginWidget(self.flakerService)
        self.connect(self.loginWidget, QtCore.SIGNAL("loggedon"), self.login)
        self.scrollArea.setWidget(self.loginWidget)
        
        self.writeWidget = WriteWidget()
        layout.addWidget(self.writeWidget)
        
        self.connect(self.writeWidget, QtCore.SIGNAL("send(str)"), self.send)
        self.writeWidget.hide()

        f = open("entry.css", "r")
        stylesheet = f.read()
        f.close
        self.setStyleSheet(stylesheet)
        

    def createEntryListWidget(self):
      self.entryListContainer = QWidget()
      sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
      self.entryListContainer.setSizePolicy(sizePolicy)
      self.entryListContainer.setSizeIncrement(QtCore.QSize(0, 10))
      self.entryListContainer.setBaseSize(QtCore.QSize(300, 100))
      self.entryListContainer.setObjectName("container")
      self.entryListLayout = QVBoxLayout(self.entryListContainer)
      self.entryListLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
      self.entryListLayout.setObjectName("entryListLayout")
      self.entryListLayout.setMargin(0)

      self.entrywidgets = []

      # entries = flakerService.getNewEntries("piotrj")
      entries = self.flakerService.friends(self.flakerService.login)
      
      for entry in entries:
        widget = EntryWidget(entry, self.entryListContainer)
        self.entrywidgets.append(widget)
        self.entryListLayout.addWidget(widget)
        self.connect(widget, QtCore.SIGNAL("doubleClick(str)"), self.doubleClick)
        self.connect(widget, QtCore.SIGNAL("comment(str)"), self.comment)
        
      self.entryListContainer.adjustSize()

  
    def createEntryDetailWidget(self, id):
      self.detailContainer = QWidget()
      sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
      self.detailContainer.setSizePolicy(sizePolicy)
      self.detailContainer.setSizeIncrement(QtCore.QSize(0, 10))
      self.detailContainer.setBaseSize(QtCore.QSize(400, 100))
      self.detailContainer.setObjectName("container")   
      self.detailLayout = QVBoxLayout(self.detailContainer)
      self.detailLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize)
      self.detailLayout.setObjectName("detailLayout")
      self.detailLayout.setMargin(0)

      entry = self.flakerService.show(id)

      self.detailwidgets = []
      widget = EntryWidget(entry, False, self.detailContainer)
      self.detailwidgets.append(widget)
      self.detailLayout.addWidget(widget)
      
      self.commentLabel = QLabel()
      self.commentLabel.setText("Komentarze")
      
      self.detailLayout.addWidget(self.commentLabel)

      for comment in entry.comments:
        widget = EntryWidget(comment, False, self.detailContainer)
        self.detailwidgets.append(widget)
        self.detailLayout.addWidget(widget)   
        
    def doubleClick(self, id):
      self.createEntryDetailWidget(id)
      self.comment(id)
      self.entryListContainer.hide()
      self.scrollArea.takeWidget()
      self.scrollArea.setWidget(self.detailContainer)
      self.top.backButton.show()
    
    def login(self):
      self.createEntryListWidget()
      self.scrollArea.takeWidget()
      self.scrollArea.setWidget(self.entryListContainer)
      self.entryListContainer.adjustSize()
      del self.loginWidget
      
      self.centralWidget.adjustSize()
      self.centralWidget.setFixedWidth(self.centralWidget.sizeHint().width()+15)
      self.centralWidget.setMaximumWidth(self.centralWidget.width())
      self.writeWidget.show()
      
    def goBack(self):
      self.scrollArea.setWidget(self.entryListContainer)
      self.top.backButton.hide()
      del self.detailwidgets
      del self.detailContainer
      
    def comment(self, id):
      self.writeWidget.plainTextEdit.clear()
      self.writeWidget.plainTextEdit.appendPlainText("@"+id)
      
    def send(self, msg):
      # message = self.writeWidget.plainTextEdit.text()
      self.flakerService.submit(text=unicode(msg))
      # print msg
      self.writeWidget.plainTextEdit.clear()
    
    def reload(self):
      self.scrollArea.takeWidget()
      del self.entryListContainer
      self.createEntryListWidget()
      self.scrollArea.setWidget(self.entryListContainer)