Ejemplo n.º 1
0
    def __init__(self,
                 parent=None,
                 dataFile=None,
                 wtFiles=[''],
                 vars=[''],
                 results=[],
                 dialogMode=False):
        self.results = results
        self.dialogMode = dialogMode
        SpatialLag_xrc.xrcCreateSpatialLag.__init__(self, parent)
        self.width = None
        d = {}
        d['wtFiles'] = self.__wtFile
        d['wtFile'] = self.__wtFile
        d['vars'] = self.__vars
        d['dataFile'] = self.__dataFile
        self.dispatch = d

        self.weights.Bind(wx.EVT_CHOICE, self.__wtFile)
        self.fakeVarsChoice.Bind(wx.EVT_CHOICE, self.addRow)
        self.openWeights.Bind(wx.EVT_BUTTON, self.__wtFile)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.close)
        self.okButton.Bind(wx.EVT_BUTTON, self.run)
        self.dataFileButton.Bind(wx.EVT_BUTTON, self.__dataFile)
        self.dataFile.Bind(wx.EVT_TEXT, self.__dataFile)

        self.model = M_CreateSpatialLag()
        self.model.addListener(self.populate)
        for wtFile in wtFiles:
            self.model.set('wtFile', wtFile)
        self.model.set('wtFile', 0)
        self.model.set('vars', vars)
        # hack to force initial data file to show up in GUI, even if it doesn't
        # exist
        self.model.data['dataFile'] = dataFile
        self.populate(None)
        self.model.set('dataFile', dataFile)

        # VariablesPeer is a hidden panel of size (0,0), this is necessary
        # because XRC does
        # not allow accessing sizers directly, so you get call a sizer item's
        # GetContainingSizer method
        self.varSizer = self.VariablesPeer.GetContainingSizer()
Ejemplo n.º 2
0
    def __init__(self, parent=None, dataFile=None, wtFiles=[''], vars=[''],
                 results=[], dialogMode=False):
        self.results = results
        self.dialogMode = dialogMode
        SpatialLag_xrc.xrcCreateSpatialLag.__init__(self, parent)
        self.width = None
        d = {}
        d['wtFiles'] = self.__wtFile
        d['wtFile'] = self.__wtFile
        d['vars'] = self.__vars
        d['dataFile'] = self.__dataFile
        self.dispatch = d

        self.weights.Bind(wx.EVT_CHOICE, self.__wtFile)
        self.fakeVarsChoice.Bind(wx.EVT_CHOICE, self.addRow)
        self.openWeights.Bind(wx.EVT_BUTTON, self.__wtFile)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.close)
        self.okButton.Bind(wx.EVT_BUTTON, self.run)
        self.dataFileButton.Bind(wx.EVT_BUTTON, self.__dataFile)
        self.dataFile.Bind(wx.EVT_TEXT, self.__dataFile)

        self.model = M_CreateSpatialLag()
        self.model.addListener(self.populate)
        for wtFile in wtFiles:
            self.model.set('wtFile', wtFile)
        self.model.set('wtFile', 0)
        self.model.set('vars', vars)
        # hack to force initial data file to show up in GUI, even if it doesn't
        # exist
        self.model.data['dataFile'] = dataFile
        self.populate(None)
        self.model.set('dataFile', dataFile)

        # VariablesPeer is a hidden panel of size (0,0), this is necessary
        # because XRC does
        # not allow accessing sizers directly, so you get call a sizer item's
        # GetContainingSizer method
        self.varSizer = self.VariablesPeer.GetContainingSizer()
