Forums

WPF test

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

WPF test

Postby agustech » Tue Mar 17, 2009 2:30 pm

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())
agustech
 
Posts: 37

Re: WPF test

Postby agustech » Tue Mar 17, 2009 2:54 pm

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
agustech
 
Posts: 37

Re: WPF test

Postby Charles » Tue Mar 17, 2009 3:50 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: WPF test

Postby agustech » Tue Mar 17, 2009 5:45 pm

just tested again with svn rev 1977, same error
agustech
 
Posts: 37

Re: WPF test

Postby Caligari » Tue Mar 17, 2009 6:02 pm

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
Caligari
 
Posts: 33

Re: WPF test

Postby Charles » Thu Mar 19, 2009 6:53 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: WPF test

Postby Charles » Thu Mar 19, 2009 12:50 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: WPF test

Postby agustech » Thu Mar 19, 2009 1:32 pm

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

Last edited by agustech on Thu Mar 19, 2009 1:50 pm, edited 1 time in total.
agustech
 
Posts: 37

Re: WPF test

Postby agustech » Thu Mar 19, 2009 1:47 pm

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!"
agustech
 
Posts: 37

Re: WPF test

Postby Charles » Sun Apr 05, 2009 10:35 pm

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Next

Return to Discussion

Who is online

Users browsing this forum: No registered users and 75 guests

cron