about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-29 17:46:27 +0100
committerhut <hut@lavabit.com>2009-12-29 17:46:27 +0100
commit17f83af2f8ff958022902013b84f20b9eb9c3b70 (patch)
treef2759e1c5886932fb6473d70c78b456f9894ed28 /ranger
parent23c450bf891ddf1da7ebee326e7fb1248448e84c (diff)
downloadranger-17f83af2f8ff958022902013b84f20b9eb9c3b70.tar.gz
a somewhat working version
Diffstat (limited to 'ranger')
-rw-r--r--ranger/gui/displayable.py27
-rw-r--r--ranger/gui/widgets/console.py4
-rw-r--r--ranger/gui/widgets/filelist.py41
3 files changed, 39 insertions, 33 deletions
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index 6ce81df5..442a7d35 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -18,8 +18,6 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 
 		self.x = 0
 		self.y = 0
-		self.yy = 0
-		self.xx = 0
 		self.absx = 0
 		self.absy = 0
 		self.wid = 0
@@ -51,6 +49,12 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		
 		return self.contains_point(y, x)
 
+	def addstr(self, *args):
+		try:
+			self.win.addstr(*args)
+		except:
+			pass
+	
 	def color(self, keylist = None, *keys):
 		"""Change the colors from now on."""
 		keys = combine(keylist, keys)
@@ -122,6 +126,7 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 
 	def resize(self, y, x, hei=None, wid=None):
 		"""Resize the widget"""
+		do_move = False
 		try:
 			maxy, maxx = self.env.termsize
 		except TypeError:
@@ -150,31 +155,31 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 
 		if hei != self.hei or wid != self.wid:
 			try:
+				log("resizing " + self.__class__.__name__)
 				self.win.resize(hei, wid)
 			except:
 				# Not enough space for resizing...
 				try:
 					self.win.mvderwin(0, 0)
-					self.absy, self.absx = self.win.getbegyx()
+					do_move = True
 					self.win.resize(hei, wid)
 				except:
 					pass
 					#raise OutOfBoundsException("Resizing Failed!")
 
-		if y != self.absy or x != self.absx:
+		if do_move or  y != self.absy or x != self.absx:
+			log("moving " + self.__class__.__name__)
 			try:
 				self.win.mvderwin(y, x)
 			except:
 				pass
 
-		self.yy, self.xx = y, x
-		if self.parent:
-			self.yy += self.parent.yy
-			self.xx += self.parent.xx
+			self.absy, self.absx = y, x
+			if self.parent:
+				self.absy += self.parent.absy
+				self.absx += self.parent.absx
 
-		self.absy, self.absx = self.win.getbegyx()
-		self.x = 0
-		self.y = 0
+		self.y, self.x = self.win.getbegyx()
 		self.hei, self.wid = self.win.getmaxyx()
 
 
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 52a8963b..ffabefcc 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -42,7 +42,9 @@ class Console(Widget):
 	def draw(self):
 		if self.mode is None:
 			return
-		self.win.addstr(self.y, self.x, self.prompt + self.line)
+		
+		self.addstr(0, 0, self.prompt)
+		self.addstr(self.line)
 
 	def finalize(self):
 		try:
diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py
index 43f3834a..f38b4bee 100644
--- a/ranger/gui/widgets/filelist.py
+++ b/ranger/gui/widgets/filelist.py
@@ -33,7 +33,7 @@ class FileList(Widget, DisplayableContainer):
 			pass
 
 		elif self.target.type is T_DIRECTORY:
-			index = self.scroll_begin + event.y - self.yy
+			index = self.scroll_begin + event.y - self.absy
 
 			if event.pressed(1):
 				if not self.main_display:
@@ -96,8 +96,9 @@ class FileList(Widget, DisplayableContainer):
 
 	def draw_file(self):
 		"""Draw a preview of the file, if the settings allow it"""
+		self.win.move(0, 0)
 		if not self.target.accessible:
-			self.win.addnstr(self.y, self.x, "not accessible", self.wid)
+			self.win.addnstr("not accessible", self.wid)
 			return
 
 		if not self._preview_this_file(self.target):
@@ -120,6 +121,8 @@ class FileList(Widget, DisplayableContainer):
 
 		self.target.use()
 
+		self.win.move(0, 0)
+
 		if not self.target.load_content_if_outdated():
 			self.target.sort_if_outdated()
 
@@ -139,19 +142,19 @@ class FileList(Widget, DisplayableContainer):
 					and self.target.accessible \
 					and self.target.size > maxdirsize:
 				self.color(base_color, 'error')
-				self.win.addnstr(self.y, self.x, "no preview", self.wid)
+				self.win.addnstr("no preview", self.wid)
 				self.color_reset()
 				return
 
 			if self.settings.auto_load_preview:
 				self.color(base_color)
-				self.win.addnstr(self.y, self.x, "...", self.wid)
+				self.win.addnstr("...", self.wid)
 				self.postpone_drawing = True
 				self.color_reset()
 				return
 			else:
 				self.color(base_color, 'error')
-				self.win.addnstr(self.y, self.x, "not loaded", self.wid)
+				self.win.addnstr("not loaded", self.wid)
 				self.color_reset()
 				return
 
@@ -160,13 +163,13 @@ class FileList(Widget, DisplayableContainer):
 
 		if not self.target.accessible:
 			self.color(base_color, 'error')
-			self.win.addnstr(self.y, self.x, "not accessible", self.wid)
+			self.win.addnstr("not accessible", self.wid)
 			self.color_reset()
 			return
 
 		if self.target.empty():
 			self.color(base_color, 'empty')
-			self.win.addnstr(self.y, self.x, "empty", self.wid)
+			self.win.addnstr("empty", self.wid)
 			self.color_reset()
 			return
 
@@ -212,31 +215,27 @@ class FileList(Widget, DisplayableContainer):
 			try:
 				if self.main_display:
 					if tagged:
-						if self.wid > 1:
-							self.win.addnstr(self.y + line, self.x,
-									text, self.wid - 2)
-					elif self.wid > 2:
-						self.win.addnstr(self.y + line, self.x + 1,
-								text, self.wid - 2)
+						self.win.addnstr(line, 0, text, self.wid - 2)
+					elif self.wid > 1:
+						self.win.addnstr(line, 1, text, self.wid - 2)
 				else:
-					self.win.addnstr(self.y + line, self.x, text, self.wid)
+					self.win.addnstr(line, 0, text, self.wid)
 
 				if self.display_infostring and drawed.infostring:
 					info = drawed.infostring
-					x = self.x + self.wid - 1 - len(info)
+					x = self.wid - 1 - len(info)
 					if x > self.x:
-						self.win.addstr(self.y + line, x, str(info) + ' ')
+						self.win.addstr(line, x, str(info) + ' ')
 			except:
-				# the last string will cause an error because
-				# ncurses tries to move out of the bounds
+				# the drawing of the last string will cause an error
+				# because ncurses tries to move out of the bounds
 				pass
 
-			self.color_at(self.y + line, self.x, self.wid, this_color)
+			self.color_at(line, 0, self.wid, this_color)
 
 			if self.main_display and tagged and self.wid > 2:
 				this_color.append('tag_marker')
-				self.color_at(self.y + line, self.x,
-						len(self.tagged_marker), this_color)
+				self.color_at(line, 0, len(self.tagged_marker), this_color)
 
 			self.color_reset()