Jump to content
Nokioteca Forum

[python] Msys


madhacker
 Share

Recommended Posts

  • 6 mesi dopo...
  • Risposte 67
  • Created
  • Ultima Risposta

Top Posters In This Topic

  • 7 mesi dopo...

Grazie mad, gentile e disponibile come sempre :lol:

Già! E ne approfitto per chiederti due cosette:

Potresti aggiungere la possibilità di killare processi come appswitch (stesso metodo, magari copi direttamente il codice così c'è compatibilità)

Potresti aggiungere la possibilità in send_fg di indicare il parametro (che sarebbe il titolo o uid dell'applicazione) di quale app mandare in fg?

Grazie

ps: tutto questo per eliminare completamente appswitch e facilitare i port futuri (sto lavorando su winfile come sai hehe)

Link to comment
Condividi su altri siti

quella per python 2.0?

attualmente msys killa i processi così

msys.killapp(u'Menu')

a te come torna comodo?

per quanto riguarda il foreground, si fa prima se mi posti il codice :P

Si certo per python 2 (mai più mi metto a lavorare con la vecchia versione! :))

x il foreground ecco:

#include <e32std.h>
#include <e32base.h>
#include <apgtask.h>
#include <eikenv.h>

#include "Python.h"
#include "symbian_python_ext_util.h"


TBool TryToBringForeground(const TDesC& aCaption)
{

TApaTaskList taskList(CEikonEnv::Static()->WsSession());
TApaTask task(taskList.FindApp(aCaption));

if (task.Exists())
{
	task.BringToForeground();		
}
return task.Exists();
}

static PyObject* switch_to_fg(PyObject* /*self*/, PyObject *args)
{
char* b = NULL;	
TInt l = 0;

if (!PyArg_ParseTuple(args, "u#", &b, &l))
{
	return 0;
}

TPtrC caption((TUint16*)b, l);

if (TryToBringForeground(caption))
{
	Py_INCREF(Py_True);
	return Py_True;
}
else
{
	Py_INCREF(Py_False);
	return Py_False;
}	
}


static const PyMethodDef appswitch_methods[] =
{
{"switch_to_fg", (PyCFunction)switch_to_fg, METH_VARARGS},
{0, 0} /* sentinel */
};

DL_EXPORT(void) init_iapconnect()
{
Py_InitModule("appswitch", (PyMethodDef*) appswitch_methods);	
}

GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}

Per killare i processi intendevo proprio terminarli (killapp non termina il task??)

cmq qui il codice (l'aveva fatte dokkis certe aggiunte!)

#include <e32std.h>
#include <e32base.h>
#include <apgtask.h>
#include <apgcli.h>
#include <eikenv.h>
#include <apgwgnam.h>

#include "Python.h"
#include "unicodeobject.h"
#include "symbian_python_ext_util.h"

enum TTaskOperations
   {
   ETaskForeground,
   ETaskBackground,
   ETaskKill,
   ETaskEnd,    
   };


void GetRunningApplicationTitlesL(CDesCArray& aArray, TBool aIncludeHidden)
{  
   // this code is somewhat borrowed from Switcher application

   RWsSession ws(CEikonEnv::Static()->WsSession()); 
   RApaLsSession rs;
   CApaWindowGroupName* wgName; 
   TApaAppInfo ai;

   User::LeaveIfError(rs.Connect());    
   CleanupClosePushL(rs);

   CArrayFixFlat<TInt>* wgl = new (ELeave) CArrayFixFlat<TInt>(5);
   CleanupStack::PushL(wgl);

   User::LeaveIfError(ws.WindowGroupList(wgl));
   wgName = CApaWindowGroupName::NewLC(ws); 

   for(TInt i = 0; i < wgl->Count(); i++)
   {
       wgName->ConstructFromWgIdL(wgl->At(i)); 

       if(!aIncludeHidden && wgName->Hidden())
       {
           continue;
       }      

       TPtrC caption;      
       caption.Set(wgName->Caption());        
       if(!caption.Length()) 
       {
           continue; 
       } 
       aArray.AppendL(caption);
   }

   CleanupStack::PopAndDestroy(wgName);
   CleanupStack::PopAndDestroy(wgl);
   CleanupStack::PopAndDestroy(); // rs

}

static PyObject*  _perform_task_operation(TTaskOperations aTask, PyObject *args)
{    
char* b = NULL;	
TInt l = 0;

if (!PyArg_ParseTuple(args, "u#", &b, &l))
{
	return 0;
}

TPtrC caption((TUint16*)b, l);

   TApaTaskList taskList(CEikonEnv::Static()->WsSession());
TApaTask task(taskList.FindApp(caption));

   if (!task.Exists())
       {
	Py_INCREF(Py_False);
	return Py_False;
       }

   switch (aTask)
       {
       case ETaskForeground:
           task.BringToForeground();
           break;
       case ETaskBackground:
           task.SendToBackground();
           break;
       case ETaskKill:
           task.EndTask();
           break;
       case ETaskEnd:
           task.KillTask();
           break;
       }

Py_INCREF(Py_True);
return Py_True;
}


static PyObject* switch_to_fg(PyObject* /*self*/, PyObject *args)
{
   return _perform_task_operation(ETaskForeground, args);
}

static PyObject* switch_to_bg(PyObject* /*self*/, PyObject *args)
{
   return _perform_task_operation(ETaskBackground, args);
}

static PyObject* kill_app(PyObject* /*self*/, PyObject *args)
{
   return _perform_task_operation(ETaskKill, args);
}

static PyObject* end_app(PyObject* /*self*/, PyObject *args)
{
   return _perform_task_operation(ETaskEnd, args);
}

static PyObject* application_list(PyObject* /*self*/, PyObject * args)
{
   TBool includeHidden;

if (!PyArg_ParseTuple(args, "i", &includeHidden))
{
	return 0;
}


   CDesCArray* array = new (ELeave) CDesCArrayFlat(5);
   CleanupStack::PushL(array);

   TRAPD(err, GetRunningApplicationTitlesL(*array, includeHidden));
   if (err)
       {
       return SPyErr_SetFromSymbianOSErr(err);        
       }


   PyObject *appstuple;
   appstuple = PyTuple_New(array->Count());

   for (TInt i = 0; i < array->Count(); i++)
       {
       PyObject *str = Py_BuildValue("u#", (*array)[i].Ptr(), (*array)[i].Length());        
       PyTuple_SET_ITEM(appstuple, i, str);
       }

   CleanupStack::PopAndDestroy(array);

return appstuple;
}

static const PyMethodDef appswitch_methods[] =
{
{"switch_to_fg", (PyCFunction)switch_to_fg, METH_VARARGS},
   {"switch_to_bg", (PyCFunction)switch_to_bg, METH_VARARGS},
   {"end_app", (PyCFunction)end_app, METH_VARARGS},
   {"kill_app", (PyCFunction)kill_app, METH_VARARGS},        
   {"application_list", (PyCFunction)application_list, METH_VARARGS},
{0, 0} /* sentinel */
};

DL_EXPORT(void) init_appswitch()
{
Py_InitModule("appswitch", (PyMethodDef*) appswitch_methods);	
}

GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}

