我正在尝试为ArcMap创建一个“自动刷新”工具,以刷新数据帧。我相信版本10有一个附加组件,你可以为此下载。。不过,我们现在运行的是10.1版本,没有这样的工具。在
编辑wxPython的计时器应该可以工作,但是在arc中使用wx是很棘手的。下面是当前的代码:import arcpy
import pythonaddins
import os
import sys
sMyPath = os.path.dirname(__file__)
sys.path.insert(0, sMyPath)
WATCHER = None
class WxExtensionClass(object):
"""Implementation for Refresher_addin.extension (Extension)"""
_wxApp = None
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def startup(self):
from wx import PySimpleApp
self._wxApp = PySimpleApp()
self._wxApp.MainLoop()
global WATCHER
WATCHER = watcherDialog()
class RefreshButton(object):
"""Implementation for Refresher_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
if not WATCHER.timer.IsRunning():
WATCHER.timer.Start(5000)
else:
WATCHER.timer.Stop()
class watcherDialog(wx.Frame):
'''Frame subclass, just used as a timer event.'''
def __init__(self):
wx.Frame.__init__(self, None, -1, "timer_event")
#set up timer
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.onTimer, self.timer)
def onTimer(self, event):
localtime = time.asctime( time.localtime(time.time()) )
print "Refresh at :", localtime
arcpy.RefreshActiveView()
app = wx.App(False)
你会注意到里面有PySimpleApp的东西。我从塞德霍姆的演讲中得到的。我想知道我是否误解了什么。我应该为扩展创建一个完全独立的加载项吗?然后,用我需要的代码创建我的工具栏/工具栏加载项?我这么问是因为我没有看到下面代码中引用的PySimpleApp,或者在startup override方法中没有从wx导入任何内容。。。我认为这是必要的/这一切的重点。我非常感谢你的帮助。请告诉我你在我的代码中看到了什么。在