Ejemplo n.º 3
0
class C_CreateSpatialLag(SpatialLag_xrc.xrcCreateSpatialLag):
    def __init__(self,
                 parent=None,
                 dataFile=None,
                 wtFiles=[''],
                 vars=[''],
                 results=[],
                 dialogMode=False):
        self.results = results
        self.dialogMode = dialogMode
        SpatialLag_xrc.xrcCreateSpatialLag.__init__(self, parent)
        self.width = None
        d = {}
        d['wtFiles'] = self.__wtFile
        d['wtFile'] = self.__wtFile
        d['vars'] = self.__vars
        d['dataFile'] = self.__dataFile
        self.dispatch = d

        self.weights.Bind(wx.EVT_CHOICE, self.__wtFile)
        self.fakeVarsChoice.Bind(wx.EVT_CHOICE, self.addRow)
        self.openWeights.Bind(wx.EVT_BUTTON, self.__wtFile)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.close)
        self.okButton.Bind(wx.EVT_BUTTON, self.run)
        self.dataFileButton.Bind(wx.EVT_BUTTON, self.__dataFile)
        self.dataFile.Bind(wx.EVT_TEXT, self.__dataFile)

        self.model = M_CreateSpatialLag()
        self.model.addListener(self.populate)
        for wtFile in wtFiles:
            self.model.set('wtFile', wtFile)
        self.model.set('wtFile', 0)
        self.model.set('vars', vars)
        # hack to force initial data file to show up in GUI, even if it doesn't
        # exist
        self.model.data['dataFile'] = dataFile
        self.populate(None)
        self.model.set('dataFile', dataFile)

        # VariablesPeer is a hidden panel of size (0,0), this is necessary
        # because XRC does
        # not allow accessing sizers directly, so you get call a sizer item's
        # GetContainingSizer method
        self.varSizer = self.VariablesPeer.GetContainingSizer()
        # self.addRow()
        # print self.GetEffectiveMinSize()
        # self.SetMinSize(self.GetSize())

    def close(self, evt=None):
        self.EndModal(wx.ID_CANCEL)

    def run(self, evt):

        dpath, dfile = os.path.split(self.model.get('dataFile'))
        wild = '*.' + dfile.split('.')[1]
        fileDialog = wx.FileDialog(self,
                                   defaultFile=dfile,
                                   defaultDir=dpath,
                                   message="Save Data File As...",
                                   wildcard=wild,
                                   style=wx.SAVE + wx.OVERWRITE_PROMPT)
        result = fileDialog.ShowModal()
        if result == wx.ID_OK:
            path = fileDialog.GetPath()
            if self.model.run(path) == False:
                dialog = wx.MessageDialog(
                    self,
                    "Please check if all inputs (W and lag names) are valid.",
                    "Warning", wx.OK | wx.ICON_ERROR)
                dialog.ShowModal()
            else:
                self.results.append(path)
                dialog = wx.MessageDialog(
                    self, "The new variables were saved in, \n%s" % (path),
                    "Success", wx.OK | wx.ICON_INFORMATION)
                dialog.ShowModal()
                self.model.set('dataFile', path)
                if self.dialogMode:
                    self.EndModal(wx.ID_OK)

    def addRow(self, evt=None, varIDX=-1):
        """Add an additional row to the Variables Table"""
        if evt and evt.EventType == wx.EVT_CHOICE.typeId:
            varIDX = self.fakeVarsChoice.GetSelection()
            self.fakeVarsChoice.SetSelection(-1)

        # get old width,weight
        width, height = self.GetSize()

        parent = self.VariablesPeer.GetParent()
        var = C_spLagVariable(parent=parent)
        if varIDX != -1:
            var.model.set('var', varIDX, passive=True)
        self.model.addVar(var.model)
        self.varSizer.Add(var, flag=wx.ALL | wx.EXPAND)
        self.varSizer.Layout()

        self.Fit()

        self.model.update()
        var.model.update()

    def populate(self, model):
        data = self.model.get()
        for key in self.model.DATA_KEYS_ORDER:
            v = data[key]
            if key in self.dispatch:
                self.dispatch[key](value=v)
            else:
                print "Warning: %s, has not been implemented" % key

    def __wtFile(self, evt=None, value=None):
        if evt:
            if evt.EventType == wx.EVT_CHOICE.typeId:  # The drop down
                self.model.set('wtFile', self.weights.GetSelection())
            elif evt.EventType == wx.EVT_BUTTON.typeId:
                print "button"
                filter = "Weights File (*.gal; *.gwt)|*.gal;*.gwt"
                # "|*.gal|GWT file|*.gwt|XML Weights|*.xml"
                fileDialog = wx.FileDialog(self,
                                           message="Choose Weights File",
                                           wildcard=filter)
                result = fileDialog.ShowModal()
                if result == wx.ID_OK:
                    path = fileDialog.GetPath()
                    self.model.set('wtFile', path)
                else:
                    print "canceled"
        elif value is not None:
            if type(value) == int:
                self.weights.SetSelection(value)
            else:
                self.weights.Clear()
                if '' in value:
                    value.remove('')
                values = []
                for p in value:
                    if issubclass(type(p), basestring):
                        values.append(os.path.basename(p))
                    else:
                        values.append(p.name)
                self.weights.AppendItems(values)

    def __vars(self, evt=None, value=None):
        if value is not None:
            self.fakeVarsChoice.Clear()
            if '' in value:
                value.remove('')
            self.fakeVarsChoice.AppendItems(value)

    def __dataFile(self, evt=None, value=None):
        if evt:
            if evt.EventType == wx.EVT_BUTTON.typeId:
                filter = "Data File (*.dbf; *.csv)|*.dbf;*.csv"
                # "|*.gal|GWT file|*.gwt|XML Weights|*.xml"
                fileDialog = wx.FileDialog(self,
                                           message="Choose Data File",
                                           wildcard=filter)
                result = fileDialog.ShowModal()
                if result == wx.ID_OK:
                    path = fileDialog.GetPath()
                    self.model.set('dataFile', path)
                else:
                    print "canceled"
            elif evt.EventType == wx.EVT_TEXT.typeId:
                if not value == self.dataFile.GetValue():
                    self.model.set('dataFile',
                                   self.dataFile.GetValue())  # ,passive=True)
        elif value is not None:
            if value is False:
                print "warning datafile"
                self.dataFileWarn.Show()
            else:
                if not value == self.dataFile.GetValue():
                    self.dataFile.SetValue(value)
                self.dataFileWarn.Hide()
