1

I built a simple toolbar with Tool Palette and Button. Button should make a selection according to a global parameter which can be set by selection of Value in Palette box.

enter image description here

I.e. if I choose number "1", pressing the button on the right will select layer by attribute value like for example "PAR =1".

I tried something like this:

class ONE(object):
    """Implementation for SelectNlevelTest_addin.ONE (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
        global par
    def onMouseDown(self, x, y, button, shift):
        global par
        par = "par = 1"
    def onMouseDownMap(self, x, y, button, shift):
        pass
    def onMouseUp(self, x, y, button, shift):
        global par
        par = "par = 1"
    def onMouseUpMap(self, x, y, button, shift):
        pass
    def onMouseMove(self, x, y, button, shift):
        pass
    def onMouseMoveMap(self, x, y, button, shift):
        pass
    def onDblClick(self):
        pass
    def onKeyDown(self, keycode, shift):
        pass
    def onKeyUp(self, keycode, shift):
        pass
    def deactivate(self):
        pass
    def onCircle(self, circle_geometry):
        pass
    def onLine(self, line_geometry):
        pass
    def onRectangle(self, rectangle_geometry):
        pass

But setting PAR in defs onMouseUp and onMouseDown doesn't help, it tells that value 'par' is not defined. If I set PAR in def __init__(self), it makes selection, but only by one parameter ignoring pressing other number.

Is that possible to set the parameter by pressing the button from Tool Palette?

2

This should work:

par = ''    
class ONE(object):
    """Implementation for SelectNlevelTest_addin.ONE (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
        global par
    def onMouseDown(self, x, y, button, shift):
        global par
        par = "par = 1"

But this is way better:

class ONE(object):
    """Implementation for SelectNlevelTest_addin.ONE (Tool)"""
    def __init__(self):
        self.enabled = True
        self.shape = "NONE"
        self.par = ''
    def onMouseDown(self, x, y, button, shift):
        self.par = "par = 1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.