def run(self): gflags = curses.A_BOLD width = self._width self._win = curses.newwin(3, width, self.y, self.x) self._win.border() if self._title: width = ( self._win.getmaxyx()[1] - 2 ) # TODO: I don't know why it needs to be "-2" but it does not work otherwise center = (width / 2) - (len(self._title) / 2) + 1 self._win.addstr(0, center, encode_string(self._title), gflags) self._win.refresh() self._win2 = curses.newwin(1, width, self.y + 1, self.x + 1) curses.curs_set(1) while self._running: self.refresh() self._win2.keypad(1) char = self._win2.getch() self.validator(char) curses.curs_set(0) self._win.erase() self._win.refresh()
def refresh(self): width = self.text_length() + 2 gflags = curses.A_BOLD self._win = curses.newwin( 3, width, self._y, self._x) self._win.border() swidth = self._win.getmaxyx()[1] - 2 # TODO: I don't know why it needs to be "-2" but it does not work otherwise if self._title: center = ( swidth/2 ) - ( len(self._title)/2 ) + 1 self._win.addstr( 0, center, encode_string(self._title), gflags ) self._win.refresh() self._win2 = curses.newpad( 1, swidth + 1) try: self._win2.addstr( 0, 0, encode_string(self.text), curses.A_BOLD ) except curses.error, er: raise RuntimeError( self.text )
def fill(self): if self._main != None: self._main.clear() self.refresh() sql = SQL_MSG(self._user.ggnumber) query = 'select *, strftime( "%H:%M:%S", time) as showtime from msg where strftime( "%Y-%m-%d", time)=:time order by time asc;' tab = { 'time': self._time, } ret = sql.execute(query, tab) list = ret.fetchall() (maxy, maxx) = self._get_main_size() max = maxx lines = [] for obj in list: if obj['type'] in [ 'chatrecvign', 'msgrecvign', 'chatrecv', 'chatrcv', 'msgrecv', 'msgrcv' ]: text = u"%(showtime)s <%(nick)s> %(msg)s" % { 'showtime': obj['showtime'], 'nick': obj['nick'], 'msg': obj['msg'], } elif obj['type'] in ['chatsend', 'msgsend']: text = u"%(showtime)s <ME> %(msg)s" % { 'showtime': obj['showtime'], 'msg': obj['msg'], } else: text = u"%(showtime)s * %(nick)s - %(status)s: %(descr)s" % { 'showtime': obj['showtime'], 'nick': obj['nick'], 'status': obj['status'], 'descr': obj['descr'], } text = text.replace('\r', '') tmp_lines = text.split('\n') for tmp_line in tmp_lines: tmp_line = tmp_line.strip() while len(tmp_line) > max: lines.append(tmp_line[:max]) tmp_line = tmp_line[max:] lines.append(tmp_line) self._maxlines = len(lines) + 1 self._main = curses.newpad(self._maxlines, 255) loop = -1 for line in lines: try: loop += 1 self._main.addstr(loop, 0, encode_string(line)) except: pass self.update_percent()
def refresh(self): width = self.text_length() + 2 gflags = curses.A_BOLD self._win = curses.newwin(3, width, self._y, self._x) self._win.border() swidth = ( self._win.getmaxyx()[1] - 2 ) # TODO: I don't know why it needs to be "-2" but it does not work otherwise if self._title: center = (swidth / 2) - (len(self._title) / 2) + 1 self._win.addstr(0, center, encode_string(self._title), gflags) self._win.refresh() self._win2 = curses.newpad(1, swidth + 1) try: self._win2.addstr(0, 0, encode_string(self.text), curses.A_BOLD) except curses.error, er: raise RuntimeError(self.text)
def _set_title(self, title): (maxy,maxx) = get_stdscr().getmaxyx() if title == None: self._title = None else: if self._title != None: self._title.clear() self._title = curses.newwin( 1, maxx, 0, 0 ) title = encode_string(title.strip()) center = ( maxx / 2 ) - ( len(title) / 2 ) flags = curses.color_pair(Colors.title ) self._title.bkgd( ' ', flags ) self._title.addstr( 0, center, title )
def fill(self): if self._main != None: self._main.clear() self.refresh() sql = SQL_MSG(self._user.ggnumber) query = 'select *, strftime( "%H:%M:%S", time) as showtime from msg where strftime( "%Y-%m-%d", time)=:time order by time asc;' tab = {"time": self._time} ret = sql.execute(query, tab) list = ret.fetchall() (maxy, maxx) = self._get_main_size() max = maxx lines = [] for obj in list: if obj["type"] in ["chatrecvign", "msgrecvign", "chatrecv", "chatrcv", "msgrecv", "msgrcv"]: text = u"%(showtime)s <%(nick)s> %(msg)s" % { "showtime": obj["showtime"], "nick": obj["nick"], "msg": obj["msg"], } elif obj["type"] in ["chatsend", "msgsend"]: text = u"%(showtime)s <ME> %(msg)s" % {"showtime": obj["showtime"], "msg": obj["msg"]} else: text = u"%(showtime)s * %(nick)s - %(status)s: %(descr)s" % { "showtime": obj["showtime"], "nick": obj["nick"], "status": obj["status"], "descr": obj["descr"], } text = text.replace("\r", "") tmp_lines = text.split("\n") for tmp_line in tmp_lines: tmp_line = tmp_line.strip() while len(tmp_line) > max: lines.append(tmp_line[:max]) tmp_line = tmp_line[max:] lines.append(tmp_line) self._maxlines = len(lines) + 1 self._main = curses.newpad(self._maxlines, 255) loop = -1 for line in lines: try: loop += 1 self._main.addstr(loop, 0, encode_string(line)) except: pass self.update_percent()
def fill(self): sql = SQL_MSG(self._user.ggnumber) query = 'select nick from msg where not nick="" group by nick;' ret = sql.execute( query) list = ret.fetchall() self._maxlines = 1 new_list = [ ] for obj in list: self._maxlines += 1 + obj[0].count('\n') new_list.append( obj[0] ) loop = -1 self._main = curses.newpad( self._maxlines, 255 ) for obj in new_list: loop += 1 self._main.addstr( loop, 0, encode_string(obj.strip()) ) if loop == -1: return False else: return True
def fill(self): sql = SQL_MSG(self._user.ggnumber) query = 'select nick from msg where not nick="" group by nick;' ret = sql.execute(query) list = ret.fetchall() self._maxlines = 1 new_list = [] for obj in list: self._maxlines += 1 + obj[0].count('\n') new_list.append(obj[0]) loop = -1 self._main = curses.newpad(self._maxlines, 255) for obj in new_list: loop += 1 self._main.addstr(loop, 0, encode_string(obj.strip())) if loop == -1: return False else: return True
def fill(self): sql = SQL_MSG(self._user.ggnumber) query = 'select descr, strftime( "%Y-%m-%d %H:%M:%S", time) showtime from msg where not descr="" group by descr order by time;' ret = sql.execute(query) list = ret.fetchall() self._maxlines = 1 new_list = [] for obj in list: self._maxlines += 1 new_list.append(obj[1] + ' ' + obj[0]) loop = -1 self._main = curses.newpad(self._maxlines, 255) for obj in new_list: loop += 1 self._main.addstr(loop, 0, encode_string(obj.strip())) if loop == -1: return False else: return True
def fill(self): sql = SQL_MSG(self._user.ggnumber) query = 'select descr, strftime( "%Y-%m-%d %H:%M:%S", time) showtime from msg where not descr="" group by descr order by time;' ret = sql.execute( query ) list = ret.fetchall() self._maxlines = 1 new_list = [ ] for obj in list: self._maxlines += 1 new_list.append( obj[1] +' '+ obj[0] ) loop = -1 self._main = curses.newpad( self._maxlines, 255 ) for obj in new_list: loop += 1 self._main.addstr( loop, 0, encode_string(obj.strip()) ) if loop == -1: return False else: return True
def run(self): gflags = curses.A_BOLD width = self._width self._win = curses.newwin( 3, width, self.y, self.x) self._win.border() if self._title: width = self._win.getmaxyx()[1] - 2 # TODO: I don't know why it needs to be "-2" but it does not work otherwise center = ( width/2 ) - ( len(self._title)/2 ) + 1 self._win.addstr( 0, center, encode_string(self._title), gflags ) self._win.refresh() self._win2 = curses.newwin( 1, width, self.y+1, self.x+1) curses.curs_set(1) while self._running: self.refresh() self._win2.keypad(1) char = self._win2.getch() self.validator( char ) curses.curs_set(0) self._win.erase() self._win.refresh()
def next(self): return encode_string(self.reader.next())
def show(self): self._win.border() for loop in range(len(self._text)): self._win.addstr(loop + 1, 1, encode_string(self._text[loop])) self._win.refresh()
def text(self, obj): """text(self, obj) -> str Zamiana tekstu, na tekst "writable". TODO: what does it mean? """ return encode_string(obj.name)
def show(self): self._win.border() for loop in range( len( self._text ) ): self._win.addstr( loop + 1, 1, encode_string(self._text[loop]) ) self._win.refresh()