Ejemplo n.º 4
0
class C_CreateSpatialLag(SpatialLag_xrc.xrcCreateSpatialLag):
    def __init__(self, parent=None, dataFile=None, wtFiles=[''], vars=[''],
                 results=[], dialogMode=False):
        self.results = results
        self.dialogMode = dialogMode
        SpatialLag_xrc.xrcCreateSpatialLag.__init__(self, parent)
        self.width = None
        d = {}
        d['wtFiles'] = self.__wtFile
        d['wtFile'] = self.__wtFile
        d['vars'] = self.__vars
        d['dataFile'] = self.__dataFile
        self.dispatch = d

        self.weights.Bind(wx.EVT_CHOICE, self.__wtFile)
        self.fakeVarsChoice.Bind(wx.EVT_CHOICE, self.addRow)
        self.openWeights.Bind(wx.EVT_BUTTON, self.__wtFile)
        self.cancelButton.Bind(wx.EVT_BUTTON, self.close)
        self.okButton.Bind(wx.EVT_BUTTON, self.run)
        self.dataFileButton.Bind(wx.EVT_BUTTON, self.__dataFile)
        self.dataFile.Bind(wx.EVT_TEXT, self.__dataFile)

        self.model = M_CreateSpatialLag()
        self.model.addListener(self.populate)
        for wtFile in wtFiles:
            self.model.set('wtFile', wtFile)
        self.model.set('wtFile', 0)
        self.model.set('vars', vars)
        # hack to force initial data file to show up in GUI, even if it doesn't
        # exist
        self.model.data['dataFile'] = dataFile
        self.populate(None)
        self.model.set('dataFile', dataFile)

        # VariablesPeer is a hidden panel of size (0,0), this is necessary
        # because XRC does
        # not allow accessing sizers directly, so you get call a sizer item's
        # GetContainingSizer method
        self.varSizer = self.VariablesPeer.GetContainingSizer()
        # self.addRow()
        # print self.GetEffectiveMinSize()
        # self.SetMinSize(self.GetSize())

    def close(self, evt=None):
        self.Destroy()

    def run(self, evt):
        dpath, dfile = os.path.split(self.model.get('dataFile'))
        wild = '*.' + dfile.split('.')[1]
        fileDialog = wx.FileDialog(self, defaultFile=dfile, defaultDir=dpath,
                                   message="Save Data File As...",
                                   wildcard=wild, style=wx.SAVE +
                                   wx.OVERWRITE_PROMPT)
        result = fileDialog.ShowModal()
        if result == wx.ID_OK:
            path = fileDialog.GetPath()
            self.model.run(path)
            self.results.append(path)
            dialog = wx.MessageDialog(self,
                                      "The new variables were saved in, \n%s"
                                      % (path), "Success",
                                      wx.OK | wx.ICON_INFORMATION)
            dialog.ShowModal()
            self.model.set('dataFile', path)
            if self.dialogMode:
                self.close()

    def addRow(self, evt=None, varIDX=-1):
        """Add an additional row to the Variables Table"""
        if evt and evt.EventType == wx.EVT_CHOICE.typeId:
            varIDX = self.fakeVarsChoice.GetSelection()
            self.fakeVarsChoice.SetSelection(-1)

        # get old width,weight
        width, height = self.GetSize()
        var = C_spLagVariable(self.panel)
        if varIDX != -1:
            var.model.set('var', varIDX, passive=True)
        self.model.addVar(var.model)
        self.varSizer.Add(var, flag=wx.LEFT | wx.RIGHT | wx.EXPAND)
        self.varSizer.Layout()
        self.Fit()
        if not self.width:
            self.width, height = self.GetSize()

        self.SetMinSize((self.width, self.GetSize()[1]))
        self.SetSize((width, height))
        self.model.update()
        var.model.update()

    def populate(self, model):
        data = self.model.get()
        for key in self.model.DATA_KEYS_ORDER:
            v = data[key]
            if key in self.dispatch:
                self.dispatch[key](value=v)
            else:
                print "Warning: %s, has not been implemented" % key

    def __wtFile(self, evt=None, value=None):
        if evt:
            if evt.EventType == wx.EVT_CHOICE.typeId:  # The drop down
                self.model.set('wtFile', self.weights.GetSelection())
            elif evt.EventType == wx.EVT_BUTTON.typeId:
                print "button"
                filter = "Weights File (*.gal; *.gwt)|*.gal;*.gwt"
                # "|*.gal|GWT file|*.gwt|XML Weights|*.xml"
                fileDialog = wx.FileDialog(
                    self, message="Choose Weights File", wildcard=filter)
                result = fileDialog.ShowModal()
                if result == wx.ID_OK:
                    path = fileDialog.GetPath()
                    self.model.set('wtFile', path)
                else:
                    print "canceled"
        elif value is not None:
            if type(value) == int:
                self.weights.SetSelection(value)
            else:
                self.weights.Clear()
                if '' in value:
                    value.remove('')
                values = []
                for p in value:
                    if issubclass(type(p), basestring):
                        values.append(os.path.basename(p))
                    else:
                        values.append(p.name)
                self.weights.AppendItems(values)

    def __vars(self, evt=None, value=None):
        if value is not None:
            self.fakeVarsChoice.Clear()
            if '' in value:
                value.remove('')
            self.fakeVarsChoice.AppendItems(value)

    def __dataFile(self, evt=None, value=None):
        if evt:
            if evt.EventType == wx.EVT_BUTTON.typeId:
                filter = "Data File (*.dbf; *.csv)|*.dbf;*.csv"
                # "|*.gal|GWT file|*.gwt|XML Weights|*.xml"
                fileDialog = wx.FileDialog(
                    self, message="Choose Data File", wildcard=filter)
                result = fileDialog.ShowModal()
                if result == wx.ID_OK:
                    path = fileDialog.GetPath()
                    self.model.set('dataFile', path)
                else:
                    print "canceled"
            elif evt.EventType == wx.EVT_TEXT.typeId:
                if not value == self.dataFile.GetValue():
                    self.model.set(
                        'dataFile', self.dataFile.GetValue())  # ,passive=True)
        elif value is not None:
            if value is False:
                print "warning datafile"
                self.dataFileWarn.Show()
            else:
                if not value == self.dataFile.GetValue():
                    self.dataFile.SetValue(value)
                self.dataFileWarn.Hide()