Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

  1.  

    Hi all,

    It is my very first post in this forum, but I exhausted the possibilities to find the solution in programming reference and previous forum posts (closest related: https://www.klayout.de/forum/comments.php?DiscussionID=332&page=1#Item_9).

    My problem is related to usage of setters (e.g. fill_color class LayerProperties)). Despite that in the reference is as python setter listed fill_color, the interpreter is returning an exception (Cannot call a setter on a const reference in LayerProperties.fill_color (Class exceptions.RuntimeError)). I have tried to change the setter for fill_color_, but this is not affecting the UI anyway.

    I am providing a snippet of test code. It is designed to change colors of layers upon the dose factor represented as datatype value (EBL related stuff).

    import pya
    import math
    import sys
    import colorsys
    
    # Enter your Python code here
    #Shape boolean operation testing 
    app = pya.Application.instance()
    mw = app.main_window()
    lv = mw.current_view()
    ly = lv.active_cellview().layout()
    tc = lv.active_cellview().cell
    cv_index = lv.active_cellview().cell_index
    dbu = ly.dbu
    
    def getKey(item):
        return item[1]
    
    def ReturnColor(x, arr): #just workaround - should be refined !!! extremely slow
      for i in arr:
        #print "Looking for index {} in {}".format(x, i)
        if i[0] == x:
          #print "found"
          return i[2]
      return -1
    
    
    #requested data
    ReqLayer = 1
    
    all_layers = ly.layer_indices()
    #print all_layers
    
    indxDose = []
    for layer in all_layers:
      layer_info = ly.get_info(layer)
      #print layer_info
      if layer_info.layer == ReqLayer:
        #print layer_info.datatype
        indxDose.append([layer, layer_info.datatype, 0])
    
    sorted(indxDose, key = getKey) 
    
    for i in range(0, len(indxDose)):
      reqColor = 0.71 * float(i)/len(indxDose)
      r,g,b = colorsys.hls_to_rgb(reqColor, 0.5, 1)
      #print "rgb({},{},{})".format(int(r*255),int(g*255),int(b*255))
      reqColorRGB = (int(r*255)<<16) + (int(g*255)<<8) + int(b*255)
      indxDose[i][2] = reqColorRGB 
    
    Liter = lv.begin_layers()
    
    while not Liter.at_end():
      lp = Liter.current()
      #print lp.layer_index()
      #print "Layer index:{}".format(lp.layer_index())
      if lp.cellview() == cv_index:
        Color = ReturnColor(lp.layer_index(), indxDose)
        if Color != -1:
          print "Color value for index:{} is {}".format(lp.layer_index(), Color)
          print "Color before:{}".format(lp.fill_color)
          print "Color before_:{}".format(lp.fill_color_)
          lp.fill_color = Color
          print "Color after:{}".format(lp.fill_color)
          lp.frame_color_ = 0xFFFFFFFF
          lp.dither_pattern_ = 20
        #else:
          #print "not found"
      Liter.next()
    
    lv.add_missing_layers()
    

    Thank you a lot for any idea.

    git@gitlab.com:jakub.sadilek/klayout-raith.git git@gitlab.com:jakub.sadilek/Klayout-extensions.git

    • CommentAuthorMatthias
    • CommentTimeMay 11th 2017 edited
     

    Hi,

    the problem you have was discussed in this thread: https://www.klayout.de/forum/comments.php?DiscussionID=89.

    That solution mentioned is still valid in 0.24, but with 0.25 your code is going to work too. The discussion relates to Ruby, but the translation to Python is straightforward. Please see the "Python implementation notes" in http://www.klayout.de/python_preview.html for details.

    Regards,

    Matthias