I have a toolbar with two buttons. It's a crude toggle that looks
at a text file containing a single character whose values are either 0 or 1. When the file contents are 0, then button1 ResumeExports()
should show up as depressed and disabled while button2 PauseExports()
is enabled and normal. When the contents of the file are 1, then the button2 should be active and button1 inactive--it is used as a switch to allow or disallow other processing to occur. The toggle works, and the file gets updated. How can I get the button status (checked/unchecked, enabled/disabled) on the interface to reflect that? Both buttons always show enabled and unchecked. I'm at 10.2.1.
import arcpy
import pythonaddins
class ResumeExports(object):
"""Implementation for PythonAddIns_addin.res_btn (Button)"""
ctl_file = r"C:\Users\myusername\Documents\ArcGIS\switch.txt"
def __init__(self):
with open(ctl_file, 'r') as i:
content = i.read(1)
if content == '1': # exports are allowed
self.enabled = False # button should be inactive
self.checked = True # button should be depressed
if content == '0': # exports are disallowed, resume button is active
self.enabled = True
self.checked = False
def onClick(self):
with open(ctl_file, "r+") as f:
data = f.read()
f.seek(0)
f.write("1")
f.truncate()
class PauseExports(object):
"""Implementation for PythonAddIns_addin.stop_btn (Button)"""
ctl_file = r"C:\Users\myusername\Documents\ArcGIS\switch.txt"
def __init__(self):
with open(ctl_file, 'r') as i:
content = i.read(1)
if content == '0': # exports are paused
self.enabled = False # button should be inactive
self.checked = True # button should be depressed
if content == '1': # exports are allowed, pause button is active
self.enabled = True
self.checked = False
def onClick(self):
ctl_file = r"C:\Users\myusername\Documents\ArcGIS\switch.txt"
with open(ctl_file, "r+") as f:
data = f.read()
f.seek(0)
f.write("0")
f.truncate()