diff pyink/MBScene.py @ 955:53b0f8dc2284

Add tailing 'pass' commands to close indents
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 17 Nov 2010 13:30:32 +0800
parents 82321f404b5f
children 167e359c9d5b
line wrap: on
line diff
--- a/pyink/MBScene.py	Wed Nov 17 12:52:34 2010 +0800
+++ b/pyink/MBScene.py	Wed Nov 17 13:30:32 2010 +0800
@@ -1,4 +1,6 @@
 #!/usr/bin/python
+# -*- indent-tabs-mode: t; tab-width: 8; python-indent: 4; -*-
+# vim: sw=4:ts=8:sts=4
 import pygtk
 import gtk
 from copy import deepcopy
@@ -11,26 +13,42 @@
 
 # Algorithm:
 # 
-# We will parse the first two level of the SVG DOM. collect a table of layer and scene.
-# 1. Collect the layer table which will be displayed as the first column of the grid.
-# 2. Get the maximum scene number. This will decide the size of the grid. 
-# 3. When F6 is pressed, we will check if this scene has been defined. This can be done by scan all second level group and check if the current scene number is within the 
-#    range specified by scene field. The function IsSceneDefined(scene) can be used for this purpose.
-# 4. If this is a new scene, we will append a new group which duplication the content of the last scene in the same group. The scene field will contain the number from the 
-#    last scene number of the last scene to the current scenen number. For example, if the last scene is from 4-7 and the new scene is 10, we will set the scene field as
-#    "8-10".
-# 5. If this scene are filled screne, we will split the existing scene into two scenes with the same content.
+# We will parse the first two level of the SVG DOM. collect a table of
+# layer and scene.
+# - 1. Collect the layer table which will be displayed as the first
+#      column of the grid.
+# - 2. Get the maximum scene number. This will decide the size of the
+#      grid.
+# - 3. When F6 is pressed, we will check if this scene has been
+#      defined. This can be done by scan all second level group and
+#      check if the current scene number is within the range specified
+#      by scene field. The function IsSceneDefined(scene) can be used
+#      for this purpose.
+# - 4. If this is a new scene, we will append a new group which
+#      duplication the content of the last scene in the same
+#      group. The scene field will contain the number from the last
+#      scene number of the last scene to the current scenen
+#      number. For example, if the last scene is from 4-7 and the new
+#      scene is 10, we will set the scene field as "8-10".
+# - 5. If this scene are filled screne, we will split the existing
+#       scene into two scenes with the same content.
+#
 
 class Layer:
-	def __init__(self,node):
-		self.scene = []
-		self.node = node
-		self.nodes=[]
+    def __init__(self,node):
+	self.scene = []
+	self.node = node
+	self.nodes=[]
+	pass
+    pass
+
 class Scene:
 	def __init__(self, node, start,end):
 		self.node = node
 		self.start = int(start)
 		self.end = int(end)
+		pass
+	pass
 
 
 class MBScene():
@@ -40,6 +58,7 @@
 		self.layer = []
 		self.layer.append(Layer(None))
 		self.scenemap = None
+		pass
 
 	def confirm(self,msg):
 		vbox = gtk.VBox()
@@ -48,6 +67,8 @@
 		vbox.pack_start(self.button)
 		self.button.connect("clicked", self.onQuit)
 		self.window.add(vbox)
+		pass
+	
 	def dumpattr(self,n):
 		s = ""
 		for a,v in n.attrib.items():
@@ -58,7 +79,10 @@
 		print " " * l*2,"<", node.tag, self.dumpattr(node),">"
 		for n in node:
 			self.dump(n,l+1)
+			pass
 		print " " * l * 2,"/>"
+		pass
+	
 	def parseMetadata(self,node):
 		self.current = 1
 		for n in node.childList():
@@ -81,17 +105,19 @@
 								end = start
 						except:
 							end = start
+							pass
 						link = s.repr.attribute("ref")
 						self.scenemap[link] = [int(start),int(end)]
 						print "scene %d to %d" % (self.scenemap[link][0],self.scenemap[link][1])
 						if cur >= start and cur <= end:
-							self.currentscene = link
-
+						    self.currentscene = link
+						    pass
+						pass
 					pass
 				pass
 			pass
 		pass
