Advertisement
nux95

Some corrected Code for c4d (from ScottA, original by me)

Jun 1st, 2011
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.18 KB | None | 0 0
  1. import c4d
  2. from c4d import gui
  3.  
  4. def isIterateable(item):
  5.  try:
  6.   item[0]
  7.  
  8.  except:
  9.    return False
  10.  else:
  11.    return True
  12.  
  13. class ListViewData:
  14.  def __init__(self, iterateableData):
  15.   if not isIterateable(iterateableData):
  16.       raise TypeError, "%s must be initialized with an iterateable value" %self.__class__.__name__
  17.   self.data = iterateableData
  18.  
  19.  def GetColumn(self, index):
  20.   if index > len(self.data):
  21.     return
  22.   else:
  23.     return self.data[index]
  24.  
  25.  def GetLengthOfData(self):
  26.    return len(self.data)
  27.  
  28. class MyUA(gui.GeUserArea):
  29.   colors = {
  30.             "background": c4d.Vector(.2),
  31.             "lighter": c4d.Vector(.6),
  32.             "darker": c4d.Vector(.2),
  33.             "marked": c4d.Vector(.8, .4, .2),
  34.             "text": c4d.Vector(.1),
  35.             "markedText": c4d.Vector(.7, .5, .6),
  36.            }
  37.  
  38.  
  39.   def __init__(self, rowheight, data, columnwidth = (100, )):
  40.    if not isIterateable(data):
  41.     raise TypeError, "%s must be initialized with an iterateable value" %self.__class__.__name__
  42.  
  43.    self.minimumHeight = rowheight * len(data)
  44.    self.rowheight = rowheight
  45.    self.columnwidth = columnwidth
  46.    self.data = data
  47.    self.marked = 2
  48.  
  49.  
  50.   def DrawMsg(self, x1, y1, x2, y2, msg):
  51.    #Set Background Color
  52.    self.DrawSetPen(self.colors["background"])
  53.    self.DrawRectangle(x1, y1, x2, y2)
  54.    rHeight = self.rowheight
  55.    
  56.    #Draw lighter areas
  57.    self.DrawSetPen(self.colors["lighter"])
  58.    for i in xrange(0, len(self.data), 2):
  59.     if i == self.marked:
  60.      self.DrawSetPen(self.colors["marked"])
  61.     self.DrawRectangle(x1=0, y1 = rHeight*i, x2=x2, y2 = rHeight * (i+1))
  62.     if i == self.marked:
  63.       self.DrawSetPen(self.colors["lighter"])
  64.  
  65.    #Draw darker areas
  66.    self.DrawSetPen(self.colors["darker"])
  67.    for i in xrange(1, len(self.data), 2):
  68.     if i == self.marked:
  69.      self.DrawSetPen(self.colors["marked"])
  70.     self.DrawRectangle(x1=0, y1 = rHeight*i, x2=x2, y2 = rHeight * (i+1))
  71.     if i == self.marked:
  72.       self.DrawSetPen(self.colors["darker"])
  73.  
  74.    #Draw self.data
  75.    self.DrawSetPen(self.colors["text"])
  76.    for i in xrange(len(self.data)):
  77.     if i == self.marked:
  78.      self.DrawSetPen(self.colors["markedText"])
  79.     for j in xrange(self.data[i].GetLengthOfData()):
  80.       if j >= len(self.columnwidth):
  81.        width = self.columnwidth[-1]
  82.       else:
  83.        width = self.columnwidth[j]
  84.  
  85.       itemToDraw = str(self.data[i].GetColumn(j))
  86.       self.DrawText(itemToDraw, x1 = x1 + j*width, y1 = i * rHeight + int((rHeight * .1)))
  87.    if i == self.marked:
  88.       self.DrawSetPen(self.colors["text"])
  89.  
  90.  
  91.   def GetMinimumHeight(self):
  92.     return 200, self.minimumHeight()
  93.  
  94.   def InputEvent(self, msg):
  95.     #x = msg(c4d.BFM_INPUT_X)
  96.     y = msg[c4d.BFM_INPUT_Y]
  97.     self.marked = int(y/self.rowheight)
  98.     self.Redraw()
  99.  
  100.     return True
  101.  
  102. class dlg(gui.GeDialog):
  103.   def Init(self):
  104.     pass
  105.  
  106.   def CreateLayout(self):
  107.    self.ua = MyUA(15, [ListViewData(("Name", "hello", 1002)) for i in range(20)])
  108.    ua_id = self.AddUserArea(100000121, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)
  109.    self.AttachUserArea(self.ua, ua_id)
  110.  
  111.    return True
  112. d = dlg()
  113. d.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE, 1000124, -1, -1, 400, 300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement