Forums

wxWidgets / wx.NET

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

wxWidgets / wx.NET

Postby qvprof » Sat Oct 24, 2009 12:29 am

Hi, I was wondering if I can use Cobra with wx.net?

I'm a really new desktop programmer, having spent the last years on PHP, but have experience with Python. Sorry if the question is stupid... I'm just learning about desktop application programming.

I'm assuming that you can use wx.NET / wxWidgets with Cobra.

I am hunting for the best development package and was thinking about using Cobra + Mono + wx.NET, for fast development and cross platform portability...

Thanks!
-Quang
qvprof
 
Posts: 4

Re: wxWidgets / wx.NET

Postby Charles » Sat Oct 24, 2009 10:12 pm

Thanks for considering Cobra for the language part of your ideal desktop development stack.

You can definitely use any .NET/Mono library with Cobra. We have HowTo's for three other GUI libs; see the end of the list at http://cobra-language.com/how-to/. This will help you with things like hooking up events.

You should have no problem getting wx.net going compared to any other .NET language. If you would like to submit a HowTo for wx.net, feel free.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: wxWidgets / wx.NET

Postby qvprof » Sun Oct 25, 2009 1:39 am

Hey Chuck,

Thanks for the reply,

On the Python page,
Cobra can use any .NET libraries, whether home grown, open source or commercial, without any "bridging" or "wrapping".


So I'm assuming you can do something like,

Code: Select all
@ref 'C:\Cobra\bin\wx.NET'

use wx


Is there any tutorials on how to use 3rd party .NET libraries? I'm assuming the syntax will be different from C# and Cobra. (Again sorry, I am very new to .NET, C# and Cobra)
qvprof
 
Posts: 4

Re: wxWidgets / wx.NET

Postby hopscc » Sun Oct 25, 2009 6:22 am

Looks like wx.NET might be a pathological case to start with.

( chuck remember this this discussion from earlier
one khjklujn alluded to issues with using wx.NET around case conversion)
It uses an unusual casing for its namespace ( wx rather than Wx or WX) and amongst other things it has its own version of 'object'

For such libs perhaps we should support an aliasing or no translation syntax on use ???
Code: Select all
use wx from 'wx.NET"   as 'WX'
...
class MyFrame inherits WX.Frame
# or
use wx from 'wx.NET" is raw # no case translation


qvprof:
heres a rough example of a conversion of the Minimal.cs example to cobra - it doesnt fully compile due to inability to access the 'wx' namespace
Code: Select all
use System.Drawing
use wx from "wx.NET"

namespace SampleMinimal
   class MyFrame inherits wx.Frame

      enum Cmd
         About
         Quit
         Dialog

      cue init(title as String, pos as Point, size as Size)
         base.init(title, pos, size)
         # Set the window icon
         .icon = wx.Icon("./mondrian.png")

         # Set up a menu
         fileMenu = wx.Menu() # as wx.Menu
         #fileMenu.append(Cmd.Dialog, "&Show dialog\tAlt-D", "Show test dialog")
         fileMenu.append(Cmd.Quit, "E&xit\tAlt-X", "Quit this program")

         helpMenu = wx.Menu()
         helpMenu.append(Cmd.About, "&About...\tF1", "Show about dialog")

         menuBar = wx.MenuBar()
         menuBar.append(fileMenu, "&File")
         menuBar.append(helpMenu, "&Help")

         .menuBar = menuBar

         #Set up a status bar

         .createStatusBar(2)
         .statusText = "Welcome to wxWidgets!"

         # Set up the event table

         .EVT_MENU(Cmd.Quit,    EventListener(OnQuit))
         .EVT_MENU(Cmd.Dialog,  EventListener(OnDialog))
         .EVT_MENU(Cmd.About,   EventListener(OnAbout))

      def onQuit(sender as wx.Object, e as wx.Event )
         .close


      def onDialog(sender as wx.Object, e as wx.Event)
            dialog = wx.Dialog( this, -1, "Test dialog", Point(50,50), Size(450,340) )
            main_sizer = wx.BoxSizer( wx.Orientation.wxVERTICAL )
           
            top_sizer = wx.StaticBoxSizer( wx.StaticBox( dialog, -1, "Bitmaps" ), wx.Orientation.wxHORIZONTAL )
            main_sizer.add( top_sizer, 0, wx.Direction.wxALL, 5 )
           
            bb = wx.BitmapButton( dialog, -1, wx.Bitmap("./mondrian.png") )
            top_sizer.add( bb, 0, wx.Direction.wxALL, 10 )
           
            sb = wx.StaticBitmap( dialog, -1, wx.Bitmap("./mondrian.png") )
            top_sizer.add( sb, 0, wx.Direction.wxALL, 10 )
           
            button = wx.Button( dialog, 5100, "OK" )
            main_sizer.add( button, 0, wx.Direction.wxALL|wx.Alignment.wxALIGN_CENTER, 5 )
           
            dialog.setSizer( main_sizer, true )
            main_sizer.fit( dialog )
            main_sizer.setSizeHints( dialog )
           
            dialog.centreOnParent
            dialog.showModal

      def onAbout(sender as wx.Object, e as wx.Event )
         msg = "This is the About dialog of the minimal sample."
         wx.MessageDialog.showModal(this, msg, "About Minimal", Dialog.wxOK | Dialog.wxICON_INFORMATION)



   class Minimal inherits wx.App
      def onInit as bool is override
         frame = MyFrame("Minimal wxWidgets App", Point(50,50), Size(450,340))
         frame.Show(true)
         return true

      def main has STAThread
         is shared
         app = Minimal()
         app.run
hopscc
 
Posts: 632
Location: New Plymouth, Taranaki, New Zealand

Re: wxWidgets / wx.NET

Postby Charles » Sun Oct 25, 2009 2:37 pm

What do you mean "it has its own version of 'object'"? And how does that affect C#, VB, Cobra, ...?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: wxWidgets / wx.NET

Postby Charles » Sun Oct 25, 2009 3:20 pm

If there is a problem using "wx" I need a full bug report with exact details. The following test of a lower case namespace works fine using Cobra from svn:

Code: Select all
/*
gmcs -t:library little.cs
*/
namespace little {
   public class A {
      public int One {
         get { return 1; }
      }
   }
}


use little

class P

def main
a = little.A()
assert a.one == 1
a = A()
assert a.one == 1
print 'done.'
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: wxWidgets / wx.NET

Postby arisawa » Sun Oct 25, 2009 6:44 pm

It is possible to do for the time being work this.
use wx
namespace SampleMinimal
class MyFrame inherits Frame

Code: Select all
@args -ref:wx.NET -ref:System.Drawing
use System.Drawing
use wx

namespace SampleMinimal
   class MyFrame inherits Frame
      enum Cmd
         About
         Quit
         Dialog
      
      cue init(title as String, pos as Point, size as Size)
         base.init(title, pos, size)
         # Set the window icon
         #.icon = wx.Icon("./mondrian.png") ..... unsolved problem
         
         # Set up a menu
         fileMenu = wx.Menu() # as wx.Menu
         fileMenu.append(Cmd.Dialog to int, "&Show dialog\tAlt-D", "Show test dialog")
         fileMenu.append(Cmd.Quit to int, "E&xit\tAlt-X", "Quit this program")
            
         helpMenu = wx.Menu()
         helpMenu.append(Cmd.About to int, "&About...\tF1", "Show about dialog")
            
         menuBar = wx.MenuBar()
         menuBar.append(fileMenu, "&File")
         menuBar.append(helpMenu, "&Help")
         
         .menuBar = menuBar
         
         #Set up a status bar
         
         .createStatusBar(2)
         .setStatusText("Welcome to wxWidgets!")
         
         # Set up the event table
         
         .evt_MENU(Cmd.Quit to int,    EventListener(ref .onQuit))
         .evt_MENU(Cmd.Dialog to int,  EventListener(ref .onDialog))
         .evt_MENU(Cmd.About to int,   EventListener(ref .onAbout))
         
      def onQuit(sender, e as Event )
         .close
         
         
      def onDialog(sender, e as Event)
         dialog = wx.Dialog( this, -1, "Test dialog", Point(50,50), Size(450,340) )
         main_sizer = wx.BoxSizer( wx.Orientation.wxVERTICAL )
         
         top_sizer = wx.StaticBoxSizer( wx.StaticBox( dialog, -1, "Bitmaps" ), wx.Orientation.wxHORIZONTAL )
         main_sizer.add( top_sizer, 0, wx.Direction.wxALL, 5 )
         
         bb = wx.BitmapButton( dialog, -1, wx.Bitmap("./mondrian.png") )
         top_sizer.add( bb, 0, wx.Direction.wxALL, 10 )
         
         sb = wx.StaticBitmap( dialog, -1, wx.Bitmap("./mondrian.png") )
         top_sizer.add( sb, 0, wx.Direction.wxALL, 10 )
         
         button = wx.Button( dialog, 5100, "OK" )
         main_sizer.add( button, 0, wx.Direction.wxALL|wx.Alignment.wxALIGN_CENTER, 5 )
         
         dialog.setSizer( main_sizer, true )
         main_sizer.fit( dialog )
         main_sizer.setSizeHints( dialog )
         
         dialog.centreOnParent
         dialog.showModal

      def onAbout(sender, e as Event )
         msg = "This is the About dialog of the minimal sample."
         wx.MessageDialog.showModal(this, msg, "About Minimal", Dialog.wxOK | Dialog.wxICON_INFORMATION)



   class Minimal inherits App
      def onInit as bool is override
         frame = MyFrame("Minimal wxWidgets App", Point(50,50), Size(450,340))
         frame.show(true)
         return true

      def main has STAThread
         is shared
         app = Minimal()
         app.run
         
