I am currently building an app that displays the video feed of a webcam/external camera. I have written the GUI with C# and in WPF. I have been asked to integrate a python code which does image analysis of the displayed feed. I'm not sure exactly where to begin with this.
I have tried to look into IronPython but the documentation isn't too clear so I'm quite lost. If anyone can point me in the right direction, that would be greatly appreciated.
There are at least two approaches you can take,
Calling Python Script Using New Process Initialization
Calling the Python Script Using IronPython Interpreter, Hosted in Your .NET Application
Check the below post for more information:
https://betterprogramming.pub/running-python-script-from-c-and-working-with-the-results-843e68d230e5
Another option is just to separate your application to microservices, and use python as one.
check this: https://softwareengineering.stackexchange.com/questions/385936/how-can-i-integrate-python-code-with-c-code
When it comes to using Python inside .NET applications so Python code can interact with .NET objects, Python.NET and IronPython are two popular choices.
We have implemented our code writing/scripting/debugging solutions for both of these engines, you may read a bit about pros and cons here
Related
Short story: is there a way to write a desktop application with a GUI in HTML5 and core in a cross-platform language like python (or even C#/Mono)?
Longer story: I'm a C# developer, for small personal projects I seldom do, running both under Windows and OSX, I use C# (Mono) with a frontend leveraging on Eto.Forms
I'd like to understand if there's a mature way to achieve the same results using an HTML5 GUI, since I'd like to learn that and believe it could be a good option for near-future Windows desktop UIs (or otherwise a nice tool to have in my skillset). Of course if the code running behind the scenes is C# I'll be more than happy, but also getting my feet wet in another, maybe more cross-platform like python would be good.
At this stage I'm not interested in any mobile-oriented solution.
Electron (formerly Atom shell) has really matured as of late. In fact it's what VSCode is built on.
There's a great tutorial and starter code on using Angular 2 and Typescript, and you can even use VSCode to write and build it.
For me this is the best way to transition from the WPF world to HTML5.
the NW.js look pretty promising... you might even be able to use TypeScript which would be much closer to C# than plain ol' js. If you're open to using PHP, you can check out the nightrain project https://github.com/naetech/nightrain.
Give http://www.tidesdk.org/ a try.
Your app will run on Windows 8, MacOS and Linux. You can use HTML5, Javascript and CSS3.
But you can also extend the functionality of your app with a scripting language you are comfortable with. TideSDK currently supports Python, PHP, and Ruby.
I have recently worked with Chromium Embedded Framework, basically a browser component for WPF an WinForms. It works very well and provides kind of a two-way interoperability from website to .NET-app and vice versa. Basically, you:
Create a WPF desktop app
Include CEFSharp and place a full-screen browser on the window
Call methods in JavaScript:
// .NET
var mainFrame = browser.GetMainFrame();
mainFrame.ExecuteJavaScriptAsync("any js code");
Bind a .NET-object
// .NET
browser.RegisterJsObject("boundObject", this);
Call methods on a bound .NET-object from the website/JS:
// JS
boundObject.someMethod();
On this basis you could build a mediation layer (ViewModels, controllers, ...) between HTML/JS-UI and .NET logic...
I wrote an APP with http://kivy.org/ it is capable to create apps for different systems.
Qt node https://github.com/arturadib/node-qt seems also interesting, but i did not test it myself.
And last https://chrome.google.com/webstore/launcher
You can create web apps for chrome, which should run in supported systems.
Kivy is a Python solution. Qt node is maybe what you are looking for.
Here are some nice tutorials for kivy:
https://www.youtube.com/playlist?list=PLQVvvaa0QuDe_l6XiJ40yGTEqIKugAdTy
NW.js
But it's Javascript (node), not python nor C#.
A very interesting project I think is Chromium Embedded Framework. You basically embed a (stripped down) web browser in your application. For python, many GUI Toolkits are supported. Check this for more information.
Since you are used to C#, maybe Java with JavaFX and FXML is an option. FXML is not HTML but you can style it with CSS as well. You can also use Scene Builder with it for faster UI creation. Many JVM languages support this toolkit so Jython instead of Java will also work. I will recommend Java however, because the support for other languages, while there, is not perfect yet.
Using C# and the Windows App Store WebView is also an option. You can check MSDN for more information.
I am sure there are other options (Kivy, Node.js, etc.) as well. Some of them are already mentioned in this thread.
I would recommend Node-Webkit which is based on nodejs.You can still use some python scripts to do some backend job integrated with Node-Webkit which is easy to deal with.I've already saw some successful applications using this(like wunderlist).TideSDK is another choice but the python support in TideSDK is not mature enough.The Node-Webkit project hosted at
https://github.com/nwjs/nw.js/
I am really not asking for any specific lines of code here, but more along the lines of someone being able to explain to me the idea of it to help me have a better understanding. I am very new to coding with PowerShell scripts let alone calling them in a C# app. Would anyone be able to explain or even point me in the right direction so I can learn about what I would need to do here. I have a basic "Hello World" script that I would like to call from a C# Windows Service using VS2010. I have seen examples around the internet, but they are very brief and don't really teach the concept behind it.
Any help would be much appreciated!
Thanks!
Here is a pretty good discussion on how to call Powershell from C#: http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C
I suggest you start with the RunScript function and add it to a VS2010 console application. Main() would then invoke RunScript something like RunScript( "echo 'hello from PS';get-date; get-culture; ").
Windows services have quite a few differences from a normal console application. You can read about how to write a windows service on MSDN, but if you've never coded before, you have a steep learning curve in front of you.
There is a service from an old Resource Kit call srvany.exe (Google it) which would run any console app as a service. However in Windows Vista (and above) services were restricted from accessing the desktop, so srvany could only be successful in Vista and above if you EXE doesn't need keyboard input or need to write to the display. However your EXE could read/write files.
This is what I was able to get to work for me.
I basically followed the information that I found from this post, but changed a couple of things to get it to work for me: Problem with calling a powershell function from c#
For example, for the ps.AddCommand("BatAvg") I just added my own function in my .ps1 file ps.AddCommand("PS1FunctionName") and didn't add any parameters since it was not necessary. The answer was staring me in the face the whole time, I just didn't know where I needed to place it in my windows service. I was able to figure that out and now I am cruising!
Also, don't forget to reference using System.Management.Automation and using System.Management.Automation.Runspaces in your code (for all the future people that may look at this).
I have my main program in C++, but now I need to build a beautiful application and I know that WPF is easy and makes for beautiful apps. Can WPF work with C++ or C# and C++? (If yes, how?) Is WPF the best thing for me?
You can use WPF in a managed C++ project, but you're better off keeping your C++ in a separate assembly and referencing it from a C# or VB WPF project.
Yes, you can develop a GUI using WPF framework in Managed C+ or C++/CLI. But they're not Standard C++, hence not cross-platform.
If you just want a GUI for your application written in C++, then you may try Qt as well. The advantage in Qt is that its completely in C++. Not Microsoft Managed C++. The second advantage is that its cross-platform toolkit. That means, you can run your app in Windows, Linux, Mac, and on other machines as well.
Have a look at its documentation
Qt Reference Documentation
It has lots of tools for fast development such as Qt Creator, Qt Designer and others. You can see all of them by browsing the above link.
WPF is dead along with Silverlight, remember, MS says its HTML5 only from now on :)
Using WPF in your C++ app can be achieved using hwndSource, but its not the optimal solution, for that you will have to create C# or VB.NET GUI app, and use it to communicate with your C++ app via some form of IPC.
There are alternatives, probably the best one is to write your GUI using Qt, which is very well respected. You can get similar features to WPF by writing using QML alongside the old forms-based system (which means you get all the development speed of using the old, boring text boxes and the like, and the fancy GUI benefits of using the new declarative UI system, all in the same system. sweet).
Of course, a decent option is to make your app into a back-end server process and call it from a web-server based HTML5 UI. That's pretty future proof, easy to deploy to clients, and as modern as you're likely to get.
I have to develop a plug-in for an external program using C#.
I am an experienced Qt/C++ programmer and the core of the plug-in is programmed in C++.
My first idea was to program GUI in C#, which write settings to a text file and then call the core C++ code, as an external process, with this textfile as an input.
However I also noticed that there is something called the QAxServer Module in Qt that should make it possible to run Qt/C++ GUI code from C# (trough ActiveX).
I experimented a bit with this and it seemed a bit "shaky".
Do you have any experiences with this you could share?
I would look at writing a C++/CLI (i.e. Managed C++) shim to launch your plug-in and be the bridge between it and the main application.
This will allow you to call into (or be called from) the C# application on one side and talk native C++ on the other.
http://techbase.kde.org/Development/Languages/Qyoto
Qyoto seems to be the most active Qt binding for .NET.
There is also the "QT for .NET" project.
Lately I am preparing myself to develop yet another game in XNA C#.
The last time I worked on a game in XNA C#, I ran into this problem of having to add maps and customizable data into the game. Each time I want to add in new content or change some values to the game character or something, I had to rebuild the whole game or what - which can take quite some time.
Is there any way which I can write gaming scripts to load the content that can be interpreted by my XNA C# game without having to compile? I am looking at hopefully Javascript.
I would hope that I can add in functions and other small API which can be called from the external gaming script to manipulate the game or load data so on. I am not concerned about the game being hacked since it's quite early yet - the development is of much priority.
Any help would be greatly appreciated.
You can try Jint which is a open source Javascript interpreter written in C#
The compact framework doesn't include System.Reflection.Emit, which means you can't use IronPython. I recommend LUA, and you can find an XNA interpreter implementation with open source here
Would IronPython be more appropriate? That should work well on "full" framework - but it looks like it might not work (yet) on xbox 360 (which uses compact framework).
For an IronPython / xna example, see here.