Jeff,

 

I would not know any examples of using the DataGridView in Python.

But I did use many other view classes in  IronPython, since I’ve been working on a GUI framework in IP.

What I used as doc was: .NET SDK 2.0 documentation and Python 2.4 Manuals.

 

For me that worked fine.

There’s remarkably little difference between using them from C# and from IP, even at dealing with event handlers, properties and .NET datastructures.

 

Since there probably aren’t too many examples around yet, here’s a fragment of code to illustrate this:

 

-          Instantiate a TreeView

-          Add an event handler to its MouseUp event to show a ContextMenuStrip that was built up by a widget creation function defined elsewhere

 

from sys import *

LoadAssemblyByName("System.Windows.Forms")

from System.Windows import Forms

class …:                         

       def createWidget (self):

              …

self.widget = Forms.TreeView ()   # Instantiate .NET class

self.widget.Dock = Forms.DockStyle.Fill  # Set properties, just like you would in C#

self.widget.HideSelection = False # Same

self.widget.AllowDrop = True      # Same

if self.contextMenuView:

self.widget.ContextMenuStrip = self.contextMenuView.createWidget ()  # Get populated context menu strip

              self.widget.MouseUp += lambda sender, event: event.Button != Forms.MouseButtons.Right or sender.ContextMenuStrip.Show (sender, event.Location)      # Add event handler to show context menu at mouse up

 

.NET datastructures can usually be betraversed with Python iterators without any special tricks:

 

       def bareWrite (self):

              expansionDictionary = {}

              self.fillExpansionDictionary (self.widget.Nodes, (), expansionDictionary)  # Will traverse Nodes, see function def below

              self.widget.Nodes.Clear () # Call member, just like you would in C#

              self.writeTree (self.treeNode.new, self.widget.Nodes, (), expansionDictionary) # Pass Forms.TreeView.Nodes property as param, just like in C#

 

       def fillExpansionDictionary (self, treeViewNodes, hashPath, expansionDictionary):

                 for treeViewNode in treeViewNodes:  # Treat treeViewNodes as an ordinary Python iterable datastructure, even though it is a reference to Forms.TreeView.Nodes, an instance of public class TreeNodeCollection: IList, ICollection, IEnumerable

 

                     if self.transformer:

                           newHashPath = hashPath + (treeViewNode.Tag, )   # Use .NET properties just as you would in C#

                     else:

                           newHashPath = hashPath + (treeViewNode.Text,                        

                     expansionDictionary [newHashPath] = treeViewNode.IsExpanded   # Yet another property

                     self.fillExpansionDictionary (treeViewNode.Nodes, newHashPath, expansionDictionary)

 

Probably you just should start experimenting.

What helped me tremendously  is the fact that IP is interpreted, rather than compiled.

I can experiment in seconds, even from the command line, although I prefer assembling small code fragments in an editor to try out stuff.

 

Currently I am using IP 0.9.5 as interpreter, running IP 0.9.6 beforehand as a syntax checker, since that version has improved error reporting but some run time issues.

(for wich a fix is already on this mailing list (thanks Dino) but I haven’t yet found the time to try this out)

 

Hope this helps

Jacques de Hooge

[EMAIL PROTECTED]

 

 

 

 

 

 

 

 

-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens jeff sacksteder
Verzonden: Thursday, December 22, 2005 4:14 PM
Aan: [EMAIL PROTECTED];
Discussion of IronPython
Onderwerp: Re: [IronPython] DataGridView

 

I'm sorry, I meant in Python.

_______________________________________________
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to