Creating a code editor.

Ravi Dhoble

Member
Joined
Dec 11, 2019
Messages
13
Programming Experience
1-3
Hello,

I want to create a code editor module of my own, like windows forms or WPF. A little background about this idea, If anybody has ever worked with National Instruments Teststand software, there you can create a sequence file (.seq) which is a kind of custom script file, which only opens in NI teststand. FYI, NI Teststand is mainly used in the factory automation-related work.. (not only for this purpose but for a variety of applications.). So when you create a sequence, you can drag and drop different functions (for eg. subsequence, if-else, for loop, message popup func. etc. ). There it is termed as "steps". For each step, you can add customize logics, set variables and invoke different compiler modules that will execute the step, generate the results.

Okay, so I want to design a similar "Script editor" engine/module in c# and I thought to use IronPython, which will allow me a create a script file (.py) automatically whenever I will drag n drop GUI elements like buttons, step types n all. Since user will design a script in runtime so, I need interpreter to check syntax and other things in the runtime and that's why I thought to use IronPython. I read many documents on the web related to this, but don't know exactly how to approach this? I am curious to know how binding works, how Windows forms works..like when a control is added, it automatically links its functionality to the designer or code file. So how this works?
 
I think you are conflating the typical meaning of "binding" in WPF and WinForms context with code generation. In WPF and WinForms, binding means exposing (and/or tunneling) the current state of the data model of your application to the UI. My understanding of your use of "binding" is mapping each of the blocks that the user has added on the UI into associated generated IronPython code. Yes, they are similar ideas and concepts, but at different levels of abstraction. The WPF/WinForms binding is down at the data level, while your binding is up at the module/code logic level.

Also, I'm not sure if you are using the term "binding" for determining where a block "attaches" itself to one or more other blocks. E.g. An action block will place itself as the child of a branch-if block when you drag the action block on top of a branch-if block.

Any which way, you will have to write custom code to detect when things change in the UI and somehow map those back into the IronPython modules. I highly suggest looking at expression trees in the Red Dragon book. Basically what your UI is doing is manipulating an expression tree: adding/removing nodes, changing node types, etc. From there it's just a matter of generating code from the expression tree: unlike a regular compiler whose output is assembly or p-code, your code will generate IronPython.

When taking a first stab at this, I recommend just always blowing away the previously generated code and regenerate from scratch. It will be very easy to go down the rabbit hole of trying to dynamically just update a few lines within an existing file like Visual Studio does when you double click to add an event handler. Focus first on being able to get a minimum viable product (MVP) where the user can create and edit a sequence of steps in the GUI, then hit compile, and get running IronPython code in the end. On succeeding iterations slowly work towards being able to do what VS does.
 
Thanks for the guidance on this. Well, with a bit of research, I found a tool that will generate a python file from an interactive GUI. This seems to solve that script editor part. I did a study on iron python. ironpython2 source code when am trying to load this c sharp project in visual studio, it's not loading in incorrect way. Need help on this. I am thinking to use ironpython as a backend engine to execute python script.
 
It would help if you told us in more detail what "it's not loading in incorrect way" was. Are seeing error messages? Of so what are they?
 
It would help if you told us in more detail what "it's not loading in incorrect way" was. Are seeing error messages? Of so what are they?
Here are the attached screenshots. It seems there is some issue with the confirguration file IronPython.sln. This is an entire source code for ironpython, its be load correctly in visual studio.
 

Attachments

  • IronPython_Unloaded2.PNG
    IronPython_Unloaded2.PNG
    45.7 KB · Views: 36
  • IronPython1.PNG
    IronPython1.PNG
    55.6 KB · Views: 37
Back
Top Bottom