⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appuifwmodule.cpp

📁 python s60 1.4.5版本的源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#if SERIES60_VERSION>=28
    {"layout", (PyCFunction)app_layout, METH_VARARGS},
#endif /* SERIES60_VERSION */
    {NULL,              NULL}           /* sentinel */
  };

  static PyObject *
  application_getattr(Application_object *op, char *name)
  {
    if (!strcmp(name, "title")) {
      Py_INCREF(op->ob_title);
      return op->ob_title;
    }

    if (!strcmp(name, "menu")) {
      Py_INCREF(op->ob_menu);
      return op->ob_menu;
    }

    if (!strcmp(name, "body")) {
      Py_INCREF(op->ob_body);
      return op->ob_body;
    }

    if (!strcmp(name, "screen")) {
      Py_INCREF(op->ob_screen);
      return op->ob_screen;
    }
#ifdef EKA2
    if (!strcmp(name, "orientation")) {
      Py_INCREF(op->ob_orientation);
      return op->ob_orientation;
    }
#endif
    if (!strcmp(name, "exit_key_handler"))
      return op->ob_data->ob_exit_key_cb.Get();
    
    if (!strcmp(name, "focus"))
      return op->ob_data->ob_focus_cb.Get();

    if (op->ob_dict_attr != NULL) {
      PyObject *v = PyDict_GetItemString(op->ob_dict_attr, name);
      if (v != NULL) {
        Py_INCREF(v);
        return v;
      }
    }

    return Py_FindMethod((PyMethodDef*)application_methods,
                         (PyObject *)op, name);
  }


  static int
  application_setattr(Application_object *op, char *name, PyObject *v)
  {
    /*
     * title
     */

    if (!strcmp(name, "title")) {
      if (!PyUnicode_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "unicode string expected");
        return -1;
      }
      
      TPtr buf(PyUnicode_AsUnicode(v), PyUnicode_GetSize(v),
               PyUnicode_GetSize(v));

      TRAPD(error, {
        CAknTitlePane* tp = (CAknTitlePane*)
          (((CEikonEnv::Static())->AppUiFactory()->StatusPane())
           ->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
        tp->SetTextL(buf);
      });

      if (error == KErrNone) {
        Py_DECREF(op->ob_title);
        op->ob_title = v;
        Py_INCREF(v);
        return 0;
      }
      else {
        SPyErr_SetFromSymbianOSErr(error);
        return -1;
      }
    }

    /*
     * menu
     */

    if (!strcmp(name, "menu")) {
      const static char menu_type_msg[] =
        "list of (unicode, callable) or (unicode, (unicode, callable)...) expected";

      if (!PyList_Check(v))  {
        PyErr_SetString(PyExc_TypeError, menu_type_msg);
        return -1;
      }

      int sz = PyList_Size(v);
      if (sz > KMaxPythonMenuExtensions) {
        PyErr_SetString(PyExc_ValueError, "too many menu items");
        return -1;
      }

      for (int i = 0; i < sz; i++) {
        PyObject* t = PyList_GetItem(v, i);
        if ((!PyTuple_Check(t)) ||
	    (!PyUnicode_Check(PyTuple_GetItem(t, 0))) ) {
          PyErr_SetString(PyExc_TypeError, menu_type_msg);
          return -1;
        }

	PyObject* secondObj = PyTuple_GetItem(t, 1);

	if (!PyCallable_Check(secondObj))
	  if (PyTuple_Check(secondObj)) { /* submenu checking */

	    int subsz = PyTuple_Size(secondObj);
	    if (subsz > KMaxPythonMenuExtensions) {
	      PyErr_SetString(PyExc_ValueError, "too many submenu items");
	      return -1;
	    }
	    
	    for (int j=0; j < subsz; j++) {
	      PyObject* submenu = PyTuple_GetItem(secondObj, j);
	      if ((!PyTuple_Check(submenu)) ||
		  (!PyUnicode_Check(PyTuple_GetItem(submenu, 0))) ||
		  (!PyCallable_Check(PyTuple_GetItem(submenu, 1)))) {
		PyErr_SetString(PyExc_TypeError, menu_type_msg);
		return -1;
	      }	      
	    }

	  }
	  else {
	    PyErr_SetString(PyExc_TypeError, menu_type_msg);
	    return -1;
	  }
      } 

      Py_XDECREF(op->ob_menu);
      op->ob_menu = v;
      Py_XINCREF(v);
      return 0;
    }
    
    /*
     * body
     */

    if (!strcmp(name, "body")) {
      if((v != Py_None) && !AppuifwControl_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "UI control expected");
        return -1;
      }

      TInt error;

      if (v == Py_None) {
        Py_BEGIN_ALLOW_THREADS
        error = op->ob_data->appui->SetHostedControl(0, 0);
        Py_END_ALLOW_THREADS
      }
      else {
        Py_BEGIN_ALLOW_THREADS
        error =
          op->ob_data->appui->
          SetHostedControl(((_control_object*)AppuifwControl_AsControl(v))->ob_control,
                           &(op->ob_data->ob_event_cb));
        Py_END_ALLOW_THREADS
      }

      if (error != KErrNone) {
        SPyErr_SetFromSymbianOSErr(error);
        return -1;
      }

      Py_XDECREF(op->ob_body);
      op->ob_body = v;
      Py_XINCREF(v);
      return 0;
    }
    

    /*
     * screen mode
     */

    if (!strcmp(name, "screen")) {
      if (!PyString_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "invalid screen setting: string expected");
        return -1;
      }
      char *screen_mode=PyString_AsString(v);
      if (!strcmp(screen_mode,"normal")) { // normal screen mode
        op->ob_data->appui->SetScreenmode(ENormal);    
      } else if (!strcmp(screen_mode,"large")) { // fullscreen with soft_keys
	         op->ob_data->appui->SetScreenmode(ELarge);
      } else if (!strcmp(screen_mode,"full")) { // full screen
        op->ob_data->appui->SetScreenmode(EFull);
      } else {
        PyErr_SetString(PyExc_TypeError, "invalid screen mode: must be one of normal, large, full");
        return -1;
      }
      Py_DECREF(op->ob_screen);
      Py_INCREF(v);
      op->ob_screen=v;
      return 0;
    }

