summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-12-31 17:13:12 +0100
committerhut <hut@lavabit.com>2009-12-31 17:13:12 +0100
commit42fd36907c9d9e4c68634e35e7b5de2c91c9164e (patch)
treea8cb1799eacb31ecfc73c768978097c5288a7677
parent9cce9fab0792ee0ac17ad4355d9af9274159f294 (diff)
downloadranger-42fd36907c9d9e4c68634e35e7b5de2c91c9164e.tar.gz
optimized drawing of widgets (broke notify widget)
-rw-r--r--ranger/gui/defaultui.py3
-rw-r--r--ranger/gui/displayable.py47
-rw-r--r--ranger/gui/ui.py4
-rw-r--r--ranger/gui/widgets/browsercolumn.py36
-rw-r--r--ranger/gui/widgets/console.py1
-rw-r--r--ranger/gui/widgets/statusbar.py33
6 files changed, 90 insertions, 34 deletions
diff --git a/ranger/gui/defaultui.py b/ranger/gui/defaultui.py
index 540d088d..3985b1cc 100644
--- a/ranger/gui/defaultui.py
+++ b/ranger/gui/defaultui.py
@@ -42,6 +42,7 @@ class DefaultUI(UI):
 
 		# Create the pager
 		self.pager = Pager(self.win)
+		self.pager.visible = False
 		self.add_child(self.pager)
 
 	def update_size(self):
@@ -119,8 +120,6 @@ class DefaultUI(UI):
 			self.titlebar.throbber = type(self.titlebar).throbber
 		else:
 			self.titlebar.throbber = string
-	
-#		self.win.addnstr(0, self.env.termsize[1]-1, string, 1)
 
 	def hint(self, text=None):
 		self.status.override = text
diff --git a/ranger/gui/displayable.py b/ranger/gui/displayable.py
index 315d2f7b..c5e1dbac 100644
--- a/ranger/gui/displayable.py
+++ b/ranger/gui/displayable.py
@@ -2,6 +2,7 @@ from ranger.shared import FileManagerAware, EnvironmentAware, SettingsAware
 from ranger import log
 import _curses
 
+
 class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 	"""
 	Displayables are objects which are displayed on the screen.
@@ -32,6 +33,9 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 	Modifiable:
 		focused -- Focused objects receive press() calls.
 		visible -- Visible objects receive draw() and finalize() calls
+		need_redraw -- Should the widget be redrawn? This variable may
+			be set at various places in the script and should eventually be
+			handled (and unset) in the draw() method.
 	
 	Read-Only: (i.e. reccomended not to change manually)
 		win -- the own curses window object
@@ -49,14 +53,18 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		if settings is not None:
 			self.settings = settings
 
+		self.need_redraw = True
 		self.focused = False
 		self.visible = True
 		self.x = 0
 		self.y = 0
 		self.wid = 0
 		self.hei = 0
+		self.paryx = (0, 0)
 		self.parent = None
 
+		self._old_visible = self.visible
+
 		if win is not None:
 			if isinstance(self, UI):
 				self.win = win
@@ -110,7 +118,8 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 		Displayable.color(self, 'reset')
 
 	def draw(self):
-		"""Draw the object. Called on every main iteration.
+		"""
+		Draw the object. Called on every main iteration if visible.
 		Containers should call draw() on their contained objects here.
 		Override this!
 		"""
@@ -142,13 +151,13 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 
 	def poke(self):
 		"""Called before drawing, even if invisible"""
-	
-	def draw(self):
-		"""Draw displayable.  Called on every main iteration if the object
-		is visible.  Override this!
-		"""
-		pass
+		if self._old_visible != self.visible:
+			self._old_visible = self.visible
+			self.need_redraw = True
 