arisawa
 
Posts: 51

Re: wxWidgets / wx.NET

Postby Charles » Sun Oct 25, 2009 8:43 pm

So I should include this in the HowTo's, yes?
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: wxWidgets / wx.NET

Postby arisawa » Sun Oct 25, 2009 10:00 pm

no problem. :)

there is not a problem in the old Cobra 0.8 as follows either.
.icon = Icon("./mondrian.png")

strange... :?
arisawa
 
Posts: 51

Re: wxWidgets / wx.NET

Postby qvprof » Sun Oct 25, 2009 11:19 pm

Thanks hopscc, Chuck, and arisawa. :)

Using ariawa's example I was able to compile my first Cobra + Mono + wx.NET, I think there was a slight typo on line 79 "def main has STAThread \n is shared" (or was it?), attached is the one that compiles

Code: Select all
@args -ref:wx.NET -ref:System.Drawing
use System.Drawing
use wx

namespace SampleMinimal
   class MyFrame inherits Frame
      enum Cmd
         About
         Quit
         Dialog
      cue init(title as String, pos as Point, size as Size)
         base.init(title, pos, size)
         # Set the window icon
         #.icon = wx.Icon("./mondrian.png") ..... unsolved problem
         
         # Set up a menu
         fileMenu = wx.Menu() # as wx.Menu
         fileMenu.append(Cmd.Dialog to int, "&Show dialog\tAlt-D", "Show test dialog")
         fileMenu.append(Cmd.Quit to int, "E&xit\tAlt-X", "Quit this program")
            
         helpMenu = wx.Menu()
         helpMenu.append(Cmd.About to int, "&About...\tF1", "Show about dialog")
            
         menuBar = wx.MenuBar()
         menuBar.append(fileMenu, "&File")
         menuBar.append(helpMenu, "&Help")
         
         .menuBar = menuBar
         
         #Set up a status bar
         
         .createStatusBar(2)
         .setStatusText("Welcome to wxWidgets!")
         
         # Set up the event table
         
         .evt_MENU(Cmd.Quit to int,    EventListener(ref .onQuit))
         .evt_MENU(Cmd.Dialog to int,  EventListener(ref .onDialog))
         .evt_MENU(Cmd.About to int,   EventListener(ref .onAbout))
         
      def onQuit(sender, e as Event )
         .close
         
         
      def onDialog(sender, e as Event)
         dialog = wx.Dialog( this, -1, "Test dialog", Point(50,50), Size(450,340) )
         main_sizer = wx.BoxSizer( wx.Orientation.wxVERTICAL )
         
         top_sizer = wx.StaticBoxSizer( wx.StaticBox( dialog, -1, "Bitmaps" ), wx.Orientation.wxHORIZONTAL )
         main_sizer.add( top_sizer, 0, wx.Direction.wxALL, 5 )
         
         bb = wx.BitmapButton( dialog, -1, wx.Bitmap("./mondrian.png") )
         top_sizer.add( bb, 0, wx.Direction.wxALL, 10 )
         
         sb = wx.StaticBitmap( dialog, -1, wx.Bitmap("./mondrian.png") )
         top_sizer.add( sb, 0, wx.Direction.wxALL, 10 )
         
         button = wx.Button( dialog, 5100, "OK" )
         main_sizer.add( button, 0, wx.Direction.wxALL|wx.Alignment.wxALIGN_CENTER, 5 )
         
         dialog.setSizer( main_sizer, true )
         main_sizer.fit( dialog )
         main_sizer.setSizeHints( dialog )
         
         dialog.centreOnParent
         dialog.showModal

      def onAbout(sender, e as Event )
         msg = "This is the About dialog of the minimal sample."
         wx.MessageDialog.showModal(this, msg, "About Minimal", Dialog.wxOK | Dialog.wxICON_INFORMATION)
   
      


   class Minimal inherits App
      def onInit as bool is override
         frame = MyFrame("Minimal wxWidgets App", Point(50,50), Size(450,340))
         frame.show(true)
         return true

      def main is shared
         app = Minimal()
         app.run


Sweet awesome, thanks hopscc and ariawa :D