#ifdef EKA2
    /*
     * orientation
     */

    if (!strcmp(name, "orientation")) {
      if (!PyString_Check(v)) {
        PyErr_SetString(PyExc_TypeError, "invalid orientation setting: string expected");
        return -1;
      }
      char *orientation_mode = PyString_AsString(v);
      CAknAppUiBase::TAppUiOrientation orientation = CAknAppUiBase::EAppUiOrientationAutomatic;
      
      if (!strcmp(orientation_mode,"portrait")) {
        orientation = CAknAppUiBase::EAppUiOrientationPortrait; 
      } else if (!strcmp(orientation_mode,"landscape")) {
        orientation = CAknAppUiBase::EAppUiOrientationLandscape;
      } else if (!strcmp(orientation_mode,"automatic")) {
        orientation = CAknAppUiBase::EAppUiOrientationAutomatic;
      } else {
        PyErr_SetString(PyExc_TypeError, "invalid orientation mode: must be one of portrait, landscape or automatic");
        return -1;
      }
      
      TRAPD(error, op->ob_data->appui->SetOrientationL(orientation));
      if (error != KErrNone) {
	      SPyErr_SetFromSymbianOSErr(error);
	      return -1;
      }
      
      Py_DECREF(op->ob_orientation);
      Py_INCREF(v);
      op->ob_orientation=v;
      return 0;
    }
#endif
    /*
     * exit_key_handler
     */

    if (!strcmp(name, "exit_key_handler"))
      return op->ob_data->ob_exit_key_cb.Set(v);

    /*
     * focus_handler
     */

    if (!strcmp(name, "focus"))
      return op->ob_data->ob_focus_cb.Set(v);

    /*
     * other
     */

    if (!(op->ob_dict_attr) && !(op->ob_dict_attr = PyDict_New()))
      return -1;

    if (v == NULL) {
      int rv = PyDict_DelItemString(op->ob_dict_attr, name);
      if (rv < 0)
        PyErr_SetString(PyExc_AttributeError,
                        "delete non-existing app attribute");
      return rv;
    }
    else
      return PyDict_SetItemString(op->ob_dict_attr, name, v);
  }

  static const PyTypeObject c_Application_type = {
    PyObject_HEAD_INIT(NULL)
    0,
    "Application",
    sizeof(Application_object),
    0,
    /* methods */
    (destructor)application_dealloc,    /* tp_dealloc */
    0,                                  /* tp_print */
    (getattrfunc)application_getattr,   /* tp_getattr */
    (setattrfunc)application_setattr,   /* tp_setattr */
    0,                                  /* tp_compare */
    0,                                  /* tp_repr */
    0,                                  /* tp_as _number*/
    0,                                  /* tp_as _sequence*/
    0,                                  /* tp_as _mapping*/
    0,                                  /* tp_hash */
  };
} /* extern "C" */

/*
 *
 * Implementation of appuifw.selection_list()
 *
 */

