Mouse input

Banging my head and the poor Mouse in frustration
How hard can it be just too get mouse inputs.
Yes , I am aware of the pya.PluginFactory
I don't want a menu interface, just allow too
select mouse inputs .
So would like to be able to input mouse coords with mutiple clicks
then gather those xy values, may ask why , it's practical , most other tools
allow this with out jumping through hoops.
So code would be enter mouse click until "esc" key is entered

Anybody, with a solution chime up

Comments

  • @tagger5896 Basically you should not approach this problem like "a want to achieve this and that". You should rather ask yourself, what you can do with the functionality provided. Forcing your expectations on the system will not help.

    The Plugin thing is a framework API, not a general, do-what-you-want API. A plugin integrates itself into the framework and it will give you what the framework offers. In this case this means you need a "mode" and this comes with a menu item. This ensures there is exclusive control for one plugin, there are no conflicts and the various plugins will cooperate. A major part of KLayout's functionality is implemented in plugins, so I think this proves the general usability of the concept.

    As a side remark, frameworks are very common today in many fields and if you're frustrated with mouse events in KLayout you should look into Rails for example to learn how real confinement feels like.

    And I don't want to enter a competition for the best application API. If "other tools" means the "C brand" I need to say that I know this one well enough to hate their 1958 style automation language for more general reasons and I don't think a simple mouse API compensates for that.

    Matthias

  • edited February 2021

    Hmm,

    I will figure it out, this current code works getting
    mouse inputs , now to make it work with Klayout
    simplicity is the way .

           from ctypes import windll, Structure, c_long, byref
    
           class POINT(Structure):
          _fields_ = [("x", c_long), ("y", c_long)]
    
           def queryMousePosition():
           pt = POINT()
           windll.user32.GetCursorPos(byref(pt))
           return { "x": pt.x, "y": pt.y}
    
           pos = queryMousePosition()
           print(pos)
    
  • Matthias,

    Thanks for the comment, making progress with the plugin as suggested,
    Question how do you pass mouse inputs to either Python or Ruby.
    def box_finished(self, box):
    # TODO: put in your code to do what you like to do with the box
    #pya.MainWindow.instance().message("Box finished: " + str(box), 10000)
    b = str(box)
    c = re.split('[ ; , ) (]', b)
    #Get Box Coordinates
    x1 = c[1]
    y1 = c[2]
    x2 = c[3]
    y2 = c[4]
    print(f"x1:y1 = {x1},{y1} : x2:y2 = {x2},{y2} ")
    self.ungrab_mouse()
    pya.MainWindow.instance().cancel()

  • @tagger5896 You can format code by indenting with four blanks or putting a line with triple backticks before or after the code. With Python this much more readable.

    Specifically here I wonder where the "box_finished" functions ends.

    But why do you get the coordinates of a box by turning to a string, the splitting and turning into numbers??? There is "b.left", "b.bottom" and many more methods and property getters: https://www.klayout.de/doc-qt5/code/class_Box.html

    I sense what you're trying to do ... but I will not support the kind of system hacking. I will only support the way that is provided by the API. Capturing the mouse cursor may or may not work. Even if it does you'll be left alone with many nasty details such as transforming the pointer coordinates into layout coordinates. Please seriously consider if forcing your will on the system is really worth the effort.

    Matthias

  • Matthias,

    Thanks for the valuable input,
    I am new at Ruby and Python in general, 4 months, Klayout 3
    25 plus years of Cadence Skill coding it's hard to unwire your
    brain around an new tool and constructs, but I will get there.

Sign In or Register to comment.