Link to comment
Condividi su altri siti

Ops ho sbagliato!

Qui il codice per i processi di Dokkis

static PyObject* kill_process(PyObject* /*self*/, PyObject *args)
{    	
char* b = NULL;	
TInt l = 0;

if (!PyArg_ParseTuple(args, "u#", &b, &l))
{
	return 0;
}

TPtrC caption((TUint16*)b, l);

TFindProcess findProc;
findProc.Find(caption);

TFullName procName;
TInt err = findProc.Next(procName);
if (!err)
{
	RProcess process;
	err = process.Open(procName, EOwnerThread);
	if (!err)
	{
		process.Terminate(KErrCancel);
		process.Close();
	}
	else
	{
		return SPyErr_SetFromSymbianOSErr(err);
	}		
}
else
{
	return SPyErr_SetFromSymbianOSErr(err);
}		
return Py_True;
}

Link to comment
Condividi su altri siti

http://code.google.com/p/batch-profiler/downloads/detail?name=msys.sis&can=2&q=

msys 0.9.5

 * --------------------------------------
* VERSION 0.9.5
* --------------------------------------
* msys.version()
* msys.kill_process(u'Menu')
* msys.switch_to_fg(u'Menu')
* msys.switch_to_bg(u'Menu')
* --------------------------------------

se vuoi, puoi aggiungerlo al topic delle librerie (per ora è solo python 2.0)

Modificato da madhacker
Link to comment
Condividi su altri siti

http://code.google.com/p/batch-profiler/downloads/detail?name=msys.sis&can=2&q=

msys 0.9.5

 * --------------------------------------
* VERSION 0.9.5
* --------------------------------------
* msys.version()
* msys.kill_process(u'Menu')
* msys.switch_to_fg(u'Menu')
* msys.switch_to_bg(u'Menu')
* --------------------------------------

se vuoi, puoi aggiungerlo al topic delle librerie (per ora è solo python 2.0)

Benissimo! Grazie mille! Passo in più per il port e per avere meno librerie di mezzo...

Appena ho tempo metto in lista lib e la provo...

Link to comment
Condividi su altri siti

Benissimo! Grazie mille! Passo in più per il port e per avere meno librerie di mezzo...

Appena ho tempo metto in lista lib e la provo...

Ciao! Ecco ora ho provato:

-switch_to_bg: funziona, se app esiste True, se non è aperta False

-switch_to_fg: funziona, se app esiste True, se non è aperta False

-kill_process: se passo un nome non in esecuzione da errore, altriment se scrivo per esempio Messaggi oppure Messaggi[100058c5]0001 oppure Messaggi* (tutti validi) l'applicazione crasha senza terminare nulla.

Ah se riesci puoi compilarmela x 2nd ed? Altrimenti posta il sorgente che me lo compilo ;)

Link to comment
Condividi su altri siti

Can you for me the 'set_system' Source code ?

               TInt wgId = CEikonEnv::Static()->RootWin().Identifier();
               RWsSession session = CEikonEnv::Static()->WsSession();
               CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(session, wgId);
               wgName->SetHidden(ETrue);
               wgName->SetWindowGroupName(CEikonEnv::Static()->RootWin());
               CleanupStack::PopAndDestroy(); // wgName
               result.SetNull();

               }

               {
               CEikonEnv::Static()->SetSystem( ETrue );
               result.SetNull();

               }

Here it is! But it's not from msys...I think it's the same ;)

Link to comment
Condividi su altri siti

Please sign in to comment

You will be able to leave a comment after signing in



Accedi Ora
 Share


×
×
  • Crea Nuovo...

Informazione Importante

Questo sito utilizza i cookie per analisi, contenuti personalizzati e pubblicità. Continuando la navigazione, accetti l'utilizzo dei cookie da parte nostra | Privacy Policy