Anonymous avatar Anonymous committed baca526

The selected pygame application is launched in it's own process now.

Resize event sent when orientation changes.

Comments (0)

Files changed (6)

symbian/BuildPygameRelease.py

     args['sdluid'] = hex(UID_SDL).replace("L","")
     args['jpeguid']= hex(UID_JPEG).replace("L","")
     args['pythoninclude'] = config.pythoninclude
-    args['defines'] = "STDERR_TO_STDOUT"
+    #args['defines'] = "STDERR_TO_STDOUT"
     args['winscw_options'] = "-nostderr" # Don't show the stdioserver output
     dobuild(args)
     

symbian/SConscript.app.py

                     #"__LOGMAN_ENABLED__", 
                 ],
                 libraries = C_LIBRARY + ["euser", "avkon", "apparc", 
-                             "cone","eikcore", "libGLES_CM",                             
+                             "cone","eikcore", "libGLES_CM", 
+                             "bafl", # arrays and command line                            
                              PYTHON_LIB_NAME,
                              SDL_DLL_NAME,
                              "pygame.lib",

symbian/app/launcher/pygame_launcher.py

 
 import sys
 import os
+from os.path import join
 
 import pygame
 from pygame.locals import *
         del a
         
         if path_to_app:
-            
-            # Run the application and restart launcher after app is completed.
-            try:
-                os.chdir(os.path.dirname(path_to_app))
-                execfile(path_to_app, {'__builtins__': __builtins__,
-                                       '__name__': '__main__',
-                                       '__file__': path_to_app,
-                                       'pygame' : pygame }
-                )
-            except:
-                import traceback
-                traceback.print_exc()
-                sys.stdout.flush()
-                        
-            
-        else:
-            # Exit launcher
-            break
+            path_to_app = os.path.abspath(path_to_app)
+            if sys.platform == "symbian_s60":
+                import e32
+                #if e32.in_emulator():
+                    # Run the application and restart launcher after app is completed.
+               #     execfile(path_to_app, {'__builtins__': __builtins__,
+               #                            '__name__': '__main__',
+                #                           '__file__': path_to_app,
+                #                           'pygame' : pygame }
+                #    )
+                #else:
+                # The application is started in it's own process on device.
+                # S60 SDL does not show the selected application correctly when using double buffering,
+                # but it is needed to make application hide correctly on device.
+                datapath = os.path.join( THISDIR, "startapp.txt" )
+                f = open(datapath,'w')
+                f.write(path_to_app)
+                f.close()
+                
+                # The launcher starts a new pygame.exe process for the selected application.
+                # This process must close before starting the new one.
+                p = os.path.abspath( join( THISDIR, "..", "pygame_main.py") )
+                e32.start_exe( "251_python_launcher.exe", p )
+
+            else:         
+                # TODO: Use subprocess
+                os.system("start pythonw " + join( THISDIR, "..", "pygame_main.py"))
+                
+        # Exit launcher
+        break
         
     pygame.quit()
     
 if __name__ == "__main__":
-    
-    if sys.platform == "symbian_s60":
+        
+    if "profile" not in sys.argv:
         start()
     else:
         import hotshot

symbian/app/pygame_app.cpp

+/** pygame S60 application */
+#include <stddef.h>
 #include <coecntrl.h>
 #include <aknappui.h>
 #include <aknapp.h>
 #include <sdlepocapi.h>
 #include <aknnotewrappers.h>
 #include <eikstart.h>
+#include "pygame.hrh"
 
-#include "pygame.hrh"
+#include <BACLINE.H>
 
 #include "logmanutils.h"
 
 	~CSdlAppUi();
 private:
 	void HandleCommandL(TInt aCommand);
+	void HandleResourceChangeL( TInt aType );
 	void StartTestL(TInt aCmd);
 	void DoExit(TInt aErr);
 	void HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination);
 	CWindowGc& gc = SystemGc();
 	gc.SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
 	gc.Clear();
