X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/68320e40cde2ceaac4645db9ae2989e3101fde45..174911cfd60f5cde1f1ebc78df0a8b8ff648a197:/wxPython/src/misc2.i diff --git a/wxPython/src/misc2.i b/wxPython/src/misc2.i index dfdefeda5d..5747f5774b 100644 --- a/wxPython/src/misc2.i +++ b/wxPython/src/misc2.i @@ -16,10 +16,10 @@ %{ #include "helpers.h" +#include "pyistream.h" #include #include #include -#include #include #include @@ -48,32 +48,58 @@ %import streams.i %import utils.i + +//---------------------------------------------------------------------- + %{ - static wxString wxPyEmptyStr(""); + // Put some wx default wxChar* values into wxStrings. + DECLARE_DEF_STRING(FileSelectorPromptStr); + DECLARE_DEF_STRING(FileSelectorDefaultWildcardStr); + DECLARE_DEF_STRING(DirSelectorPromptStr); + static const wxString wxPyEmptyString(wxT("")); %} //--------------------------------------------------------------------------- // Dialog Functions -wxString wxFileSelector(char* message, - char* default_path = NULL, - char* default_filename = NULL, - char* default_extension = NULL, - char* wildcard = "*.*", +wxString wxFileSelector(const wxString& message = wxPyFileSelectorPromptStr, + const wxString& default_path = wxPyEmptyString, + const wxString& default_filename = wxPyEmptyString, + const wxString& default_extension = wxPyEmptyString, + const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr, int flags = 0, wxWindow *parent = NULL, int x = -1, int y = -1); +// Ask for filename to load +wxString wxLoadFileSelector(const wxString& what, + const wxString& extension, + const wxString& default_name = wxPyEmptyString, + wxWindow *parent = NULL); + +// Ask for filename to save +wxString wxSaveFileSelector(const wxString& what, + const wxString& extension, + const wxString& default_name = wxPyEmptyString, + wxWindow *parent = NULL); + + +wxString wxDirSelector(const wxString& message = wxPyDirSelectorPromptStr, + const wxString& defaultPath = wxPyEmptyString, + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxDD_NEW_DIR_BUTTON, + const wxPoint& pos = wxDefaultPosition, + wxWindow *parent = NULL); + wxString wxGetTextFromUser(const wxString& message, - const wxString& caption = wxPyEmptyStr, - const wxString& default_value = wxPyEmptyStr, + const wxString& caption = wxPyEmptyString, + const wxString& default_value = wxPyEmptyString, 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 = wxPyEmptyString, + const wxString& default_value = wxPyEmptyString, wxWindow *parent = NULL); @@ -101,7 +127,7 @@ int wxGetSingleChoiceIndex(const wxString& message, const wxString& caption, int wxMessageBox(const wxString& message, - const wxString& caption = wxPyEmptyStr, + const wxString& caption = wxPyEmptyString, int style = wxOK | wxCENTRE, wxWindow *parent = NULL, int x = -1, int y = -1); @@ -153,15 +179,15 @@ void wxFlushEvents(); //--------------------------------------------------------------------------- // Resource System -bool wxResourceAddIdentifier(char *name, int value); +bool wxResourceAddIdentifier(char* name, int value); void wxResourceClear(void); -wxBitmap wxResourceCreateBitmap(char *resource); -wxIcon wxResourceCreateIcon(char *resource); -wxMenuBar * wxResourceCreateMenuBar(char *resource); -int wxResourceGetIdentifier(char *name); -bool wxResourceParseData(char *resource, wxResourceTable *table = NULL); -bool wxResourceParseFile(char *filename, wxResourceTable *table = NULL); -bool wxResourceParseString(char *resource, wxResourceTable *table = NULL); +wxBitmap wxResourceCreateBitmap(char* resource); +wxIcon wxResourceCreateIcon(char* resource); +wxMenuBar * wxResourceCreateMenuBar(char* resource); +int wxResourceGetIdentifier(char* name); +bool wxResourceParseData(char* resource, wxResourceTable *table = NULL); +bool wxResourceParseFile(char* filename, wxResourceTable *table = NULL); +bool wxResourceParseString(char* resource, wxResourceTable *table = NULL); //--------------------------------------------------------------------------- // System Settings @@ -186,6 +212,7 @@ enum wxSystemColour { wxSYS_COLOUR_SCROLLBAR, wxSYS_COLOUR_BACKGROUND, + wxSYS_COLOUR_DESKTOP = wxSYS_COLOUR_BACKGROUND, wxSYS_COLOUR_ACTIVECAPTION, wxSYS_COLOUR_INACTIVECAPTION, wxSYS_COLOUR_MENU, @@ -200,23 +227,28 @@ enum wxSystemColour 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_DESKTOP = wxSYS_COLOUR_BACKGROUND, - wxSYS_COLOUR_3DFACE = wxSYS_COLOUR_BTNFACE, - wxSYS_COLOUR_3DSHADOW = wxSYS_COLOUR_BTNSHADOW, - wxSYS_COLOUR_3DHIGHLIGHT = wxSYS_COLOUR_BTNHIGHLIGHT, - wxSYS_COLOUR_3DHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT, - wxSYS_COLOUR_BTNHILIGHT = wxSYS_COLOUR_BTNHIGHLIGHT + wxSYS_COLOUR_MAX }; // possible values for wxSystemSettings::GetMetric() parameter @@ -339,52 +371,6 @@ public: //---------------------------------------------------------------------- -%{ -class wxPyFontEnumerator : public wxFontEnumerator { -public: - wxPyFontEnumerator() {} - ~wxPyFontEnumerator() {} - - DEC_PYCALLBACK_BOOL_STRING(OnFacename); - DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding); - - PYPRIVATE; -}; - -IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename); -IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding); - -%} - -%name(wxFontEnumerator) class wxPyFontEnumerator { -public: - wxPyFontEnumerator(); - ~wxPyFontEnumerator(); - void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref); - %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxFontEnumerator, 0)" - - bool EnumerateFacenames( - wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all - bool fixedWidthOnly = FALSE); - bool EnumerateEncodings(const char* facename = ""); - - //wxArrayString* GetEncodings(); - //wxArrayString* GetFacenames(); - %addmethods { - PyObject* GetEncodings() { - wxArrayString* arr = self->GetEncodings(); - return wxArrayString2PyList_helper(*arr); - } - - PyObject* GetFacenames() { - wxArrayString* arr = self->GetFacenames(); - return wxArrayString2PyList_helper(*arr); - } - } -}; - -//---------------------------------------------------------------------- - class wxBusyCursor { public: wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR); @@ -570,7 +556,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 +568,7 @@ public: static void Suspend(); static void Resume(); - void SetVerbose(bool bVerbose = TRUE); + static void SetVerbose(bool bVerbose = TRUE); static void DontCreateOnDemand(); static void SetTraceMask(wxTraceMask ulMask); @@ -590,13 +576,13 @@ public: static void RemoveTraceMask(const wxString& str); static void ClearTraceMasks(); - static void SetTimestamp(const wxChar *ts); - static const wxChar *GetTimestamp(); + static void SetTimestamp(const wxString& ts); + static const wxString& GetTimestamp(); 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 { @@ -606,6 +592,7 @@ public: return msg; } } + }; @@ -633,7 +620,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? @@ -641,7 +628,7 @@ public: wxFrame *GetFrame() const; wxLog *GetOldLog() const; bool IsPassingMessages() const; - void PassMessages(bool bDoPass) { m_bPassMessages = bDoPass; } + void PassMessages(bool bDoPass); }; @@ -665,16 +652,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); %{ @@ -687,7 +674,8 @@ public: bool found; wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLog"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(isi)", level, szString, t)); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iOi)", level, + wx2PyString(szString), t)); wxPyEndBlockThreads(); if (! found) wxLog::DoLog(level, szString, t); @@ -697,7 +685,8 @@ public: bool found; wxPyBeginBlockThreads(); if ((found = wxPyCBH_findCallback(m_myInst, "DoLogString"))) - wxPyCBH_callCallback(m_myInst, Py_BuildValue("(si)", szString, t)); + wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oi)", + wx2PyString(szString), t)); wxPyEndBlockThreads(); if (! found) wxLog::DoLogString(szString, t); @@ -778,9 +767,26 @@ public: }; +enum +{ + // execute the process asynchronously + wxEXEC_ASYNC = 0, + + // execute it synchronously, i.e. wait until it finishes + wxEXEC_SYNC = 1, + + // under Windows, don't hide the child even if it's IO is redirected (this + // is done by default) + wxEXEC_NOHIDE = 2, + + // under Unix, if the process is the group leader then killing -pid kills + // all children as well as pid + wxEXEC_MAKE_GROUP_LEADER = 4 +}; + long wxExecute(const wxString& command, - int sync = FALSE, + int flags = wxEXEC_ASYNC, wxPyProcess *process = NULL); //---------------------------------------------------------------------- @@ -962,10 +968,10 @@ class wxFileTypeInfo public: // ctors // a normal item - wxFileTypeInfo(const char *mimeType, - const char *openCmd, - const char *printCmd, - const char *desc); + wxFileTypeInfo(const char* mimeType, + const char* openCmd, + const char* printCmd, + const char* desc); // the array elements correspond to the parameters of the ctor above in @@ -1033,8 +1039,8 @@ public: { public: // ctors - MessageParameters(const wxString& filename=wxPyEmptyStr, - const wxString& mimetype=wxPyEmptyStr); + MessageParameters(const wxString& filename=wxPyEmptyString, + const wxString& mimetype=wxPyEmptyString); // accessors (called by GetOpenCommand) // filename @@ -1057,8 +1063,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(); } @@ -1105,7 +1116,11 @@ public: 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(); return tuple; @@ -1119,9 +1134,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(); } } @@ -1130,11 +1149,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=wxPyEmptyString) { 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(); } } @@ -1143,11 +1166,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=wxPyEmptyString) { 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(); } } @@ -1156,7 +1183,7 @@ public: // Get all commands defined for this file type %addmethods { PyObject* GetAllCommands(const wxString& filename, - const wxString& mimetype=wxPyEmptyStr) { + const wxString& mimetype=wxPyEmptyString) { wxArrayString verbs; wxArrayString commands; if (self->GetAllCommands(&verbs, &commands, @@ -1179,7 +1206,7 @@ public: bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = TRUE); - bool SetDefaultIcon(const wxString& cmd = wxEmptyString, int index = 0); + bool SetDefaultIcon(const wxString& cmd = wxPyEmptyString, int index = 0); // remove the association for this filetype from the system MIME database: @@ -1223,7 +1250,7 @@ public: // use the extraDir parameter if you want to look for files in another // directory void Initialize(int mailcapStyle = wxMAILCAP_STANDARD, - const wxString& extraDir = wxEmptyString); + const wxString& extraDir = wxPyEmptyString); // and this function clears all the data from the manager void ClearData(); @@ -1321,7 +1348,7 @@ public: void Save(wxConfigBase& config); void AddFilesToMenu(); - %name(AddFilesToSingleMenu)void AddFilesToMenu(wxMenu* menu); + %name(AddFilesToThisMenu)void AddFilesToMenu(wxMenu* menu); // Accessors wxString GetHistoryFile(int i) const; @@ -1337,7 +1364,6 @@ public: %init %{ - wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator"); wxPyPtrTypeMap_Add("wxDragImage", "wxGenericDragImage"); wxPyPtrTypeMap_Add("wxProcess", "wxPyProcess"); %}