none
Windows.Forms.RadioButton crashes when I select the second button from a list RRS feed

  • Question

  • Dear Windows,

    I run this code (at the bottom) from within a host application (Revit). The code works perfectly from a windows command line (python radios.py). The behavior should be "when another radiobutton is checked, all others are uncheked", and inside of Revit, as I check the second button I get this crash.

    Unhandled exception has occurred in a component in your application. If you click Continue, the application will ignore this error and attempt to continue.

    Absolute path information is required.


    "Details":

    See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.
    
    ************** Exception Text **************
    System.ArgumentException: Absolute path information is required.
       at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
       at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
       at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
       at System.Windows.Forms.Control.ControlVersionInfo.GetFileVersionInfo()
       at System.Windows.Forms.Control.ControlVersionInfo.get_CompanyName()
       at IronPython.NewTypes.System.Windows.Forms.RadioButton_22$22.#base#get_CompanyName()
       at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
       at Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0 arg0, T1 arg1, T2 arg2)
       at IronPython.Runtime.Types.BuiltinFunction.Call0(CodeContext context, SiteLocalStorage`1 storage, Object instance)
       at IronPython.Runtime.Types.ReflectedProperty.CallGetter(CodeContext context, PythonType owner, SiteLocalStorage`1 storage, Object instance)
       at IronPython.Runtime.Types.ReflectedProperty.TryGetValue(CodeContext context, Object instance, PythonType owner, Object& value)
       at IronPython.Runtime.Types.PythonType.TryGetNonCustomMember(CodeContext context, Object instance, String name, Object& value)
       at IronPython.Runtime.Operations.PythonOps.ObjectGetAttribute(CodeContext context, Object o, String name)
       at IronPython.Runtime.Operations.CustomTypeDescHelpers.GetPropertiesImpl(Object self, Attribute[] attributes)
       at IronPython.Runtime.Operations.CustomTypeDescHelpers.GetProperties(Object self)
       at System.ComponentModel.TypeDescriptor.MergedTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetProperties()
       at System.ComponentModel.TypeDescriptor.GetPropertiesImpl(Object component, Attribute[] attributes, Boolean noCustomTypeDesc, Boolean noAttributes)
       at System.Windows.Forms.RadioButton.PerformAutoUpdates(Boolean tabbedInto)
       at System.Windows.Forms.RadioButton.set_Checked(Boolean value)
       at IronPython.NewTypes.System.Windows.Forms.RadioButton_22$22.OnClick(EventArgs e)
       at System.Windows.Forms.RadioButton.OnMouseUp(MouseEventArgs mevent)
       at IronPython.NewTypes.System.Windows.Forms.RadioButton_22$22.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at IronPython.NewTypes.System.Windows.Forms.RadioButton_22$22.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)





    radios.py

    # Windows utilities and IronPython stuff
    import clr
    clr.AddReference("System.Drawing")
    import System.Drawing as wdrawing
    clr.AddReference("System.Windows.Forms")
    import System.Windows.Forms as wforms
    
    
    class RoadRadioButton(wforms.RadioButton):
    
        def __init__(self, name, radios_collection):
    
            self.radios_collection = radios_collection
            
            self.Text = name
            self.MouseHover += self.onMouseHover
            self.MouseLeave += self.onMouseLeave
            self.CheckedChanged += self.checkedChanged
            print("init %s" % self.Text)
    
        def onMouseHover(self, sender, args):
            print("onMouseHover %s " % self.Text)
    
        def onMouseLeave(self, sender, args):
            print("onMouseLeave %s " % self.Text)
    
        def checkedChanged(self, sender, args):
            print("checkedChanged %s " % self.Text)
            for cb in self.radios_collection:
                if cb.Checked and cb != self:
                    cb.Checked = False
            self.Checked = True
    
    
    
    class RadiosForm(wforms.Form):
        
        def __init__(self, *args, **kwargs):
    
            self.Text = "" if "title" not in kwargs else kwargs["title"]
            self.num = 1 if "num" not in kwargs else int(kwargs["num"])
    
            self.AutoSize = True
            #self.Location = wdrawing.Point(20,20)
    
            print("init %s " % self.Text)
    
            # creation of a title
            l = wforms.Label()
            l.Text = "Init radio form: list of buttons:"
            l.AutoSize = True
            l.Location = wdrawing.Point(10, 10)
            self.lab_intro = l
            self.Controls.Add(self.lab_intro)
    
    
            # addition of all radios with events 
            self.radios = list()
            self.groupbox = wforms.GroupBox()
            lineno, height = 20, 25
            for i in range(1, self.num+1):
                rbname = "radio %d" % i
                print("\t\tprocessing %s" % rbname)
                rb = RoadRadioButton(rbname, self.radios)
                rb.Location = wdrawing.Point(30, lineno + height)
                rb.AutoCheck = True
                rb.AutoSize = True
                #self.radios.append(rb)
                self.groupbox.Controls.Add(rb)
                #self.Controls.Add(self.radios[len(self.radios)-1])
                lineno += height
            self.Controls.Add(self.groupbox)
    
            # cancel button
            b = wforms.Button()
            b.Text = "Cancel"
            b.Height = 30
            b.Width = 100
            b.Location = wdrawing.Point(170,310)
            b.Click += self.close
            self.btn_cancel = b
            self.Controls.Add(self.btn_cancel)
    
        def close(self, sender=None, args=None):
            print(">>> closing %s" % self.Text)
            self.Dispose()
    
    
    f = RadiosForm(title="Radios Form", num=5)
    f.ShowDialog()
    
    




    Thursday, April 4, 2019 3:33 PM

All replies

  • Hi angelo.mastro,

    This forum discuss client application development using Windows Forms controls and features by using c#, and your issue is more related to Iron Python, I would suggest that you could post your feedback on the following link.

    https://ironpython.net/support/

    Best regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Kiodos Friday, April 5, 2019 5:28 AM
    Friday, April 5, 2019 5:20 AM
  • solved myself. apparently trouble started because I "dared" to make my own RadioButton() class, inheriting from the original MSFT Windows.Forms.RadioButton(). The original class works fine. 
    Friday, April 5, 2019 1:42 PM