I get an "Error: Cannot initialize OLE" but no big... thanks guys~
This was just for me to see if it actually works.

Also wx.NET's Minimal.cs is attached
Code: Select all
//-----------------------------------------------------------------------------
// wx.NET/Samples - Minimal.cs
//
// A wx.NET version of the wxWidgets "minimal" sample.
//
// Written by Jason Perkins (jason@379.com)
// (C) 2003 by 379, Inc.
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// $Id: Minimal.cs,v 1.15 2007/10/21 15:30:41 harald_meyer Exp $
//-----------------------------------------------------------------------------

using System;
using System.Drawing;

namespace wx.SampleMinimal
{
   public class MyFrame : wx.Frame
   {
      enum Cmd { About, Quit, Dialog }

      //---------------------------------------------------------------------

      public MyFrame(string title, Point pos, Size size)
         : base(title, pos, size)
      {
         // Set the window icon

         Icon = new wx.Icon("../Samples/Minimal/mondrian.png");

         // Set up a menu

         wx.Menu fileMenu = new wx.Menu();
         //fileMenu.Append((int)Cmd.Dialog, "&Show dialog\tAlt-D", "Show test dialog");
         fileMenu.Append((int)Cmd.Quit, "E&xit\tAlt-X", "Quit this program");

         wx.Menu helpMenu = new wx.Menu();
         helpMenu.Append((int)Cmd.About, "&About...\tF1", "Show about dialog");

         wx.MenuBar menuBar = new wx.MenuBar();
         menuBar.Append(fileMenu, "&File");
         menuBar.Append(helpMenu, "&Help");

         MenuBar = menuBar;

         // Set up a status bar

         CreateStatusBar(2);
         StatusText = "Welcome to wxWidgets!";

         // Set up the event table

         EVT_MENU((int)Cmd.Quit,    new EventListener(OnQuit));
          EVT_MENU((int)Cmd.Dialog,  new EventListener(OnDialog));
         EVT_MENU((int)Cmd.About,   new EventListener(OnAbout));
      }

      //---------------------------------------------------------------------

      public void OnQuit(object sender, wx.Event e)
      {
         Close();
      }

      //---------------------------------------------------------------------

      public void OnDialog(object sender, wx.Event e)
      {
            wx.Dialog dialog = new wx.Dialog( this, -1, "Test dialog", new Point(50,50), new Size(450,340) );
            wx.BoxSizer main_sizer = new wx.BoxSizer( wx.Orientation.wxVERTICAL );
           
            wx.StaticBoxSizer top_sizer = new wx.StaticBoxSizer( new wx.StaticBox( dialog, -1, "Bitmaps" ), wx.Orientation.wxHORIZONTAL );
            main_sizer.Add( top_sizer, 0, wx.Direction.wxALL, 5 );
           
            wx.BitmapButton bb = new wx.BitmapButton( dialog, -1, new wx.Bitmap("../Samples/Minimal/mondrian.png") );
            top_sizer.Add( bb, 0, wx.Direction.wxALL, 10 );
           
            wx.StaticBitmap sb = new wx.StaticBitmap( dialog, -1, new wx.Bitmap("../Samples/Minimal/mondrian.png") );
            top_sizer.Add( sb, 0, wx.Direction.wxALL, 10 );
           
            wx.Button button = new wx.Button( dialog, 5100, "OK" );
            main_sizer.Add( button, 0, wx.Direction.wxALL|wx.Alignment.wxALIGN_CENTER, 5 );
           
            dialog.SetSizer( main_sizer, true );
            main_sizer.Fit( dialog );
            main_sizer.SetSizeHints( dialog );
           
            dialog.CentreOnParent();
            dialog.ShowModal();
      }

      //---------------------------------------------------------------------

      public void OnAbout(object sender, wx.Event e)
      {
         string msg = "This is the About dialog of the minimal sample.";
         wx.MessageDialog.ShowModal(this, msg, "About Minimal", Dialog.wxOK | Dialog.wxICON_INFORMATION);
      }

      //---------------------------------------------------------------------
   }



   public class Minimal : wx.App
   {
      //---------------------------------------------------------------------

      public override bool OnInit()
      {
         MyFrame frame = new MyFrame("Minimal wxWidgets App", new Point(50,50), new Size(450,340));
         frame.Show(true);

         return true;
      }

      //---------------------------------------------------------------------

      [STAThread]
      static void Main()
      {
         Minimal app = new Minimal();
         app.Run();
      }

      //---------------------------------------------------------------------
   }
}


Thanks, I'll definitely compare the two, to learn how to convert C# to Cobra.
qvprof
 
Posts: 4

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 10 guests