+			if not self.visible:
+				self.win.erase()
+	
 	def finalize(self):
 		"""Called after every displayable is done drawing.
 		Override this!
@@ -184,7 +193,13 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 			if y + hei > maxy:
 				raise OutOfBoundsException("Y out of bounds!")
 
+		window_is_cleared = False
+
 		if hei != self.hei or wid != self.wid:
+			#log("resizing " + str(self))
+			self.win.erase()
+			self.need_redraw = True
+			window_is_cleared = True
 			try:
 				self.win.resize(hei, wid)
 			except:
@@ -199,17 +214,24 @@ class Displayable(EnvironmentAware, FileManagerAware, SettingsAware):
 
 			self.hei, self.wid = self.win.getmaxyx()
 
-		if do_move or y != self.y or x != self.x:
-			log("moving " + self.__class__.__name__)
+		if do_move or y != self.paryx[0] or x != self.paryx[1]:
+			if not window_is_cleared:
+				self.win.erase()
+				self.need_redraw = True
+			#log("moving " + str(self))
 			try:
 				self.win.mvderwin(y, x)
 			except:
 				pass
 
-			self.y, self.x = self.win.getparyx()
+			self.paryx = self.win.getparyx()
+			self.y, self.x = self.paryx
 			if self.parent:
 				self.y += self.parent.y
 				self.x += self.parent.x
+	
+	def __str__(self):
+		return self.__class__.__name__
 
 class DisplayableContainer(Displayable):
 	"""
@@ -245,15 +267,20 @@ class DisplayableContainer(Displayable):
 
 	def poke(self):
 		"""Recursively called on objects in container"""
+		Displayable.poke(self)
 		for displayable in self.container:
 			displayable.poke()
 
 	def draw(self):
 		"""Recursively called on visible objects in container"""
 		for displayable in self.container:
+			if self.need_redraw:
+				displayable.need_redraw = True
 			if displayable.visible:
 				displayable.draw()
 
+		self.need_redraw = False
+
 	def finalize(self):
 		"""Recursively called on visible objects in container"""
 		for displayable in self.container:
diff --git a/ranger/gui/ui.py b/ranger/gui/ui.py
index e609b72d..31ddf61a 100644
--- a/ranger/gui/ui.py
+++ b/ranger/gui/ui.py
@@ -146,9 +146,11 @@ class UI(DisplayableContainer):
 
 	def redraw_window(self):
 		"""Redraw the window. This only calls self.win.redrawwin()."""
+		self.win.erase()
 		self.win.redrawwin()
 		self.win.refresh()
 		self.win.redrawwin()