extern "C" PyObject *
selection_list(PyObject* /*self*/, PyObject* args,  PyObject *kwds)
{
  TInt error = KErrNone;
  TInt resp = 0;
  PyObject* list;
  int search = 0;

  static const char *const kwlist[] = {"choices", "search_field", NULL};

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|i", (char**)kwlist,
				   &PyList_Type, &list, &search))
    return NULL;

  if ( (search<0) || (search>1)) {
    PyErr_SetString(PyExc_ValueError, "search field can be 0 or 1");
    return NULL;
  }

  CDesCArray *items_list = new CDesCArrayFlat(5);
  if (items_list == NULL)
    return PyErr_NoMemory();

  TBuf<KMaxFileName+1> temp;
  int sz = PyList_Size(list);
  for (int i = 0; i < sz; i++) {
    PyObject* s = PyList_GetItem(list, i);
    if (!PyUnicode_Check(s))
      error = KErrArgument;
    else {
      temp.Copy(KSeparatorTab);
      temp.Append(PyUnicode_AsUnicode(s),
                  Min(PyUnicode_GetSize(s), KMaxFileName));
      TRAP(error, items_list->AppendL(temp));
    }

    if (error != KErrNone)
      break;
  }

  TInt index = (-1);
  CAknSelectionListDialog *dlg = NULL;

  if (error == KErrNone) {
    Py_BEGIN_ALLOW_THREADS
    TRAP(error, {
      dlg = CAknSelectionListDialog::NewL(index, items_list,
                                          R_AVKON_DIALOG_EMPTY_MENUBAR);
      if (search==1)
	resp = dlg->ExecuteLD(R_APPUIFW_SEL_LIST_QUERY);
      else
	resp = dlg->ExecuteLD(R_APPUIFW_SEL_LIST);
    });
    Py_END_ALLOW_THREADS
  }

  delete items_list;

  if ((error == KErrNone) && resp)
    return Py_BuildValue("i", index);
  else
    RETURN_ERROR_OR_PYNONE(error);
}

/*
 *
 * Implementation of appuifw.multi_selection_list()
 *
 */
#if SERIES60_VERSION==28
_LIT(KIconsFile, "Z:\\system\\data\\avkon2.mif");
#elif SERIES60_VERSION>28
_LIT(KIconsFile, "Z:\\resource\\apps\\avkon2.mif");
#else
_LIT(KIconsFile, "Z:\\system\\data\\avkon.mbm");
#endif /* SERIES60_VERSION */

extern "C" PyObject *
multi_selection_list(PyObject* /*self*/, PyObject *args, PyObject *kwds)
{
  TInt error = KErrNone;
  PyObject* list;
  char *type = NULL;
  int l_type = 0;
  int search = 0;
  TBool isChkbx = EFalse;

  static const char *const kwlist[] = {"choices", "style", "search_field", NULL};

  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|s#i", (char**)kwlist,
				   &PyList_Type, &list, &type, &l_type, &search))
    return NULL;

  TPtrC8 type_style((TUint8*)type, l_type);

  if (!type || (type_style.Compare(KCheckboxStyle) == 0))
    isChkbx = ETrue;
  else if (type && (type_style.Compare(KCheckmarkStyle) != 0)) {
    PyErr_SetString(PyExc_ValueError, "unknown style type");
    return NULL;
  }

  if ( (search<0) || (search>1) ){
    PyErr_SetString(PyExc_ValueError, "search field can be 0 or 1");
    return NULL;
  }

  PyObject* selected = NULL;
  int sz = PyList_Size(list);

  CDesCArray *items_list = new CDesCArrayFlat(5);
  if (items_list == NULL)
    return PyErr_NoMemory();

  CArrayFixFlat<TInt> *selected_items = NULL;
  TRAP(error, 
       selected_items = new(ELeave) CArrayFixFlat<TInt>(sz));

  if (error != KErrNone) {
    delete items_list;
    items_list = NULL;
    selected_items = NULL;
    return SPyErr_SetFromSymbianOSErr(error);
  }

  TBuf<KMaxFileName+1> temp;

  for (int i = 0; i < sz; i++) {
    PyObject* s = PyList_GetItem(list, i);
    if (!PyUnicode_Check(s))
      error = KErrArgument;
    else {
      if (isChkbx) {
        temp.Copy(_L("1\t"));
      }
      else {
        temp.Copy(_L("\t"));
      }
      temp.Append(PyUnicode_AsUnicode(s),
		  Min(PyUnicode_GetSize(s), KMaxFileName));
      TRAP(error, items_list->AppendL(temp));
    }
    
    if (error != KErrNone)
      break;
  }

  CArrayPtr<CGulIcon>* icons = NULL;
  TRAP(error,
       icons = new(ELeave) CArrayPtrFlat<CGulIcon>(2));

  if (error != KErrNone) {
    delete items_list;
    items_list = NULL;
    delete selected_items;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -