[IronPython] Making A Windows Form App

Rakesh Ravuri Rakesh.Ravuri at adeasolutions.com
Wed Jul 13 15:15:12 CEST 2005


Hi All,

 I have implemented a rich text console , using the IConsole 
 interface. 
 Still has bugs, but helps noobs like me in locating methods 
 in a module by simulating intellisense.
 Also has support for up & down arrow keys to scroll through 
 history & the default copy paste of Rich Text box.

 To see it action & try it out follow the link below:
 
http://www.eternalillusions.com/Blog/PermaLink,guid,6124596b-b9e2-4254-8
149-15ace49a88dc.aspx
 
 
 I had to make minor modifications to the Ops.cs & 
 PhythonEngine.cs files to get the custom console working.

 Here are the differences:

Ops.cs------------------------------------------------------------------
---------
C:\IronPython-0.7.6>diff -ru
C:\IronPython-0.7.6\IronPython-0.7.6-Original\IronP
ython\objects\ops.cs
C:\IronPython-0.7.6\IronPython-0.7.6\IronPython\Objects\Ops
.cs
---
C:\IronPython-0.7.6\IronPython-0.7.6-Original\IronPython\objects\ops.cs
2005-06-12 17:01:42.000000000 +0530
+++ C:\IronPython-0.7.6\IronPython-0.7.6\IronPython\Objects\Ops.cs
2005-07-
13 15:54:23.571026400 +0530
@@ -32,6 +32,9 @@
     /// Summary description for time.
     /// </summary>
     public class Ops {
+        //RR: Added static variable for Custom Console Support
+        public static IronPython.Hosting.IConsole CurrentConsole =
null;
+
         public static object NotImplemented = "<NotImplemented>"; //!!!
need re
ally singleton objects

         public static object Ellipsis = "..."; //!!!
@@ -2021,7 +2024,10 @@


         public static void PrintNewline() {
-            PrintNewlineWithDest(sys.stdout);
+            if (CurrentConsole == null)
+                PrintNewlineWithDest(sys.stdout);
+            else
+                CurrentConsole.WriteLine("",
IronPython.Hosting.Style.Out);
         }

         public static void PrintNewlineWithDest(object dest) {
@@ -2030,15 +2036,35 @@
         }

         public static void Print(object o) {
-            PrintWithDest(sys.stdout, o);
+            if (CurrentConsole == null)
+                PrintWithDest(sys.stdout, o);
+            else
+            {
+                if (o == null)
+                    CurrentConsole.WriteLine("None",
IronPython.Hosting.Style.O
ut);
+                else
+                    CurrentConsole.WriteLine(ToString(o),
IronPython.Hosting.St
yle.Out);
+            }
+
         }

         public static void PrintNoNewline(object o) {
-            PrintWithDestNoNewline(sys.stdout, o);
+            if (CurrentConsole == null)
+                PrintWithDestNoNewline(sys.stdout, o);
+            else
+            {
+                if (o==null)
+                    CurrentConsole.Write("None",
IronPython.Hosting.Style.Out);

+                else
+                    CurrentConsole.Write(ToString(o),
IronPython.Hosting.Style.
Out);
+            }
         }

         public static void PrintComma(object o) {
-            PrintCommaWithDest(sys.stdout, o);
+            if (CurrentConsole == null)
+                PrintCommaWithDest(sys.stdout, o);
+            else
+                PrintNoNewline(o);
         }

         public static void PrintWithDest(object dest, object o) {

Ops.cs------------------------------------------------------------------
---------


PythonEngine.cs---------------------------------------------------------
---------
 C:\IronPython-0.7.6>diff -ru
C:\IronPython-0.7.6\IronPython-0.7.6-Original\IronP
ython\Hosting\PythonEngine.cs
C:\IronPython-0.7.6\IronPython-0.7.6\IronPython\Ho
sting\PythonEngine.cs
---
C:\IronPython-0.7.6\IronPython-0.7.6-Original\IronPython\Hosting\PythonE
ngin
e.cs    2005-06-13 16:17:38.000000000 +0530
+++
C:\IronPython-0.7.6\IronPython-0.7.6\IronPython\Hosting\PythonEngine.cs
2005-07-06 11:02:53.886841800 +0530
@@ -46,7 +46,7 @@
         }
         public IConsole MyConsole {
             get { return _console; }
-            set { _console = value; }
+            set { _console = value; Ops.CurrentConsole = value; }
         }

         public static Version Version {
PythonEngine.cs---------------------------------------------------------
---------

Cheers!
Rakesh Ravuri
  

-----Original Message-----
From: users-ironpython.com-bounces at lists.ironpython.com
[mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf Of
Martin Maly
Sent: Tuesday, July 12, 2005 4:24 AM
To: Discussion of IronPython
Subject: RE: [IronPython] Making A Windows Form App

The command line tool that comes with IronPython runs in the standard
Windows console.
You can set up the console to allow copy'n' paste. To do that:

left click on the icon on the upper-left corner of the console window
select "Defaults"
Check "Quick edit mode"
Restart the IronPython.

Then you can use mouse to select area on the console. Right click (or
Enter) will copy to clipboard
and another right click of the mouse will insert the text as a console
input. I find this very useful when using the IronPython console.

Martin

> -----Original Message-----
> From: users-ironpython.com-bounces at lists.ironpython.com
> [mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf 
> Of Freddie Witherden
> Sent: Wednesday, July 06, 2005 2:22 PM
> To: users-ironpython.com at lists.ironpython.com
> Subject: RE: [IronPython] Making A Windows Form App
> 
> Namespaces are the biggest problem, LoadAssemblyByName and importing 
> modules are always a paint for me. The 'editor' or command line tool 
> is also a bit annoying as you can not copy or paste text from/to it 
> which makes it harder to work with, but when I had a poke about with 
> MSIL Disassembler I found:
> IronPythonConsole.FancyConsole, is this some kind of more advanced 
> console, as I often make a lot of small programs in IronPython to test

> things about and something like a nicer IDE would be great, it is not 
> like Jython where I can get a book so better documentation would go a 
> long way.
> 
_______________________________________________
users-ironpython.com mailing list
users-ironpython.com at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list