+		self.need_redraw = True
 
 	def update_size(self):
 		"""Update self.env.termsize.
@@ -158,7 +160,7 @@ class UI(DisplayableContainer):
 
 	def draw(self):
 		"""Erase the window, then draw all objects in the container"""
-		self.win.erase()
+		self.win.touchwin()
 		DisplayableContainer.draw(self)
 		self.win.refresh()
 
diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py
index 055c9843..5427d958 100644
--- a/ranger/gui/widgets/browsercolumn.py
+++ b/ranger/gui/widgets/browsercolumn.py
@@ -11,6 +11,9 @@ class BrowserColumn(Pager, Widget):
 	postpone_drawing = False
 	tagged_marker = '*'
 
+	old_dir = None
+	old_cf = None
+
 	def __init__(self, win, level):
 		Pager.__init__(self, win)
 		Widget.__init__(self, win)
@@ -65,6 +68,7 @@ class BrowserColumn(Pager, Widget):
 		return True
 
 	def poke(self):
+		Widget.poke(self)
 		self.target = self.env.at_level(self.level)
 
 	def draw(self):
@@ -72,15 +76,26 @@ class BrowserColumn(Pager, Widget):
 		from ranger.fsobject.file import File
 		from ranger.fsobject.directory import Directory
 
-#		self.pager.visible = False
-		if self.target is None:
-			pass
-		elif type(self.target) == File:
-			Pager.open(self)
-			self._draw_file()
-		elif type(self.target) == Directory:
-			self._draw_directory()
-			Widget.draw(self)
+		if self.target != self.old_dir:
+			self.need_redraw = True
+			self.old_dir = self.target
+
+		if isinstance(self.target, Directory) \
+				and self.target.pointed_obj != self.old_cf:
+			self.need_redraw = True
+			self.old_cf = self.target.pointed_obj
+
+		if self.need_redraw:
+			self.win.erase()
+			if self.target is None:
+				pass
+			elif type(self.target) == File:
+				Pager.open(self)
+				self._draw_file()
+			elif type(self.target) == Directory:
+				self._draw_directory()
+				Widget.draw(self)
+			self.need_redraw = False
 
 	def _preview_this_file(self, target):
 		return target.document and not self.settings.preview_files
@@ -278,3 +293,6 @@ class BrowserColumn(Pager, Widget):
 		if self.target.scroll_begin == old_value:
 			self.target.move(relative = relative)
 			self.target.scroll_begin += relative
+	
+	def __str__(self):
+		return self.__class__.__name__ + ' at level ' + str(self.level)
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index 22b9831d..11b83417 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -43,6 +43,7 @@ class Console(Widget):
 		if self.mode is None:
 			return
 		
+		self.win.erase()
 		self.addstr(0, 0, self.prompt)
 		self.addstr(self.line)
 
diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py
index b5f3bdce..94e62d0b 100644
--- a/ranger/gui/widgets/statusbar.py
+++ b/ranger/gui/widgets/statusbar.py
@@ -23,7 +23,6 @@ class StatusBar(Widget):
 
 	old_cf = None
 	old_mtime = None
-	old_wid = None
 	result = None
 
 	def __init__(self, win, column=None):
@@ -39,18 +38,28 @@ class StatusBar(Widget):
 
 		if self.override and isinstance(self.override, str):
 			self._draw_message()
-		else:
-			try:
-				mtime = self.env.cf.stat.st_mtime
-			except:
-				mtime = -1
-			if not self.result or self.old_cf != self.env.cf or \
-					mtime != self.old_mtime or self.old_wid != self.wid:
-				self.old_mtime = mtime
-				self.old_cf = self.env.cf
-				self.old_wid = self.wid
-				self._calc_bar()
+			return
+
+		try:
+			mtime = self.env.cf.stat.st_mtime
+		except:
+			mtime = -1
+
+		if not self.result:
+			self.need_redraw = True
+
+		if self.old_cf != self.env.cf:
+			self.old_cf = self.env.cf
+			self.need_redraw = True
+
+		if self.old_mtime != mtime:
+			self.old_mtime = mtime
+			self.need_redraw = True
+
+		if self.need_redraw:
+			self.need_redraw = False
 
+			self._calc_bar()
 			self._print_result(self.result)
 	
 	def _calc_bar(self):
i-tty/blame/src/plugins/plugins.c?id=f887a35c0cd550a3c635630da2bd83bb7400b957'>^
0fc0b3ee ^
03ab8baf ^
41fe8c22 ^



03ab8baf ^






























3bb1f124 ^
88f423af ^
d1c71e98 ^
b3a3351a ^



03ab8baf ^







41fe8c22 ^





03ab8baf ^










46687aec ^
41fe8c22 ^
46687aec ^

03ab8baf ^
41fe8c22 ^
03ab8baf ^
46687aec ^
03ab8baf ^
46687aec ^

03ab8baf ^

46687aec ^
03ab8baf ^
46687aec ^
03ab8baf ^


46687aec ^
03ab8baf ^


46687aec ^
03ab8baf ^


41fe8c22 ^
































































































































































































93672eba ^













699e08b2 ^
93672eba ^





41fe8c22 ^











































































d0397f3d ^




















8933d59b ^

















d0397f3d ^




















8933d59b ^

















d0397f3d ^




















8933d59b ^

















41fe8c22 ^
759d9ccb ^





















271278dd ^










7ca60846 ^









623fbe9e ^





7ca60846 ^
41fe8c22 ^




9b177a9e ^
0fc0b3ee ^



9b177a9e ^
41fe8c22 ^






9b177a9e ^
0fc0b3ee ^

9b177a9e ^
41fe8c22 ^



ac91e7ef ^
a4e6d50a ^
5cabcf9b ^
623fbe9e ^
41fe8c22 ^













1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720