-						
+	
 						
 	def parseScene(self):
 		"""
@@ -104,6 +130,7 @@
 		for node in doc.childList():
 			if node.repr.name() == 'svg:metadata':
 				self.parseMetadata(node)
+				pass
 			elif node.repr.name() == 'svg:g':
 				oldscene = None
 				#print layer.attrib.get("id")
@@ -119,14 +146,17 @@
 								continue
 							if self.current <= scmap[1] and self.current >= scmap[0]:
 								oldscene = scene
+								pass
 						except:
 							lyobj.current_scene.append(scene)
 							continue
 
 						lyobj.scene.append(Scene(scene,scmap[0],scmap[1]))
+						pass
 					else:
 						lyobj.current_scene.append(scene)
-				pass
+						pass
+					pass
 
 				if oldscene != None:
 					# Put the objects back to the current scene
@@ -135,34 +165,47 @@
 						#oldscene.append(o)
 					pass
 				pass
-		pass
+			pass
 
 		self.collectID()
 		self.dumpID()
+		pass
+
 	def collectID(self):
 		self.ID = {}
 		root = self.desktop.doc().root()
 		for n in root.childList():
 			self.collectID_recursive(n)
+			pass
+		pass
+	
 	def collectID_recursive(self,node):
 		self.ID[node.getId()] = 1
 		for n in node.childList():
 			self.collectID_recursive(n)
+			pass
+		pass
+	
 	def newID(self):
 		while True:
 			n = 's%d' % int(random.random()*10000)
 			#print "try %s" % n
 			if self.ID.has_key(n) == False:
 				return n
+			pass
+		pass
+	
 	def dumpID(self):
 		for a,v in self.ID.items():
 			print a
-
+			pass
+		pass
 		
 	def getLayer(self, layer):
 		for l in self.layer:
 			if l.node.getId() == layer:
 				return l
+			pass
 		return None
 		
 	
@@ -193,6 +236,8 @@
 				self.grid.remove(self.last_cell)
 				self.grid.attach(btn, x,x+1,y,y+1,0,0,0,0)
 				return
+			pass
+		
 		if len(layer.scene) > 0:
 			last = nth
 			lastscene = None
@@ -200,12 +245,17 @@
 				if s.end < nth and last < s.end:
 					last = s.end
 					lastscene = s
+					pass
+				pass
+			
 			for x in range(last+1, nth):
 				btn = self.newCell('fill.png')
 				btn.nScene = x
 				btn.layer = layer.node.getId()
 				btn.nLayer = y
 				self.grid.attach(btn, x, x+1, y , y+1,0,0,0,0)
+				pass
+			
 			if lastscene == None:
 				node = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene')
 				node.setId(self.newID())
@@ -214,6 +264,8 @@
 				lastscene.end = nth-1
 				newscene = Scene(DuplicateNode(lastscene.node),nth,nth)
 				newscene.node.setId(self.newID())
+				pass
+			
 			layer.scene.append(newscene)
 			btn = self.newCell('start.png')
 			x = self.last_cell.nScene
@@ -233,9 +285,9 @@
 			btn.layer = layer.node.getId()
 			btn.nLayer = y
 			self.grid.attach(btn, x, x+1, y, y+1,0,0,0,0)
-
-
-
+			pass
+		pass
+	
 
 	def removeKeyScene(self):
 		nth = self.last_cell.nScene
@@ -255,6 +307,7 @@
 						btn.layer = layer
 						btn.nLayer = y
 						self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
+						pass
 					layer.scene.remove(s)
 				else:
 					if s.start == layer.scene[i-1].end+1:
@@ -277,9 +330,12 @@
 							btn.layer = layer
 							btn.nLayer = y
 							self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
-
-						
+							pass
+						pass
+					pass
 				return
+			pass
+		pass
 
 	def extendScene(self):
 		nth = self.last_cell.nScene
@@ -290,12 +346,14 @@
 			return
 		x = self.last_cell.nScene
 		y = self.last_cell.nLayer
-		if layer == None: return
+		if layer == None:
+		    return
 
 		for i in range(0,len(layer.scene)-1):
 			s = layer.scene[i]
 			if nth >= layer.scene[i].start and nth <= layer.scene[i].end:
 				return
+			pass
 
 		for i in range(0,len(layer.scene)-1):
 			s = layer.scene[i]
@@ -308,6 +366,7 @@
 					self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
 				layer.scene[i].end = nth
 				return
+			pass
 		if len(layer.scene) > 0 and nth > layer.scene[len(layer.scene)-1].end:
 			for j in range(layer.scene[len(layer.scene)-1].end+1, nth+1):
 				btn = self.newCell('fill.png')
@@ -315,7 +374,11 @@
 				btn.nLayer = y
 				btn.layer = self.last_cell.layer
 				self.grid.attach(btn, j,j+1,y,y+1,0,0,0,0)
+				pass
 			layer.scene[len(layer.scene)-1].end = nth
+			pass
+		pass
+	
 	def setCurrentScene(self,nth):
 		self.current = nth
 		for layer in self.layer:
@@ -332,6 +395,11 @@
 					#	s.node.remove(o)
 				else:
 					s.node.repr.setAttribute("style","display:none",True)
+					pass
+				pass
+			pass
+		pass
+	
 	def generate(self):
 		newdoc = deepcopy(self.document)
 		root = newdoc.getroot()
@@ -353,11 +421,17 @@
 								else:
 									scene.set("start", "%d" % s.start)
 									scene.set("end", "%d" % s.end)
+									pass
 
 								scenes.append(scene)
+								pass
+							pass
 						for s in scenes:
 							nn.append(s)
+							pass
 						has_scene = True
+						pass
+					pass
 				if has_scene == False:
 					scenes = etree.Element('{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes')
 					scenes.set("current","%d" % self.current)
@@ -370,27 +444,40 @@
 							else:
 								scene.set("start", "%d" % s.start)
 								scene.set("end", "%d" % s.end)
+								pass
 							scenes.append(scene)
+							pass
+						pass
 					n.append(scenes)
 			if n.tag ==  '{http://www.w3.org/2000/svg}g':
 				root.remove(n)
-
+				pass
+			pass
+		
 		for l in self.layer:
 			# Duplicate all attribute of the layer
 			lnode = etree.Element("{http://www.w3.org/2000/svg}g")
 			for a,v in l.node.attrib.items():
 				lnode.set(a,v)
+				pass
 			for n in l.nodes:
 				lnode.append(n)
+				pass
 			root.append(lnode)
 			for s in l.scene:
 				snode = etree.Element("{http://www.w3.org/2000/svg}g")
 				for a,v in s.node.attrib.items():
 					snode.set(a,v)
+					pass
 				for n in s.node:
 					snode.append(deepcopy(n))
+					pass
 				lnode.append(snode)
+				pass
+			pass
 		self.document = newdoc
+		pass
+	
 	def newCell(self,file):
 		img = gtk.Image()
 		img.set_from_file(file)
@@ -399,12 +486,16 @@
 		btn.connect("button_press_event", self.cellSelect)
 		btn.modify_bg(gtk.STATE_NORMAL, btn.get_colormap().alloc_color("gray"))
 		return btn
+	
 	def showGrid(self):
 		max = 0
 		for layer in self.layer:
 			for s in layer.scene:
 				if s.end > max:
 					max = s.end
+					pass
+				pass
+			pass
 		max = 50
 
 		self.grid = gtk.Table(len(self.layer)+1, 50)
@@ -414,6 +505,7 @@
 		self.scrollwin.set_size_request(-1,150)
 		for i in range(1,max):
 			self.grid.attach(gtk.Label('%d'% i), i,i+1,0,1,0,0,0,0)
+			pass
 		for i in range(1,len(self.layer)+1):
 			print "Layer", i
 			l = self.layer[i-1]
@@ -432,10 +524,14 @@
 					btn.nScene = j
 					btn.layer = l.node.getId()
 					btn.nLayer = i
+					pass
+				pass
 			if len(l.scene) == 0:
 				start = 0
 			else:
 				start = l.scene[len(l.scene)-1].end
+				pass
+			
 			for j in range(start,max):
 				btn = self.newCell('empty.png')
 				self.grid.attach(btn, j+1, j+2,i,i+1,0,0,0,0)
@@ -443,29 +539,41 @@
 				btn.nScene = j+1
 				btn.layer = l.node.getId()
 				btn.nLayer = i
+				pass
+			pass
 		self.last_cell = None
+		pass
+	
 	def cellSelect(self, cell, data):
 		if self.last_cell:
 			self.last_cell.modify_bg(gtk.STATE_NORMAL, self.last_cell.get_colormap().alloc_color("gray"))
+			pass
 			
 		self.last_cell = cell
 		cell.modify_bg(gtk.STATE_NORMAL, cell.get_colormap().alloc_color("green"))
+		pass
 		
 	def doEditScene(self,w):
 		self.setCurrentScene(self.last_cell.nScene)
+		pass
+	
 	def doInsertKeyScene(self,w):
+		#self.insertKeyScene()
+		#self.grid.show_all()
 		return
-		self.insertKeyScene()
-		self.grid.show_all()
 
 	def doRemoveScene(self,w):
 		return
 		self.removeKeyScene()
 		self.grid.show_all()
 		self.generate()
+		pass
+	
 	def doExtendScene(self,w):
 		self.extendScene()
 		self.grid.show_all()
+		pass
+	
 	def addButtons(self,hbox):
 		btn = gtk.Button('Edit')
 		btn.connect('clicked', self.doEditScene)
@@ -479,12 +587,17 @@
 		btn=gtk.Button('Extend scene')
 		btn.connect('clicked', self.doExtendScene)
 		hbox.pack_start(btn,expand=False,fill=False)
+		pass
+	
 	def onQuit(self, event):
 		self.OK = False
 		gtk.main_quit()
+		pass
+	
 	def onOK(self,event):
 		self.OK = True
 		gtk.main_quit()
+		pass
 
 	def onConfirmDelete(self):
 		if self.scenemap == None:
@@ -502,7 +615,8 @@
 			self.window.show_all()
 			gtk.main()
 			self.window.remove(vbox)
-
+			pass
+		pass
 
 	def show(self):
 		self.OK = True
@@ -516,6 +630,7 @@
 		#self.window.set_position(gtk.WIN_POS_MOUSE)
 		if self.scenemap == None:
 			self.onConfirmDelete()
+			pass
 		if self.OK:
 			vbox = gtk.VBox(False,0)
 			self.window.pack_start(vbox,expand=False)
@@ -530,5 +645,5 @@
 		#self.window.set_size_request(600,200)
 
 		self.window.show_all()
-
-		
+		pass
+	pass