示例#1
0
    def __init__(self, client, board):
        Screen.__init__(self, client, 'bbs')
        self.size = [client.columns, client.rows]
        self.board = self.loadBoard(board)
        self.header = Label()
        self.header.label = u"""     ___       __   _     
    / / |__   / /__| |__  
   / /| '_ \ / / _ \ '_ \ 
  / / | |_) / /  __/ | | |
 /_/  |_.__/_/ \___|_| |_|"""
        self.header.pack()
        self.header.position = [0,0]
        self.header.setBackground(Canvas.COLOR_BLUE)
        self.addChild(self.header)
        self.threads = {}
        self.dirty = False
        self.lastpoll = 0
        self.newthreadpane = Panel()
        self.newthreadpane.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.position = [6,6]
        self.addChild(self.newthreadpane)
        t = Label('Name:')
        t.pack()
        t.position = [0,0]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        
        self.name = TextField()
        self.name.size = [15,1]
        self.name.position = [5,0]
        self.newthreadpane.addChild(self.name)
        
        t = Label('Betreff:')
        t.pack()
        t.position = [21,0]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        self.topic = TextField()
        self.topic.size = [15,1]
        self.topic.position = [29,0]
        self.newthreadpane.addChild(self.topic)
        
        t = Label('Text:')
        t.pack()
        t.position = [0,3]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        self.text = TextArea()
        self.text.size = [40,10]
        self.text.position = [5,3]
        self.newthreadpane.addChild(self.text)
        
        self.sendbutton = Button('Senden')
        self.sendbutton.size = [10,1]
        self.sendbutton.position = [5,14]
        self.sendbutton.onPress = self.newThread
        self.sendbutton.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(self.sendbutton)
        self.scrollpane = ScrollPane()
        self.scrollpane.size = [self.size[0],0]
        self.scrollpane.position = [0,18]
        self.scrollpane.setBackground(Canvas.COLOR_BLUE)
        self.addChild(self.scrollpane)
        self.setBackground(Canvas.COLOR_BLUE)
        self.repaint()
示例#2
0
class Board(Screen):
    
    def __init__(self, client, board):
        Screen.__init__(self, client, 'bbs')
        self.size = [client.columns, client.rows]
        self.board = self.loadBoard(board)
        self.header = Label()
        self.header.label = u"""     ___       __   _     
    / / |__   / /__| |__  
   / /| '_ \ / / _ \ '_ \ 
  / / | |_) / /  __/ | | |
 /_/  |_.__/_/ \___|_| |_|"""
        self.header.pack()
        self.header.position = [0,0]
        self.header.setBackground(Canvas.COLOR_BLUE)
        self.addChild(self.header)
        self.threads = {}
        self.dirty = False
        self.lastpoll = 0
        self.newthreadpane = Panel()
        self.newthreadpane.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.position = [6,6]
        self.addChild(self.newthreadpane)
        t = Label('Name:')
        t.pack()
        t.position = [0,0]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        
        self.name = TextField()
        self.name.size = [15,1]
        self.name.position = [5,0]
        self.newthreadpane.addChild(self.name)
        
        t = Label('Betreff:')
        t.pack()
        t.position = [21,0]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        self.topic = TextField()
        self.topic.size = [15,1]
        self.topic.position = [29,0]
        self.newthreadpane.addChild(self.topic)
        
        t = Label('Text:')
        t.pack()
        t.position = [0,3]
        t.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(t)
        self.text = TextArea()
        self.text.size = [40,10]
        self.text.position = [5,3]
        self.newthreadpane.addChild(self.text)
        
        self.sendbutton = Button('Senden')
        self.sendbutton.size = [10,1]
        self.sendbutton.position = [5,14]
        self.sendbutton.onPress = self.newThread
        self.sendbutton.setBackground(Canvas.COLOR_BLUE)
        self.newthreadpane.addChild(self.sendbutton)
        self.scrollpane = ScrollPane()
        self.scrollpane.size = [self.size[0],0]
        self.scrollpane.position = [0,18]
        self.scrollpane.setBackground(Canvas.COLOR_BLUE)
        self.addChild(self.scrollpane)
        self.setBackground(Canvas.COLOR_BLUE)
        self.repaint()
    
    def loadBoard(self, board):
        return self.client.session.query(sql.Board).filter(sql.Board.name==board).first()
    
    def update(self):
        if time.time()-self.lastpoll > 1:
            self.lastpoll = time.time()
        else:
            return
        self.updateBoard()
        x = 1
        self.scrollpane.size[0] = self.size[0]
        if len(self.threads) > 0:
            for threadid in reversed(sorted(self.threads.keys())):
                if self.threads[threadid].update():
                    self.dirty = True
                self.threads[threadid].position = (2,x)
                x += self.threads[threadid].size[1]+1
            
            if self.dirty:
                print self.dirty
                self.scrollpane.pack()
                self.scrollpane.repaint()
                self.dirty = False

    def updateBoard(self):
        threads = self.board.getThreads(self.client.session)
        for thread in threads:
            if thread.postid not in self.threads.keys():
                tp = ThreadPane(thread)
                self.scrollpane.addChild(tp)
                self.threads[thread.postid] = tp
                self.dirty = True
    
    def newThread(self):
        self.board.addThread(self.client.session, self.name.getValue(), self.topic.getValue(), self.text.getValue())
    
    def paint(self, canvas):
        self.header.position[0] = (self.size[0]-self.header.size[0])/2
        self.scrollpane.size[0] = self.size[0]
        
        if not self.newthreadpane.visible:
            self.scrollpane.size[1] = self.size[1]-6
            self.scrollpane.position[1] = 6
        else:
            self.scrollpane.size[1] = self.size[1]-22
            self.scrollpane.position[1] = 22
        
        Screen.paint(self, canvas)
        canvas.setBackground(self.background)
        canvas.fillBackground()
        
    def onInput(self, command):
        if command == self.canvas.terminfo.tigets('kf1'):
            self.newthreadpane.visible = not self.newthreadpane.visible
            if not self.newthreadpane.visible:
                self.newthreadpane.removeFocus()
            self.repaint()
        if command == self.canvas.terminfo.tigets('kf2'):
            self.name.giveFocus()
        Screen.onInput(self, command)