summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-18 02:41:05 +0100
committerhut <hut@lavabit.com>2009-12-18 02:41:05 +0100
commita923ead7fbc5dcb0593a6756828202719373c3cc (patch)
treee9c7f9f0da336d5288a87576195637ef5bec4abd
parente85d44ae0eac49d21818d4cdd3972eb89f6ffd37 (diff)
downloadranger-a923ead7fbc5dcb0593a6756828202719373c3cc.tar.gz
notification widget
-rw-r--r--ranger/colorschemes/default.py16
-rw-r--r--ranger/gui/colorscheme.py3
-rw-r--r--ranger/gui/defaultui.py19
-rw-r--r--ranger/gui/displayable.py7
-rw-r--r--ranger/gui/widgets/notify.py72
5 files changed, 110 insertions, 7 deletions
diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py
index ba78142d..4f7e5498 100644
--- a/ranger/colorschemes/default.py
+++ b/ranger/colorschemes/default.py
@@ -26,14 +26,14 @@ class Default(ColorScheme):
 			if context.container:
 				fg = red
 
-			if context.document:
-				fg = default
+#			if context.document:
+#				fg = default
 
 			if context.directory:
 				fg = blue
 
 			elif context.executable and not \
-					any((context.media, context.container, context.document)):
+					any((context.media, context.container)):
 				attr |= bold
 				fg = green
 
@@ -62,4 +62,14 @@ class Default(ColorScheme):
 				elif context.bad:
 					fg = magenta
 
+		elif context.in_notify:
+			attr |= reverse
+#			if context.good:
+#				bg = cyan
+#			else:
+#				bg = red
+#			if context.message:
+#				attr |= bold
+#				fg = white
+
 		return fg, bg, attr
diff --git a/ranger/gui/colorscheme.py b/ranger/gui/colorscheme.py
index 7105adc0..d8dbc927 100644
--- a/ranger/gui/colorscheme.py
+++ b/ranger/gui/colorscheme.py
@@ -1,9 +1,10 @@
 CONTEXT_KEYS = [ 'reset', 'error',
 		'in_display', 'in_statusbar', 'in_titlebar', 'in_console',
+		'in_notify',
 		'directory', 'file', 'hostname',
 		'executable', 'media', 'link',
 		'video', 'audio', 'image', 'media', 'document', 'container',
-		'selected', 'empty', 'maindisplay',
+		'selected', 'empty', 'maindisplay', 'message', 'background',
 		'good', 'bad',
 		'space', 'permissions', 'owner', 'group', 'mtime', 'nlink',
 		'scroll', 'all', 'bot', 'top', 'percentage',
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index 24cc6b38..ccfe960d 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -1,5 +1,6 @@
 
 RATIO = ( 3, 3, 12, 9 )
+from ranger import log
 
 from ranger.gui.ui import UI
 class DefaultUI(UI):
@@ -9,6 +10,7 @@ class DefaultUI(UI):
 		from ranger.gui.widgets.titlebar import TitleBar
 		from ranger.gui.widgets.console import Console
 		from ranger.gui.widgets.statusbar import StatusBar
+		from ranger.gui.widgets.notify import Notify
 		self.titlebar = TitleBar(self.win)
 		self.add_obj(self.titlebar)
 
@@ -22,15 +24,30 @@ class DefaultUI(UI):
 		self.add_obj(self.console)
 		self.console.visible = False
 
+		self.notify = Notify(self.win)
+		self.add_obj(self.notify)
+
 	def update_size(self):
 		"""resize all widgets"""
 		UI.update_size(self)
 		y, x = self.env.termsize
 
-		self.filelist_container.resize(1, 0, y - 2, x)
+		notify_hei = self.notify.requested_height
+		log(notify_hei)
+
+		self.filelist_container.resize(1, 0, y - 2 - notify_hei, x)
+		self.notify.resize(y - 1 - notify_hei, 0, notify_hei, x)
 		self.titlebar.resize(0, 0, 1, x)
 		self.status.resize(y - 1, 0, 1, x)
 		self.console.resize(y - 1, 0, 1, x)
+	
+	def poke(self):
+		UI.poke(self)
+		if self.notify.requested_height != self.notify.hei:
+			self.update_size()
+	
+	def display(self, *a, **k):
+		return self.notify.display(*a, **k)
 
 	def open_console(self, mode, string=''):
 		if self.console.open(mode, string):
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index 9375be11..e3191cdb 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -105,8 +105,11 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		except TypeError:
 			pass
 		else:
-			wid = wid or maxx - x
-			hei = hei or maxy - y
+			if hei is None:
+				hei = maxy - y
+
+			if wid is None:
+				wid = maxx - x
 
 			if x < 0 or y < 0:
 				raise OutOfBoundsException("Starting point below zero!")
diff --git a/ranger/gui/widgets/notify.py b/ranger/gui/widgets/notify.py
new file mode 100644
index 00000000..2dc56fb1
--- /dev/null
+++ b/ranger/gui/widgets/notify.py
@@ -0,0 +1,72 @@
+"""Notify is a bar which displays messages."""
+
+from . import Widget
+from time import time
+from collections import deque
+from ranger import log
+
+class Notify(Widget):
+	requested_height = 0
+	max_size = 5
+	textcontainer = None
+
+	def __init__(self, win):
+		Widget.__init__(self, win)
+		self.textcontainer = deque(maxlen=self.max_size)
+
+	def poke(self):
+		for i in reversed(range(len(self.textcontainer))):
+			msg = self.textcontainer[i]
+			if msg.elapse and time() > msg.elapse:
+				msg.alive = False
+				del self.textcontainer[i]
+		self.requested_height = len(self.textcontainer)
+
+	def draw(self):
+		import curses, socket, os
+		self.win.move(self.y, self.x)
+
+		i = 0
+		for msg in self.textcontainer:
+			if i >= self.hei:
+				break
+
+			how = msg.bad and 'bad' or 'good'
+			self.color_at(self.y + i, self.x, self.wid,\
+					'in_notify', 'background', how)
+			self.color('in_notify', 'message', how)
+			self.win.addnstr(self.y + i, self.x, msg.text, self.wid)
+			i += 1
+
+		self.color_reset()
+	
+	def display(self, text, duration=4, bad=False):
+		msg = Message(self.textcontainer, text, duration, bad)
+		self.textcontainer.append(msg)
+		return msg
+
+class Message(object):
+	elapse = None
+	text = None
+	bad = False
+	alive = True
+	container = None
+
+	def __init__(self, container, text, duration, bad):
+		self.text = text
+		self.bad = bad
+		self.container = container
+		self.set_duration(duration)
+	
+	def set_duration(self, n=4):
+		if n:
+			self.elapse = time() + n
+		else:
+			self.elapse = None
+
+	def delete(self):
+		self.alive = False
+		try:
+			self.container.remove(self)
+		except ValueError:
+			pass