1

I would like to add an editable toolbox on an arcpy addin toolbar. This would be used to change values of a threshold but I don't think this is currently available. (What I would really like is a slider!)

My current work around is to use a combobox which does 80% of what I want it to do except display an initial value and update the displayed value when altered programatically. As can be seen in my code I have a + and - button that can change the value stored in the combo box items variable.

import arcpy
import pythonaddins
import os

class decreaseBottom(object):
    """Implementation for alterRange.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        firstBreak.items[0] -= 1
        if firstBreak.items[0] < 0:
            firstBreak.items[0] = 0
        firstBreak.refresh()

class decreaseTop(object):
    """Implementation for alterRange.btn3 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        firstBreak.items[0] += 1
        if firstBreak.items[0] > 100:
            firstBreak.items[0] = 100
        firstBreak.refresh()

class firstBreak(object):
    """Implementation for alterRange.firstBreak (ComboBox)"""
    def __init__(self):
        self.items = [30]
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'
    def onSelChange(self, selection):
        pass
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):
        pass
    def onEnter(self):
        pass
    def refresh(self):
        pass

Is there a variable in the __init__ of the combo box that can do this?

1
self.value = 30 

will set the initial value of the combobox to 30.

Updating the displayed value from your buttons is similar, in this case:

firstBreak.value = firstBreak.items[0]

before your combobox refresh should do the trick.

You don't seem to be using the dropdown or editing functionality of the combobox, so you could consider setting self.editable = False on your combobox. You may not even need to set .items in this case, simply setting and modifying .value might work, but I haven't tested that.

| improve this answer | |

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.