Page 1 of 2

WPF test

PostPosted: Tue Mar 17, 2009 2:30 pm
by agustech
I have made a simple WPF test but can not get it to compile. Gives following errors with verbosity:3:

...
Parsing WPFsimple.cobra
Binding use directives
Binding inheritance
Binding interface
Cannot locate CLR type "System.Windows.EffectiveValueEntry".
Skipping duplicate message: error: Cannot find top level namespace "MS" of CLR type "MS.Win32.NativeMethods".
error: Cannot locate nested CLR type "System.Windows.Media.Visual+AncestorChangedEventHandler" (simple name is "AncestorChangedEventHandler").
error: Cannot find top level namespace "MS" of CLR type "MS.Internal.InheritedPropertyChangedEventHandler".
error: Cannot find top level namespace "MS" of CLR type "MS.Win32.NativeMethods".
Compilation failed - 3 errors, 0 warnings
Not running due to errors above.

Code: Select all
use System.Windows.Media
use System.Windows
class Window1
   inherits System.Windows.Window
/#
   def setBackgroundOrOnlyBlackWindowOnMyMachine
      bmp = WinMedia.Imaging.RenderTargetBitmap(1, 1, 1, 1, WinMedia.PixelFormats.default)
      .background = WinMedia.ImageBrush(bmp)
#/
   cue init
      #.setBackgroundOrOnlyBlackWindowOnMyMachine()
      .addChild(System.Windows.Controls.Button())
      .title = "WPF Test"

   def main is shared
      app = Application()
      app.run(Window1())

Re: WPF test

PostPosted: Tue Mar 17, 2009 2:54 pm
by agustech
This mini test works though:
Code: Select all
class WPFTest0
   def main is shared
      System.Windows.MessageBox.show("Hello, WPF")

compiled with:
cobra -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" WPFsimple0.cobra

Re: WPF test

PostPosted: Tue Mar 17, 2009 3:50 pm
by Charles
I fixed an error just like that recently, but maybe there are other cases where it comes up. Btw don't forget to remind me in such posts what version of Cobra you're on (svn, 2009-03-10, 0.8).

I have a Geek Dinner and work for the rest of today so won't be able to look at this until tomorrow.

Re: WPF test

PostPosted: Tue Mar 17, 2009 5:45 pm
by agustech
just tested again with svn rev 1977, same error

Re: WPF test

PostPosted: Tue Mar 17, 2009 6:02 pm
by Caligari
Note that you can put the ref in the file, rather than on the command line, eg.:

Code: Select all
%% args -ref:System.Xml

I find it a lot easier to keep track of what needs to be referenced that way.

- Caligari

Re: WPF test

PostPosted: Thu Mar 19, 2009 6:53 am
by Charles
Okay, I fixed the bug reported by agustech in this thread. This was another case of the Cobra compiler scanning private members (in this case events) which referred to private types. This is now guarded against.

use System.Windows.Media
use System.Windows

class Window1 inherits System.Windows.Window

/#
def setBackgroundOrOnlyBlackWindowOnMyMachine
bmp = WinMedia.Imaging.RenderTargetBitmap(1, 1, 1, 1, WinMedia.PixelFormats.default)
.background = WinMedia.ImageBrush(bmp)
#/

cue init
# .setBackgroundOrOnlyBlackWindowOnMyMachine()
.addChild(System.Windows.Controls.Button())
.title = "WPF Test"

def main is shared
has STAThread
app = Application()
app.run(Window1())

The command to run:

cobra -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" x-wpf-2.cobra

Stick a -c in just to compile.

Note that I could not get the commented out method to work because WinMedia was not found. I did a Google Code search on "lang:C# winmedia" and came up empty so I'm not sure what that is.

Regarding using "%% args", I agree with Caligari's suggestion, but in this case, using %% args with a -ref: that has double quotes fails. So for now you have to stick with the command line.

If you run into further problems, please report them so I can fix them.

Re: WPF test

PostPosted: Thu Mar 19, 2009 12:50 pm
by Charles
Okay, I fixed the problem with %% args and -ref:s with quotes. Now you can run as easy as "cobra wpf.cobra". Here is the code:
%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll"
%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll"
%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll"

use System.Windows
use System.Windows.Media

class MyWindow inherits System.Windows.Window

cue init
.addChild(System.Windows.Controls.Button())
.title = "WPF Test"

def main is shared
has STAThread
app = Application()
app.run(MyWindow())

I've also added this to the Cobra regression test suite.

Re: WPF test

PostPosted: Thu Mar 19, 2009 1:32 pm
by agustech
ok thanks

forget about WinMedia, it was an alias for System.Windows.Media. you can remove "use System.Windows.Media" too


When installing your changes I run into a little issue with install-from-workspace because windows case insensitive filesystem, you can fix it with:
Code: Select all

Index: Source/InstallFromWorkspace.cobra
===================================================================
--- Source/InstallFromWorkspace.cobra   (revision 1987)
+++ Source/InstallFromWorkspace.cobra   (working copy)
@@ -545,7 +545,7 @@
       print
       baseBinDir = '[_baseDir][slash]bin'
       if found
-         if commandPath == '[baseBinDir][slash][commandName]'
+         if String.compare(commandPath,'[baseBinDir][slash][commandName]', not .isRunningOnUnix) == 0
             print 'Your PATH already contains [baseBinDir]'
             print 'so you can invoke "cobra" from any directory.'
          else


Re: WPF test

PostPosted: Thu Mar 19, 2009 1:47 pm
by agustech
a somewhat much cleaner and useful (?) example:

%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll"
%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll"
%% args -ref:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll"

use System.Windows

class Window1 inherits Window

var btn = Controls.Button()

cue init
.btn.content = "Hi! I am a big button, click me!"
listen .btn.click, ref .buttonClicked
.addChild(.btn)
.title = "WPF Test"

def main is shared
has STAThread
app = Application()
app.run(Window1())

def buttonClicked(sender, ev as RoutedEventArgs )
.btn.content = "Hey! you have clicked me!"

Re: WPF test

PostPosted: Sun Apr 05, 2009 10:35 pm
by Charles
agustech wrote:When installing your changes I run into a little issue with install-from-workspace because windows case insensitive filesystem, you can fix it with:
Code: Select all

Index: Source/InstallFromWorkspace.cobra
===================================================================
--- Source/InstallFromWorkspace.cobra   (revision 1987)
+++ Source/InstallFromWorkspace.cobra   (working copy)
@@ -545,7 +545,7 @@
       print
       baseBinDir = '[_baseDir][slash]bin'
       if found
-         if commandPath == '[baseBinDir][slash][commandName]'
+         if String.compare(commandPath,'[baseBinDir][slash][commandName]', not .isRunningOnUnix) == 0
             print 'Your PATH already contains [baseBinDir]'
             print 'so you can invoke "cobra" from any directory.'
          else

Applied and checked in. Thanks.