]> code.delx.au - offlineimap/commitdiff
/offlineimap/head: changeset 300
authorjgoerzen <jgoerzen>
Sun, 5 Jan 2003 04:51:17 +0000 (05:51 +0100)
committerjgoerzen <jgoerzen>
Sun, 5 Jan 2003 04:51:17 +0000 (05:51 +0100)
Beginnings of support for a curses-based Blinkenlights.

offlineimap/head/offlineimap/ui/Blinkenlights.py [new file with mode: 0644]
offlineimap/head/offlineimap/ui/Curses.py [new file with mode: 0644]
offlineimap/head/offlineimap/ui/__init__.py

diff --git a/offlineimap/head/offlineimap/ui/Blinkenlights.py b/offlineimap/head/offlineimap/ui/Blinkenlights.py
new file mode 100644 (file)
index 0000000..c499f64
--- /dev/null
@@ -0,0 +1,73 @@
+# Blinkenlights base classes
+# Copyright (C) 2003 John Goerzen
+# <jgoerzen@complete.org>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+class BlinkenBase:
+    """This is a mix-in class that should be mixed in with either UIBase
+    or another appropriate base class.  The Tk interface, for instance,
+    will probably mix it in with VerboseUI."""
+
+    def isusable(s):
+        "This class is not usable by itself; please override this."
+        return 0
+
+    def acct(s, accountname):
+        s.gettf().setcolor('purple')
+        s.__class__.__bases__[-1].acct(s, accountname)
+
+    def connecting(s, hostname, port):
+        s.gettf().setcolor('gray')
+        s.__class__.__bases__[-1].connecting(s, hostname, port)
+
+    def syncfolders(s, srcrepos, destrepos):
+        s.gettf().setcolor('blue')
+        s.__class__.__bases__[-1].syncfolders(s, srcrepos, destrepos)
+
+    def syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder):
+        s.gettf().setcolor('cyan')
+        s.__class__.__bases__[-1].syncingfolder(s, srcrepos, srcfolder, destrepos, destfolder)
+
+    def loadmessagelist(s, repos, folder):
+        s.gettf().setcolor('green')
+        s._msg("Scanning folder [%s/%s]" % (s.getnicename(repos),
+                                            folder.getvisiblename()))
+
+    def syncingmessages(s, sr, sf, dr, df):
+        s.gettf().setcolor('blue')
+        s.__class__.__bases__[-1].syncingmessages(s, sr, sf, dr, df)
+
+    def copyingmessage(s, uid, src, destlist):
+        s.gettf().setcolor('orange')
+        s.__class__.__bases__[-1].copyingmessage(s, uid, src, destlist)
+
+    def deletingmessages(s, uidlist, destlist):
+        s.gettf().setcolor('red')
+        s.__class__.__bases__[-1].deletingmessages(s, uidlist, destlist)
+
+    def deletingmessage(s, uid, destlist):
+        s.gettf().setcolor('red')
+        s.__class__.__bases__[-1].deletingmessage(s, uid, destlist)
+
+    def addingflags(s, uid, flags, destlist):
+        s.gettf().setcolor('yellow')
+        s.__class__.__bases__[-1].addingflags(s, uid, flags, destlist)
+
+    def deletingflags(s, uid, flags, destlist):
+        s.gettf().setcolor('pink')
+        s.__class__.__bases__[-1].deletingflags(s, uid, flags, destlist)
+
+
diff --git a/offlineimap/head/offlineimap/ui/Curses.py b/offlineimap/head/offlineimap/ui/Curses.py
new file mode 100644 (file)
index 0000000..0f122d1
--- /dev/null
@@ -0,0 +1,116 @@
+# Curses-based interfaces
+# Copyright (C) 2003 John Goerzen
+# <jgoerzen@complete.org>
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program; if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+from Blinkenlights import BlinkenBase
+from UIBase import UIBase
+from threading import *
+
+import curses, curses.panel, curses.textpad, curses.wrapper
+
+class CursesUtil:
+    def __init__(self):
+        self.pairs = {self._getpairindex(curses.COLOR_WHITE,
+                                         curses.COLOR_BLACK): 0}
+        self.start()
+        self.nextpair = 1
+        self.pairlock = Lock()
+
+    def _getpairindex(self, fg, bg):
+        return '%d/%d' % (fg,bg)
+
+    def getpair(self, fg, bg):
+        pindex = self._getpairindex(fg, bg)
+        self.pairlock.acquire()
+        try:
+            if self.pairs.has_key(pindex):
+                return curses.color_pair(self.pairs[pindex])
+            else:
+                self.pairs[pindex] = self.nextpair
+                curses.init_pair(self.nextpair, fg, bg)
+                self.nextpair += 1
+                return curses.color_pair(self.nextpair - 1)
+        finally:
+            self.pairlock.release()
+    
+    def start(self):
+        self.stdscr = curses.initscr()
+        curses.noecho()
+        curses.cbreak()
+        self.stdscr.keypad(1)
+        try:
+            curses.start_color()
+            self.has_color = curses.has_colors()
+        except:
+            self.has_color = 0
+
+        self.stdscr.clear()
+        self.stdscr.refresh()
+        (self.height, self.width) = self.stdscr.getmaxyx()
+
+    def stop(self):
+        self.stdscr.keypad(0)
+        curses.nocbreak()
+        curses.echo()
+        curses.endwin()
+        del self.stdscr
+
+    #def resize(self):
+        
+if __name__ == '__main__':
+    fgs = {'black': curses.COLOR_BLACK, 'red': curses.COLOR_RED,
+           'green': curses.COLOR_GREEN, 'yellow': curses.COLOR_YELLOW,
+           'blue': curses.COLOR_BLUE, 'magenta': curses.COLOR_MAGENTA,
+           'cyan': curses.COLOR_CYAN, 'white': curses.COLOR_WHITE}
+    
+    x = CursesUtil()
+    win1 = curses.newwin(x.height, x.width / 4 - 1, 0, 0)
+    win1.addstr("Black/normal\n")
+    for name, fg in fgs.items():
+        win1.addstr("%s\n" % name, x.getpair(fg, curses.COLOR_BLACK))
+    win2 = curses.newwin(x.height, x.width / 4 - 1, 0, win1.getmaxyx()[1])
+    win2.addstr("Blue/normal\n")
+    for name, fg in fgs.items():
+        win2.addstr("%s\n" % name, x.getpair(fg, curses.COLOR_BLUE))
+    win3 = curses.newwin(x.height, x.width / 4 - 1, 0, win1.getmaxyx()[1] +
+                         win2.getmaxyx()[1])
+    win3.addstr("Black/bright\n")
+    for name, fg in fgs.items():
+        win3.addstr("%s\n" % name, x.getpair(fg, curses.COLOR_BLACK) | \
+                    curses.A_BOLD)
+    win4 = curses.newwin(x.height, x.width / 4 - 1, 0, win1.getmaxyx()[1] * 3)
+    win4.addstr("Blue/bright\n")
+    for name, fg in fgs.items():
+        win4.addstr("%s\n" % name, x.getpair(fg, curses.COLOR_BLUE) | \
+                    curses.A_BOLD)
+        
+        
+    win1.refresh()
+    win2.refresh()
+    win3.refresh()
+    win4.refresh()
+    x.stdscr.refresh()
+    import time
+    time.sleep(40)
+    x.stop()
+    print x.has_color
+    print x.height
+    print x.width
+
+#class Blinkenlights(BlinkenBase, UIBase):
+#    def init_banner(s):
+        
index 4734f786cdfa02676aa10fd0ef480f6e8cdbe587..255efa14adb35b31cd38b5368ca55b5f6f7d992a 100644 (file)
@@ -17,7 +17,7 @@
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-import UIBase
+import UIBase, BlinkenBase
 try:
     import TTY
 except ImportError: