• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

C# and Python Integration

bigoh5

n00b
Joined
Mar 19, 2009
Messages
12
Hi all,

I am working on a project which requires a C# interface that commands a map generating program, which is written in python. The C# interface runs the python code and then displays the map in a windows form. One of the functionality I would like to implement is to display additional information about the map when the mouse hovers over a point on the graph. My question was how to best go about this? Will it be too difficult to do? Should I be looking to use IronPython (which compiles python into C#) to do this? Any pointers in the right direction would be useful.

Thanks,
 
You've not given nearly enough information to evaluate your situation and answer your question.
 
Sorry about the lack of information.

So, I have a C# interface which initiates a python script to run. The python script opens up a data file and creates map using matplot library. It then saves this file as an image file and the windows form opens up the image file. The goal is to get additional information to pop up when hovering over a data point. I assume saving the file as an image and opening it in a form will make it harder to do what I want. But I am not sure how else to go about this.

Not sure if this is enough information.
 
What kind of additional data do you want to get? If it's in the data file that python uses to create the image file, can you use C# to access that same data file and extract the info directly?

Alternatively, if the python script using matplotlib, can also output the data you want via xml, csv or some format you can use C# to access it. If you want to write the data to a database, Python (I think 2.5 and higher) comes with a built-in SQLite db too so you could output that data to SQLite and have C# access your db.

Of course you'd have to know Python to alter the script. But Python is easy to learn. I've been a C#/ASP.NET and PHP developer but I love Python. It's a handy language to know since it works on Windows, Mac and Linux.

Like you mentioned, perhaps is possible to use IronPython but you'd have to see if there is a working C extension for the matplotlib library for IronPython. Regular python is often referred to as CPython and helps distinguish from IronPython, the Dot Net implmentation.

You can take a look at IronClad which is a project trying to just that, and I remember saying they were working on getting C extensions for matplotlib.
http://code.google.com/p/ironclad/

There's a google group devoted to the project here:
http://groups.google.com/group/c-extensions-for-ironpython

If time is an issue to get this project done, it might be just easier to what I suggest earlier, to alter your original python(CPython) script and output data that can be accessed by your C# interface. You'd have to learn Python, but if you learn IronPython for Dot Net, you'd have to learn Python anyway too.
 
perhaps this a better question, but a less realistic possibility. Is it possible to import the figure browser from python (what appears when you call the py.show() function) into a C# application? seems highly improbable.
 
Sorry about the lack of information.

So, I have a C# interface which initiates a python script to run. The python script opens up a data file and creates map using matplot library. It then saves this file as an image file and the windows form opens up the image file. The goal is to get additional information to pop up when hovering over a data point. I assume saving the file as an image and opening it in a form will make it harder to do what I want. But I am not sure how else to go about this.

Not sure if this is enough information.
Look up the MouseHover and MouseLeave events.

If you insist on generating a single map image and displaying it in your form, you try generating a file with the coordinates of the data nodes on your image, and the corresponding information for each data node. In C#, add a series of invisible/transparent labels positioned over these data nodes on your image.

When your mouse hovers over this, you can have your additional information pop up.

It's not necessarily the cleanest way of doing things, but it might work.
 
Back
Top