Esempio n. 1
0
 def view_to_config(self):
     # continue with textToTuple in gen_utils
     stdText = self._view_frame.stdTextCtrl.GetValue()
     self._config.standardDeviation = gen_utils.textToTypeTuple(
         stdText, self._config.standardDeviation, 3, float)
     
     cutoffText = self._view_frame.radiusCutoffTextCtrl.GetValue()
     self._config.radiusCutoff = gen_utils.textToTypeTuple(
         cutoffText, self._config.radiusCutoff, 3, float)
Esempio n. 2
0
    def view_to_config(self):
        # continue with textToTuple in gen_utils
        stdText = self._view_frame.stdTextCtrl.GetValue()
        self._config.standardDeviation = gen_utils.textToTypeTuple(
            stdText, self._config.standardDeviation, 3, float)

        cutoffText = self._view_frame.radiusCutoffTextCtrl.GetValue()
        self._config.radiusCutoff = gen_utils.textToTypeTuple(
            cutoffText, self._config.radiusCutoff, 3, float)
Esempio n. 3
0
    def view_to_config(self):
        for configTuple in self._configList:

            widget = self._widgets[configTuple[0:5]]
            typeD = configTuple[2]

            # some widgets are only for display, we won't process their values
            if typeD.startswith('display_only'):
                continue

            if configTuple[3] == 'choice':
                wv = widget.GetStringSelection()

                # if the user has asked for a base:int, we give her
                # the index of the choice that was made; otherwise
                # we return the string on the choice at that position
                if typeD.startswith('base:'):
                    castString = typeD.split(':')[1]
                    if castString == 'int':
                        wv = widget.GetSelection()

            elif configTuple[3] == 'radiobox':
                wv = widget.GetSelection()

            elif configTuple[3] == 'tupleText':
                widgets = widget
                wv = []
                for w in widgets:
                    wv.append(w.GetValue())

                wv = ','.join(wv)

            elif configTuple[3] == 'filebrowser':
                # get value from the widget
                wv = widget.GetValue()
                # if no extension has been supplied, but the programmer
                # has specified a default, append this.
                if not os.path.splitext(wv)[1]:
                    wv += configTuple[5].get('defaultExt')

            else:
                wv = widget.GetValue()

            if typeD.startswith('base:'):
                # we're only supporting 'text' widget so far
                castString = typeD.split(':')[1]
                try:
                    val = eval('%s(wv)' % (castString, ))
                except ValueError:
                    # revert to default value
                    val = eval('self._config.%s' % (configTuple[1], ))
                    widget.SetValue(str(val))

            elif typeD.startswith('tuple:'):
                # e.g. tuple:float,3
                castString, numString = typeD.split(':')[1].split(',')
                val = gen_utils.textToTypeTuple(
                    wv, eval('self._config.%s' % (configTuple[1], )),
                    int(numString), eval(castString))

                if configTuple[3] == 'tupleText':
                    for i in range(len(widgets)):
                        widgets[i].SetValue(str(val[i]))

                else:
                    widget.SetValue(str(val))

            else:
                raise ValueError, 'Invalid typeDescription.'

            setattr(self._config, configTuple[1], val)