-	
+
 	gc.SetPenStyle(CGraphicsContext::ENullPen);
 	gc.SetPenColor(0x000000);
 	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
  {
  TKeyResponse result = EKeyWasNotConsumed;
  if ( aKeyEvent.iScanCode == 164 )
- {		
+ {
  result = EKeyWasConsumed;
  }
  return result;
 void CSdlAppUi::ConstructL()
 {
 	BaseConstructL(CAknAppUi::EAknEnableSkin /* | ENoScreenFurniture*/);
-
+	
 	iSDLWin = new (ELeave) CSDLWin;
 	iSDLWin->ConstructL(ApplicationRect());
 
 
 void CSdlAppUi::HandleCommandL(TInt aCommand)
 {
-LOGMAN_SENDLOGF("HandleCommandL:%d", aCommand)
-#if(0)
-switch (aCommand)
-{
-	//case EAknCmdExit:
-	case EAknSoftkeyExit:
-	//case EEikCmdExit:
-	Done = 1;
-	iExit = ETrue;
-	if (iWait == NULL || !iWait->IsActive())
-	Exit();
-
-	break;
 }
 
-if(iSdl == NULL)
-StartTestL(aCommand);
-#endif	
+extern "C" {
+#include <SDL_events.h>
+}
+void CSdlAppUi::HandleResourceChangeL( TInt aType )
+{
+
+	//User::InfoPrint(_L("rect.Height()"));
+	if( aType == KEikDynamicLayoutVariantSwitch )
+	{
+		// Create SDL resize event
+		TRect rect;
+		AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EApplicationWindow,rect);
+
+		SDL_Event event;
+		event.type = SDL_VIDEORESIZE;
+		event.resize.w = rect.Width();
+		event.resize.h = rect.Height();
+		//if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
+		SDL_PushEvent(&event);
+
+		iSDLWin->SetRect(rect);
+/*
+		iSdl->SetContainerWindowL(
+					iSDLWin->GetWindow(),
+					iEikonEnv->WsSession(),
+					*iEikonEnv->ScreenDevice());
+*/
+	}
+
+	CAknAppUi::HandleResourceChangeL(aType);
+
 }
 
 void CSdlAppUi::StartTestL(TInt aCmd)
 
 	//TInt flags = CSDL::EDrawModeGdi | CSDL::EEnableFocusStop
 	//		| CSDL::EMainThread;// | CSDL::EAutoOrientation;
-		
+
 	TInt flags = 0;
-	// This seems to be required to support pygame launcher.
-	flags |= CSDL::EDrawModeDSBDoubleBuffer;
-	// Don't draw when in background. 
+
+	flags |= CSDL::EDrawModeDSB | CSDL::EDrawModeDSBDoubleBuffer;
+	// Don't draw when in background.
 	flags |= CSDL::EEnableFocusStop;
 	// This should be on by default anyway
 	flags |= CSDL::EMainThread;
 	
+	//Create CommandLine Arguments and read it.
+	CDesC8ArrayFlat *arr = new (ELeave) CDesC8ArrayFlat (1);
+	CleanupStack::PushL(arr);
+	
+	CCommandLineArguments* args=CCommandLineArguments::NewLC();
+	// The real args we are interested in start at the 2nd arg
+	for (TInt i=1; i<args->Count(); i++) 
+	{
+		TBuf8<256> arg;
+		arg.Copy(args->Arg(i) );
+		
+		arr->AppendL(arg);
+		//TPtrC argumentPrt(args->Arg(i));
+		//console->Printf(_L("Arg %d == %S\n"), i, &argumentPrt); 
+	}
+	
 	iSdl = CSDL::NewL(flags);
-
+	
 	iSdl->SetContainerWindowL(iSDLWin->GetWindow(), iEikonEnv->WsSession(),
 			*iEikonEnv->ScreenDevice());
-	iSdl->CallMainL(iWait->iStatus);
+	iSdl->CallMainL(iWait->iStatus, *arr, flags, 0x14000);
 	iWait->Start();
+	
+	arr->Reset();
+	CleanupStack::PopAndDestroy(2); // command line and arr
 }
 
 void CSdlAppUi::DoExit(TInt aErr)
 GLDEF_C TInt E32Main()
 {
 	// TODO: Is this the only way to set heap size on emulator?
-	//#ifdef __WINS__	
+	//#ifdef __WINS__
 	RHeap *heap = UserHeap::ChunkHeap(0, 100000, 10000000, 100000);
 	User::SwitchHeap(heap);
-	//#endif	
+	//#endif
 	TInt result = EikStart::RunApplication(NewApplication);
-	//#ifdef __WINS__	
+	//#ifdef __WINS__
 	heap->Close();
-	//#endif	
+	//#endif
 	return result;
 }
 

symbian/app/pygame_main.cpp

 
 #ifndef PYGAME_MAIN_SCRIPT_PATH
 #define PYGAME_MAIN_SCRIPT_PATH "\\data\\pygame\\pygame_main.py"
+#define PYGAME_LAUNCHER_PATH    "\\data\\pygame\\launcher\\pygame_launcher.py"
 #endif
-static const char* gPygameMainScriptPath[1] = {PYGAME_MAIN_SCRIPT_PATH};
+static const char* gPygameMainScriptPath[2] = {
+		PYGAME_MAIN_SCRIPT_PATH,
+		PYGAME_LAUNCHER_PATH
+		};
 
 int main(int argc, char** argv)
 {
 	TInt result = interp->RunScript(1, gPygameMainScriptPath);
 #else	
 	
+	LOGMAN_SENDLOGF("Number of args:%d", argc);
+	if(argc > 1){
+		gPygameMainScriptPath[1] = argv[1];
+	}
+	
 	LOGMAN_SENDLOGF8( "Opening file:%s", gPygameMainScriptPath[0] );
-	
 	FILE *fp = fopen(gPygameMainScriptPath[0], "r");
 	if (!fp) {
 		LOGMAN_SENDLOG( "Failed to open main script" );
 	}
 	
 	// This allows us to retrieve the path of the main script in Python from sys.argv[0]
-	PySys_SetArgv(1, (char**)gPygameMainScriptPath);
+	PySys_SetArgv(2, (char**)gPygameMainScriptPath);
 	
 	int result = PyRun_SimpleFile(fp, gPygameMainScriptPath[0]);
 	fclose(fp);
 #endif
-		
+	
 	LOGMAN_SENDLOGF( "Interpreter result:%d", result )
 
 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2	

symbian/app/pygame_main.py

 """
-pygame main script for S60
+pygame main script for S60. This initializes some system defaults and 
+calls the pygame script given in sys.argv[1]
 """
 import os
 import sys
     sys.stdout = f
     sys.stderr = f
 
+__file__ = sys.argv[0]
 
-__file__ = sys.argv[0]
 THISDIR = os.path.dirname( __file__ )
 sys.path.append( os.path.join( THISDIR, "libs") )
-
-path_to_app = os.path.join( THISDIR, "launcher", "pygame_launcher.py" )
+if len(sys.argv) < 2:
+    path_to_app = os.path.join( THISDIR, "launcher", "pygame_launcher.py" )
+    if sys.platform == "symbian_s60":
+        import e32
+        datapath = os.path.join( THISDIR, "launcher", "startapp.txt" )
+        if os.path.exists(datapath):
+            # Read the application script path from a file stored by launcher.
+            df = open(datapath)
+            data = df.read()
+            df.close()
+            path_to_app = data.strip()
+            
+            # TODO: Make sure previous pygame.exe has closed first
+            import time
+            time.sleep(1)
+                         
+            e32.start_exe( "pygame.exe", path_to_app, 1)
+            
+            e32.start_exe( "pygame.exe", "")
+            
+        
+else:
+    path_to_app = sys.argv[1]
+    
 execfile(path_to_app, {'__builtins__': __builtins__,
                    '__name__': '__main__',
                    '__file__': path_to_app } )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.