I was thinking you'd do: RSWE.Resources.SomeResource
Accessing the static property the resource manager expose instead of trying to open it. I just looked at one of our Resources files though and realized that all of the resources get declared as internal static so they won't be accessible to Python code by default. You could run with the -X:PrivateBinding flag (which isn't really recommended except for development scenarios). I'm not sure if VS would be upset with you or undo the changes if you made the properties public instead of private. If that doesn't work then it seems like you're stuck w/ the solution you came up with. Regarding Ops.GetDynamicTypeFromType(...) not being documented. The IronPython runtime actually exposes a lot of functionality (all via Ops) which is public but used primarily for the purposes of exposing the runtime's functionality to dynamically generated code. That's available for your use but we reserve the right to change it in future versions. Unfortunately there are still occasions when it's the only way to accomplish what you want to achieve. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Stoy Sent: Monday, December 18, 2006 4:26 PM To: Discussion of IronPython Subject: Re: [IronPython] Accesses static ResourceManager from IronPython Thanks for the response. I tried the first option (GetDynamicTypeFromType), but that doesn't seem to work. Here is a snippet of code: EngineOptions engineOptions = new EngineOptions(); engineOptions.ClrDebuggingEnabled = true; IronPython.Compiler.Options.GenerateModulesAsSnippets = true; PythonEngine engine = new PythonEngine(engineOptions); EngineModule rswe = engine.CreateModule("RSWE", true); rswe.Globals.Add("ResourceManager", PublicResources.ResourceManager); rswe.Globals["Resources"] = IronPython.Runtime.Operations.Ops.GetDynamicTypeFromType(typeof(PublicResources)); engine.Import("RSWE"); For testing, I added the public ResourceManager from my PublicResources class to the globals. I then tried your suggestion of using GetDynamicTypeFromType (which, by the way, doesn't seem to be documented in the IronPython docs..), but none of the public attributes are there in Python..in fact the type doesn't seem correct. Here is some output from my Python console in my app: > from RSWE import Resources > print dir() ['RSWE', 'Resources', '__builtins__', '__name__', 'clr', 'sys'] > print dir(Resources) ['Equals', 'Finalize', 'GetHashCode', 'GetType', 'MakeDynamicType', 'MemberwiseClone', 'Reduce', 'ReferenceEquals', 'ToString', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__'] > x = Resources() Cannot create instances of <type 'PublicResources'> > x = Resources.Open type object 'PublicResources' has no attribute 'Open' I can, however, access the resources using ResourceManager: > icon = RSWE.ResourceManager.GetObject("Open") > print icon (Icon) Any ideas? Thanks, Chris. ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dino Viehland Sent: Monday, December 18, 2006 6:43 PM To: Discussion of IronPython Subject: Re: [IronPython] Accesses static ResourceManager from IronPython Sorry, that 1st line should have been Ops.GetDynamicTypeFromType(typeof(PublicResources)). From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dino Viehland Sent: Monday, December 18, 2006 3:42 PM To: Discussion of IronPython Subject: Re: [IronPython] Accesses static ResourceManager from IronPython If you want to follow the way you're currently doing it you can just publish the DynamicType in Globals, eg: Globals['foo'] = Ops.GetDynamicType(typeof(PublicResources)); You can also add a reference to your C# DLL and then the user can import all of your public types / namespaces (although that may not be what you want). E.g.: pe.Sys.AddReference(typeof(SomeTypeInYourAssembly).Assembly); then users can either do import Namespace or import SomeType (assuming the type has no namespace) or from Namespace import SomeType. This would be the equivalent to if the user did: import clr clr.AddReference('your_assembly_name') import ... From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Stoy Sent: Monday, December 18, 2006 3:29 PM To: [email protected] Subject: [IronPython] Accesses static ResourceManager from IronPython Hello all, I'm working on embedding IronPython into a larger C# application to allow end-users the ability to write scripts. One thing I want to do is provide a set of icon resources in the C# code and expose them to IronPython so a user can access them. I created a new Resource.resx file called "PublicResources" in my C# application. This creates a class called "PublicResources" that contains a set of static methods to access the resources in a type-safe way. Although I can expose the underlying ResourceManager instance to IP, what I really want is the class PublicResources exposed so I can us it in my IronPython code. For example, in C# I would say: Form myForm = new Form(); myForm.Icon = PublicResources.MyFormIcon; and in IronPython, I want to say: myForm = Form() myForm.Icon = PublicResources.MyFormIcon So, I guess this boils down to "how do I expose static classes from C# to IronPython?" (On a side note, if anyone knows where there is some documentation on the proper way to expose .NET class to IronPython I would appreciate it. Currently I'm creating a new module with PythonEngine.CreateModule(), adding objects to the Globals, and importing it using PythonEngine.Import()...but I have no idea if that is the right way to do it.) Thanks a lot for any help. Chris.
_______________________________________________ users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
