X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/00ca6262d110264500eb263d1c2695cca55a6b0d..98672b4b9cb156c624a66efd5b3c1935a1d37de9:/wxPython/src/misc2.i diff --git a/wxPython/src/misc2.i b/wxPython/src/misc2.i index 9da8e9f530..74c55bd82f 100644 --- a/wxPython/src/misc2.i +++ b/wxPython/src/misc2.i @@ -16,6 +16,7 @@ %{ #include "helpers.h" +#include "pyistream.h" #include #include #include @@ -48,32 +49,41 @@ %import streams.i %import utils.i -%{ - static wxString wxPyEmptyStr(""); -%} //--------------------------------------------------------------------------- // Dialog Functions -wxString wxFileSelector(char* message, - char* default_path = NULL, - char* default_filename = NULL, - char* default_extension = NULL, - char* wildcard = "*.*", +wxString wxFileSelector(const wxChar* message = wxFileSelectorPromptStr, + const wxChar* default_path = NULL, + const wxChar* default_filename = NULL, + const wxChar* default_extension = NULL, + const wxChar* wildcard = wxFileSelectorDefaultWildcardStr, int flags = 0, wxWindow *parent = NULL, int x = -1, int y = -1); +// Ask for filename to load +wxString wxLoadFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name = NULL, + wxWindow *parent = NULL); + +// Ask for filename to save +wxString wxSaveFileSelector(const wxChar *what, + const wxChar *extension, + const wxChar *default_name = NULL, + wxWindow *parent = NULL); + wxString wxGetTextFromUser(const wxString& message, - const wxString& caption = wxPyEmptyStr, - const wxString& default_value = wxPyEmptyStr, + const wxString& caption = wxEmptyString, + const wxString& default_value = wxEmptyString, wxWindow *parent = NULL, int x = -1, int y = -1, bool centre = TRUE); wxString wxGetPasswordFromUser(const wxString& message, - const wxString& caption = wxPyEmptyStr, - const wxString& default_value = wxPyEmptyStr, + const wxString& caption = wxEmptyString, + const wxString& default_value = wxEmptyString, wxWindow *parent = NULL); @@ -101,7 +111,7 @@ int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption, int wxMessageBox(const wxString& message, - const wxString& caption = wxPyEmptyStr, + const wxString& caption = wxEmptyString, int style = wxOK | wxCENTRE, wxWindow *parent = NULL, int x = -1, int y = -1); @@ -166,28 +176,27 @@ bool wxResourceParseString(char *resource, wxResourceTable *table = NULL); //--------------------------------------------------------------------------- // System Settings -enum { - wxSYS_WHITE_BRUSH, - wxSYS_LTGRAY_BRUSH, - wxSYS_GRAY_BRUSH, - wxSYS_DKGRAY_BRUSH, - wxSYS_BLACK_BRUSH, - wxSYS_NULL_BRUSH, - wxSYS_HOLLOW_BRUSH, - wxSYS_WHITE_PEN, - wxSYS_BLACK_PEN, - wxSYS_NULL_PEN, - wxSYS_OEM_FIXED_FONT, +// possible values for wxSystemSettings::GetFont() parameter +// +enum wxSystemFont +{ + wxSYS_OEM_FIXED_FONT = 10, wxSYS_ANSI_FIXED_FONT, wxSYS_ANSI_VAR_FONT, wxSYS_SYSTEM_FONT, wxSYS_DEVICE_DEFAULT_FONT, wxSYS_DEFAULT_PALETTE, wxSYS_SYSTEM_FIXED_FONT, - wxSYS_DEFAULT_GUI_FONT, + wxSYS_DEFAULT_GUI_FONT +}; +// possible values for wxSystemSettings::GetColour() parameter +// +enum wxSystemColour +{ wxSYS_COLOUR_SCROLLBAR, wxSYS_COLOUR_BACKGROUND, + wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND, wxSYS_COLOUR_ACTIVECAPTION, wxSYS_COLOUR_INACTIVECAPTION, wxSYS_COLOUR_MENU, @@ -202,25 +211,35 @@ enum { wxSYS_COLOUR_HIGHLIGHT, wxSYS_COLOUR_HIGHLIGHTTEXT, wxSYS_COLOUR_BTNFACE, + wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE, wxSYS_COLOUR_BTNSHADOW, + wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW, wxSYS_COLOUR_GRAYTEXT, wxSYS_COLOUR_BTNTEXT, wxSYS_COLOUR_INACTIVECAPTIONTEXT, wxSYS_COLOUR_BTNHIGHLIGHT, - + wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT, + wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT, + wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT, wxSYS_COLOUR_3DDKSHADOW, wxSYS_COLOUR_3DLIGHT, wxSYS_COLOUR_INFOTEXT, wxSYS_COLOUR_INFOBK, + wxSYS_COLOUR_LISTBOX, + wxSYS_COLOUR_HOTLIGHT, + wxSYS_COLOUR_GRADIENTACTIVECAPTION, + wxSYS_COLOUR_GRADIENTINACTIVECAPTION, + wxSYS_COLOUR_MENUHILIGHT, + wxSYS_COLOUR_MENUBAR, + + wxSYS_COLOUR_MAX +}; - wxSYS_COLOUR_DESKTOP, - wxSYS_COLOUR_3DFACE, - wxSYS_COLOUR_3DSHADOW, - wxSYS_COLOUR_3DHIGHLIGHT, - wxSYS_COLOUR_3DHILIGHT, - wxSYS_COLOUR_BTNHILIGHT, - - wxSYS_MOUSE_BUTTONS, +// possible values for wxSystemSettings::GetMetric() parameter +// +enum wxSystemMetric +{ + wxSYS_MOUSE_BUTTONS = 1, wxSYS_BORDER_X, wxSYS_BORDER_Y, wxSYS_CURSOR_X, @@ -256,25 +275,35 @@ enum { wxSYS_NETWORK_PRESENT, wxSYS_PENWINDOWS_PRESENT, wxSYS_SHOW_SOUNDS, - wxSYS_SWAP_BUTTONS, + wxSYS_SWAP_BUTTONS }; +// possible values for wxSystemSettings::HasFeature() parameter +enum wxSystemFeature +{ + wxSYS_CAN_DRAW_FRAME_DECORATIONS = 1, + wxSYS_CAN_ICONIZE_FRAME +}; -%inline %{ - wxColour wxSystemSettings_GetSystemColour(int index) { - return wxSystemSettings::GetSystemColour(index); - } +class wxSystemSettings { +public: + // get a standard system colour + static wxColour GetColour(wxSystemColour index); + + // get a standard system font + static wxFont GetFont(wxSystemFont index); + + // get a system-dependent metric + static int GetMetric(wxSystemMetric index); + + // return true if the port has certain feature + static bool HasFeature(wxSystemFeature index); + +}; - wxFont wxSystemSettings_GetSystemFont(int index) { - return wxSystemSettings::GetSystemFont(index); - } - int wxSystemSettings_GetSystemMetric(int index) { - return wxSystemSettings::GetSystemMetric(index); - } -%} //--------------------------------------------------------------------------- // wxToolTip @@ -347,8 +376,8 @@ IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEnc public: wxPyFontEnumerator(); ~wxPyFontEnumerator(); - void _setCallbackInfo(PyObject* self, PyObject* _class); - %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator)" + void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref); + %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)" bool EnumerateFacenames( wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all @@ -360,12 +389,12 @@ public: %addmethods { PyObject* GetEncodings() { wxArrayString* arr = self->GetEncodings(); - return wxArrayString2PyList_helper(arr); + return wxArrayString2PyList_helper(*arr); } PyObject* GetFacenames() { wxArrayString* arr = self->GetFacenames(); - return wxArrayString2PyList_helper(arr); + return wxArrayString2PyList_helper(*arr); } } }; @@ -521,6 +550,7 @@ class wxStopWatch public: // ctor starts the stop watch wxStopWatch(); + ~wxStopWatch(); void Start(long t = 0); void Pause(); void Resume(); @@ -556,7 +586,7 @@ public: static bool IsEnabled(); static bool EnableLogging(bool doIt = TRUE); - static void OnLog(wxLogLevel level, const char *szString, int t=0); + static void OnLog(wxLogLevel level, const wxString& szString, int t=0); virtual void Flush(); bool HasPendingMessages() const; @@ -582,7 +612,7 @@ public: bool GetVerbose() const { return m_bVerbose; } static wxTraceMask GetTraceMask(); - static bool IsAllowedTraceMask(const char *mask); + static bool IsAllowedTraceMask(const wxString& mask); // static void TimeStamp(wxString *str); %addmethods { @@ -619,7 +649,7 @@ class wxLogWindow : public wxLog { public: wxLogWindow(wxFrame *pParent, // the parent frame (can be NULL) - const char *szTitle, // the title of the frame + const wxString& szTitle, // the title of the frame bool bShow = TRUE, // show window immediately? bool bPassToOld = TRUE); // pass log messages to the old target? @@ -627,7 +657,7 @@ public: wxFrame *GetFrame() const; wxLog *GetOldLog() const; bool IsPassingMessages() const; - void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; } + void PassMessages(bool bDoPass); }; @@ -651,16 +681,16 @@ public: unsigned long wxSysErrorCode(); -const char* wxSysErrorMsg(unsigned long nErrCode = 0); -void wxLogFatalError(const char *szFormat); -void wxLogError(const char *szFormat); -void wxLogWarning(const char *szFormat); -void wxLogMessage(const char *szFormat); -void wxLogInfo(const char *szFormat); -void wxLogVerbose(const char *szFormat); -void wxLogStatus(const char *szFormat); -%name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const char *szFormat); -void wxLogSysError(const char *szFormat); +const wxString wxSysErrorMsg(unsigned long nErrCode = 0); +void wxLogFatalError(const wxString& szFormat); +void wxLogError(const wxString& szFormat); +void wxLogWarning(const wxString& szFormat); +void wxLogMessage(const wxString& szFormat); +void wxLogInfo(const wxString& szFormat); +void wxLogVerbose(const wxString& szFormat); +void wxLogStatus(const wxString& szFormat); +%name(wxLogStatusFrame)void wxLogStatus(wxFrame *pFrame, const wxString& szFormat); +void wxLogSysError(const wxString& szFormat); %{ @@ -671,20 +701,22 @@ public: virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) { bool found; - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t)); - wxPyEndBlockThreads(state); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, + wx2PyString(szString), t)); + wxPyEndBlockThreads(); if (! found) wxLog::DoLog(level, szString, t); } virtual void DoLogString(const wxChar *szString, time_t t) { bool found; - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t)); - wxPyEndBlockThreads(state); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", + wx2PyString(szString), t)); + wxPyEndBlockThreads(); if (! found) wxLog::DoLogString(szString, t); } @@ -777,9 +809,9 @@ long wxExecute(const wxString& command, class wxJoystick : public wxObject { public: wxJoystick(int joystick = wxJOYSTICK1) { - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); PyErr_SetString(PyExc_NotImplementedError, "wxJoystick is not available on this platform."); - wxPyEndBlockThreads(state); + wxPyEndBlockThreads(); } wxPoint GetPosition() { return wxPoint(-1,-1); } int GetZPosition() { return -1; } @@ -892,14 +924,14 @@ class wxWave : public wxObject { public: wxWave(const wxString& fileName, bool isResource = FALSE) { - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform."); - wxPyEndBlockThreads(state); + wxPyEndBlockThreads(); } wxWave(int size, const wxByte* data) { - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); PyErr_SetString(PyExc_NotImplementedError, "wxWave is not available on this platform."); - wxPyEndBlockThreads(state); + wxPyEndBlockThreads(); } ~wxWave() {} @@ -1019,8 +1051,8 @@ public: { public: // ctors - MessageParameters(const wxString& filename=wxPyEmptyStr, - const wxString& mimetype=wxPyEmptyStr); + MessageParameters(const wxString& filename=wxEmptyString, + const wxString& mimetype=wxEmptyString); // accessors (called by GetOpenCommand) // filename @@ -1043,8 +1075,13 @@ public: %addmethods { PyObject* GetMimeType() { wxString str; - if (self->GetMimeType(&str)) - return PyString_FromString(str.c_str()); + if (self->GetMimeType(&str)) { +#if wxUSE_UNICODE + return PyUnicode_FromUnicode(str.c_str(), str.Len()); +#else + return PyString_FromStringAndSize(str.c_str(), str.Len()); +#endif + } else RETURN_NONE(); } @@ -1087,13 +1124,17 @@ public: wxString iconFile; int iconIndex; if (self->GetIcon(&icon, &iconFile, &iconIndex)) { - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); PyObject* tuple = PyTuple_New(3); PyTuple_SetItem(tuple, 0, wxPyConstructObject(new wxIcon(icon), "wxIcon", TRUE)); - PyTuple_SetItem(tuple, 1, PyString_FromString(iconFile.c_str())); +#if wxUSE_UNICODE + PyTuple_SetItem(tuple, 1, PyUnicode_FromUnicode(iconFile.c_str(), iconFile.Len())); +#else + PyTuple_SetItem(tuple, 1, PyString_FromStringAndSize(iconFile.c_str(), iconFile.Len())); +#endif PyTuple_SetItem(tuple, 2, PyInt_FromLong(iconIndex)); - wxPyEndBlockThreads(state); + wxPyEndBlockThreads(); return tuple; } else @@ -1105,9 +1146,13 @@ public: // get a brief file type description ("*.txt" => "text document") PyObject* GetDescription() { wxString str; - if (self->GetDescription(&str)) - return PyString_FromString(str.c_str()); - else + if (self->GetDescription(&str)) { +#if wxUSE_UNICODE + return PyUnicode_FromUnicode(str.c_str(), str.Len()); +#else + return PyString_FromStringAndSize(str.c_str(), str.Len()); +#endif + } else RETURN_NONE(); } } @@ -1116,11 +1161,15 @@ public: // get the command to open/execute the file of given type %addmethods { PyObject* GetOpenCommand(const wxString& filename, - const wxString& mimetype=wxPyEmptyStr) { + const wxString& mimetype=wxEmptyString) { wxString str; - if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) - return PyString_FromString(str.c_str()); - else + if (self->GetOpenCommand(&str, wxFileType::MessageParameters(filename, mimetype))) { +#if wxUSE_UNICODE + return PyUnicode_FromUnicode(str.c_str(), str.Len()); +#else + return PyString_FromStringAndSize(str.c_str(), str.Len()); +#endif + } else RETURN_NONE(); } } @@ -1129,11 +1178,15 @@ public: // get the command to print the file of given type %addmethods { PyObject* GetPrintCommand(const wxString& filename, - const wxString& mimetype=wxPyEmptyStr) { + const wxString& mimetype=wxEmptyString) { wxString str; - if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) - return PyString_FromString(str.c_str()); - else + if (self->GetPrintCommand(&str, wxFileType::MessageParameters(filename, mimetype))) { +#if wxUSE_UNICODE + return PyUnicode_FromUnicode(str.c_str(), str.Len()); +#else + return PyString_FromStringAndSize(str.c_str(), str.Len()); +#endif + } else RETURN_NONE(); } } @@ -1142,16 +1195,16 @@ public: // Get all commands defined for this file type %addmethods { PyObject* GetAllCommands(const wxString& filename, - const wxString& mimetype=wxPyEmptyStr) { + const wxString& mimetype=wxEmptyString) { wxArrayString verbs; wxArrayString commands; if (self->GetAllCommands(&verbs, &commands, wxFileType::MessageParameters(filename, mimetype))) { - wxPyTState* state = wxPyBeginBlockThreads(); + wxPyBeginBlockThreads(); PyObject* tuple = PyTuple_New(2); PyTuple_SetItem(tuple, 0, wxArrayString2PyList_helper(verbs)); PyTuple_SetItem(tuple, 1, wxArrayString2PyList_helper(commands)); - wxPyEndBlockThreads(state); + wxPyEndBlockThreads(); return tuple; } else