Esempio n. 4
0
    def _createImplicitFromUI(self):
        cf = self.slice3dVWR.controlFrame
        implicitType = cf.implicitTypeChoice.GetStringSelection()
        implicitName = cf.implicitNameText.GetValue()
        
        if implicitType in self._implicitTypes:
            if implicitName in self._implicitsDict:
                md = wx.MessageDialog(
                    self.slice3dVWR.controlFrame,
                    "You have to enter a unique name for the new implicit. "
                    "Please try again.",
                    "Information",
                    wx.OK | wx.ICON_INFORMATION)
                md.ShowModal()

                return
                
            
            #implicitWidget = None
            
            ren = self.slice3dVWR._threedRenderer


            # let's find out which bounds the user wanted
            cf = self.slice3dVWR.controlFrame
            bt = cf.implicitBoundsChoice.GetStringSelection()

            pi = None
            bounds = None

            bti = self._boundsTypes.index(bt)

            if bti == 0:
                # primary input
                pi = self.slice3dVWR.getPrimaryInput()
                if pi == None:
                    md = wx.MessageDialog(
                        cf,
                        "There is no primary input. "
                        "Please try another bounds type.",
                        "Information",
                        wx.OK | wx.ICON_INFORMATION)
                    md.ShowModal()

                    return

            elif bti == 1:
                # selected object
                objs = self.slice3dVWR._tdObjects._getSelectedObjects()
                if not objs:
                    md = wx.MessageDialog(
                        cf,
                        "No object has been selected. "
                        "Please try another bounds type or select an object.",
                        "Information",
                        wx.OK | wx.ICON_INFORMATION)
                    md.ShowModal()

                    return

                try:
                    prop = self.slice3dVWR._tdObjects.findPropByObject(objs[0])
                    bounds = prop.GetBounds()
                except KeyError:
                    # this should never ever happen
                    return

            elif bti == 2:
                # visible objects
                bounds = self.slice3dVWR._threedRenderer.\
                         ComputeVisiblePropBounds()

            elif bti == 3:
                # manual
                v = cf.implicitManualBoundsText.GetValue()
                t = gen_utils.textToTypeTuple(v, (-1, 1, -1, 1, -1, 1),
                                             6, float)
                cf.implicitManualBoundsText.SetValue(str(t))
                        

            if bounds:
                b0 = bounds[1] - bounds[0]
                b1 = bounds[3] - bounds[2]
                b2 = bounds[5] - bounds[4]

                if b0 <= 0 or b1 <= 0 or b2 <= 0:
                    # not good enough...                    
                    bounds = None

                    md = wx.MessageDialog(
                        cf,
                        "Resultant bounds are invalid. "
                        "Please try again.",
                        "Information",
                        wx.OK | wx.ICON_INFORMATION)
                    md.ShowModal()

                    return
                    
            # at this stage, you MUST have pi or bounds!
            self._createImplicit(implicitType, implicitName, bounds, pi)
Esempio n. 5
0
    def view_to_config(self):
        for configTuple in self._configList:

            widget = self._widgets[configTuple[0:5]]
            typeD = configTuple[2]

            # some widgets are only for display, we won't process their values
            if typeD.startswith("display_only"):
                continue

            if configTuple[3] == "choice":
                wv = widget.GetStringSelection()

                # if the user has asked for a base:int, we give her
                # the index of the choice that was made; otherwise
                # we return the string on the choice at that position
                if typeD.startswith("base:"):
                    castString = typeD.split(":")[1]
                    if castString == "int":
                        wv = widget.GetSelection()

            elif configTuple[3] == "radiobox":
                wv = widget.GetSelection()

            elif configTuple[3] == "tupleText":
                widgets = widget
                wv = []
                for w in widgets:
                    wv.append(w.GetValue())

                wv = ",".join(wv)

            elif configTuple[3] == "filebrowser":
                # get value from the widget
                wv = widget.GetValue()
                # if no extension has been supplied, but the programmer
                # has specified a default, append this.
                if not os.path.splitext(wv)[1]:
                    wv += configTuple[5].get("defaultExt")

            else:
                wv = widget.GetValue()

            if typeD.startswith("base:"):
                # we're only supporting 'text' widget so far
                castString = typeD.split(":")[1]
                try:
                    val = eval("%s(wv)" % (castString,))
                except ValueError:
                    # revert to default value
                    val = eval("self._config.%s" % (configTuple[1],))
                    widget.SetValue(str(val))

            elif typeD.startswith("tuple:"):
                # e.g. tuple:float,3
                castString, numString = typeD.split(":")[1].split(",")
                val = gen_utils.textToTypeTuple(
                    wv, eval("self._config.%s" % (configTuple[1],)), int(numString), eval(castString)
                )

                if configTuple[3] == "tupleText":
                    for i in range(len(widgets)):
                        widgets[i].SetValue(str(val[i]))

                else:
                    widget.SetValue(str(val))

            else:
                raise ValueError, "Invalid typeDescription."

            setattr(self._config, configTuple[1], val)