Beispiel #1
0
class MapApp(wx.App):
    def OnInit(self):
        if not globalvar.CheckWxVersion([2, 9]):
            wx.InitAllImageHandlers()
        if __name__ == "__main__":
            self.cmdTimeStamp = os.path.getmtime(monFile['cmd'])
            self.Map = Map(cmdfile=monFile['cmd'],
                           mapfile=monFile['map'],
                           envfile=monFile['env'],
                           monitor=monName)
        else:
            self.Map = None

        self.mapFrm = MapFrame(parent=None,
                               id=wx.ID_ANY,
                               Map=self.Map,
                               size=monSize)
        # self.SetTopWindow(Map)
        self.mapFrm.Show()

        if __name__ == "__main__":
            self.timer = wx.PyTimer(self.watcher)
            #check each 0.5s
            global mtime
            mtime = 500
            self.timer.Start(mtime)

        return True

    def OnExit(self):
        if __name__ == "__main__":
            # stop the timer
            # self.timer.Stop()
            # terminate thread
            for f in monFile.itervalues():
                grass.try_remove(f)

    def watcher(self):
        """!Redraw, if new layer appears (check's timestamp of
        cmdfile)
        """
        # todo: events
        if os.path.getmtime(monFile['cmd']) > self.cmdTimeStamp:
            self.timer.Stop()
            self.cmdTimeStamp = os.path.getmtime(monFile['cmd'])
            self.mapFrm.OnDraw(None)
            self.mapFrm.GetMap().GetLayersFromCmdFile()
            self.timer.Start(mtime)