about summary refs log tree commit diff stats
path: root/dwm.png
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-05-07 13:14:55 +0200
committerAnselm R. Garbe <arg@suckless.org>2007-05-07 13:14:55 +0200
commitfc2e3eae209c321daba04a36fa1723293527e160 (patch)
tree01efa6ee317e744c5a1bd41ead2171e85b23dde7 /dwm.png
parentf9e7a330190259a54449837a16c2af66fa823d30 (diff)
downloaddwm-fc2e3eae209c321daba04a36fa1723293527e160.tar.gz
next version is 4.1
Diffstat (limited to 'dwm.png')
0 files changed, 0 insertions, 0 deletions
kspecs/ranger/commit/ranger/gui/ui.py?h=v1.9.3&id=e657119b4881cec409f42b738f073f5b8e43bc2a'>e657119b ^
1159f9ec ^
cc952d63 ^


1159f9ec ^




0c0b9489 ^




cc952d63 ^
5822dff7 ^
d88232a3 ^
3ea48208 ^
3ea48208 ^
d88232a3 ^
e6dfc442 ^
ae943ecb ^

cc952d63 ^
3ea48208 ^
f027adc0 ^
3ea48208 ^
419e4aa5 ^

d88232a3 ^
e657119b ^
ae943ecb ^
e657119b ^


4c05e43d ^
e657119b ^



ae943ecb ^
f8e96a97 ^


d88232a3 ^
f8e96a97 ^
4c05e43d ^

728fb838 ^
4c05e43d ^
728fb838 ^






4c05e43d ^




d88232a3 ^

ae943ecb ^




4c05e43d ^

728fb838 ^
49ae0dd1 ^

d88232a3 ^
728fb838 ^
49ae0dd1 ^
728fb838 ^


d494f019 ^
d88232a3 ^

9506fb8e ^
ae943ecb ^
d88232a3 ^

9506fb8e ^

728fb838 ^
9506fb8e ^






d88232a3 ^
9506fb8e ^

b0f0027f ^
d88232a3 ^
5822dff7 ^
b0f0027f ^

d88232a3 ^


b4b0eb24 ^

e85d44ae ^
d88232a3 ^
e85d44ae ^





d88232a3 ^






b4b0eb24 ^

d88232a3 ^





7d9ae552 ^
d88232a3 ^




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
             
 

                                             
                                        
 

                               
                                                                          
                                                                


                                                                        




                                      




                                                                                
                                           
 
                                                         
 
                             
                                                                                        
                                   

                                  
                               
                               
                                    
                                  

                                           
 
                                                
                                       


                                                                      
                                                                           



                                                                               
 


                                             
                                  
 

                                     
                                      
                                     






                                   




                                                             

                                         




                                                             

                                                           
 

                                                           
 
                                           
                                    


                                                             
 

                                       
                                        
 

                                                         

                    
                                                                         






                                                        
                                    

                                    
                               
                                                                     
                                      

                                 


                                                     

                              
        
                         





                                        






                                                                              

                                                         





                                                                              
                                  




                                                                               
import curses

from .displayable import DisplayableContainer
from .mouse_event import MouseEvent
from ranger.container import CommandList

class UI(DisplayableContainer):
	is_set_up = False
	mousemask = curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION
	def __init__(self, commandlist=None, env=None, fm=None):
		import os
		os.environ['ESCDELAY'] = '25' # don't know a cleaner way

		if env is not None:
			self.env = env
		if fm is not None:
			self.fm = fm

		if commandlist is None:
			self.commandlist = CommandList()
			self.settings.keys.initialize_commands(self.commandlist)
		else:
			self.commandlist = commandlist
		self.win = curses.initscr()

		DisplayableContainer.__init__(self, None)

	def initialize(self):
		"""initialize curses, then call setup (at the first time) and resize."""
		self.win.leaveok(0)
		self.win.keypad(1)

		curses.cbreak()
		curses.noecho()
		curses.halfdelay(20)
		curses.curs_set(0)
		curses.start_color()
		curses.use_default_colors()

		curses.mousemask(self.mousemask)
		curses.mouseinterval(0)
		
		## this line solves this problem:
		## If an action, following a mouse click, includes the
		## suspension and re-initializion of the ui (e.g. running a
		## file by clicking on its preview) and the next key is another
		## mouse click, the bstate of this mouse event will be invalid.
		## (atm, invalid bstates are recognized as scroll-down)
		curses.ungetmouse(0,0,0,0,0)

		if not self.is_set_up:
			self.is_set_up = True
			self.setup()
		self.update_size()

	def suspend(self):
		"""Turn off curses"""
		from ranger import log
		log("suspending ui!")
		self.win.keypad(0)
		curses.nocbreak()
		curses.echo()
		curses.curs_set(1)
		curses.mousemask(0)
		curses.endwin()

	def destroy(self):
		"""Destroy all widgets and turn off curses"""
		DisplayableContainer.destroy(self)
		self.suspend()

	def handle_mouse(self):
		"""Handles mouse input"""
		try:
			event = MouseEvent(curses.getmouse())
		except:
			return

		from ranger import log
		log('{0:0>28b} ({0})'.format(event.bstate))

		if DisplayableContainer.click(self, event):
			return

		n = event.ctrl() and 1 or 3
		if event.pressed(4):
			self.fm.scroll(relative = -n)
		elif event.pressed(2) or event.key_invalid():
			self.fm.scroll(relative = n)

	def handle_key(self, key):
		"""Handles key input"""
		self.env.key_append(key)

		if DisplayableContainer.press(self, key):
			return

		try:
			cmd = self.commandlist[tuple(self.env.keybuffer)]
		except KeyError:
			self.env.key_clear()
			return

		if cmd == self.commandlist.dummy_object:
			return

		cmd.execute(self.fm)
		self.env.key_clear()

	def get_next_key(self):
		"""Waits for key input and returns the pressed key"""
		key = self.win.getch()
		curses.flushinp()
		return key

	def setup(self):
		"""Called after an initialize() call.
		Override this!
		"""
	
	def redraw(self):
		"""Redraw all widgets"""
		self.poke()
		self.draw()
		self.finalize()

	def redraw_window(self):
		"""Redraw the window. This only calls self.win.redrawwin()."""
		self.win.redrawwin()
		self.win.refresh()
		self.win.redrawwin()

	def update_size(self):
		"""Update self.env.termsize.
		Extend this method to resize all widgets!
		"""
		self.env.termsize = self.win.getmaxyx()

	def draw(self):
		"""Erase the window, then draw all objects in the container"""
		self.win.erase()
		DisplayableContainer.draw(self)
		self.win.refresh()

	def finalize(self):
		"""Finalize every object in container and refresh the window"""
		DisplayableContainer.finalize(self)
		self.win.refresh()