body.tex

来自「Wxpython Implemented on Windows CE, Sou」· TEX 代码 · 共 689 行 · 第 1/3 页

TEX
689
字号
considerably. For this reason, you will find (in the common
X and Windows parts of the library) conditional
compilation that under Unix, includes a minimal set of headers;
and when using Visual C++, includes {\tt wx.h}. This should help provide
the optimal compilation for each compiler, although it is
biased towards the precompiled headers facility available
in Microsoft C++.

\section{File handling}\label{filehandling}

When building an application which may be used under different
environments, one difficulty is coping with documents which may be
moved to different directories on other machines. Saving a file which
has pointers to full pathnames is going to be inherently unportable. One
approach is to store filenames on their own, with no directory
information.  The application searches through a number of locally
defined directories to find the file. To support this, the class {\bf
wxPathList} makes adding directories and searching for files easy, and
the global function {\bf wxFileNameFromPath} allows the application to
strip off the filename from the path if the filename must be stored.
This has undesirable ramifications for people who have documents of the
same name in different directories.

As regards the limitations of DOS 8+3 single-case filenames versus
unrestricted Unix filenames, the best solution is to use DOS filenames
for your application, and also for document filenames {\it if} the user
is likely to be switching platforms regularly. Obviously this latter
choice is up to the application user to decide.  Some programs (such as
YACC and LEX) generate filenames incompatible with DOS; the best
solution here is to have your Unix makefile rename the generated files
to something more compatible before transferring the source to DOS.
Transferring DOS files to Unix is no problem, of course, apart from EOL
conversion for which there should be a utility available (such as
dos2unix).

See also the File Functions section of the reference manual for
descriptions of miscellaneous file handling functions.

\chapter{Utilities and libraries supplied with wxWidgets}\label{utilities}
\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
\setfooter{\thepage}{}{}{}{}{\thepage}%

In addition to the core wxWidgets library, a number of further
libraries and utilities are supplied with each distribution.

Some are under the 'contrib' hierarchy which mirrors the
structure of the main wxWidgets hierarchy. See also the 'utils'
hierarchy. The first place to look for documentation about
these tools and libraries is under the wxWidgets 'docs' hierarchy,
for example {\tt docs/htmlhelp/fl.chm}.

For other user-contributed packages, please see the Contributions page
on the \urlref{wxWidgets Web site}{http://www.wxwidgets.org}.

\begin{description}\itemsep=0pt
\item[{\bf Helpview}]
Helpview is a program for displaying wxWidgets HTML
Help files. In many cases, you may wish to use the wxWidgets HTML
Help classes from within your application, but this provides a
handy stand-alone viewer. See \helpref{wxHTML Notes}{wxhtml} for more details.
You can find it in {\tt samples/html/helpview}.
\item[{\bf Tex2RTF}]
Supplied with wxWidgets is a utility called Tex2RTF for converting\rtfsp
\LaTeX\ manuals HTML, MS HTML Help, wxHTML Help, RTF, and Windows
Help RTF formats. Tex2RTF is used for the wxWidgets manuals and can be used independently
by authors wishing to create on-line and printed manuals from the same\rtfsp
\LaTeX\ source. Please see the separate documentation for Tex2RTF.
You can find it under {\tt utils/tex2rtf}.
\item[{\bf Helpgen}]
Helpgen takes C++ header files and generates a Tex2RTF-compatible
documentation file for each class it finds, using comments as appropriate.
This is a good way to start a reference for a set of classes.
Helpgen can be found in {\tt utils/HelpGen}.
\item[{\bf Emulator}]
Xnest-based display emulator for X11-based PDA applications. On some
systems, the Xnest window does not synchronise with the
'skin' window. This program can be found in {\tt utils/emulator}.
\item[{\bf Configuration Tool}]
The wxWidgets Configuration Tool is a work in progress
intended to make it easier to configure wxWidgets
features in detail. It exports setup.h configurations and will
eventually generate makefile config files. Invoking compilers is
also on the cards. Since configurations are
handled one at a time, the tool is of limited used until further
development can be done. The program can be found in {\tt utils/configtool}.
\item[{\bf XRC resource system}]
This is the sizer-aware resource system, and uses
XML-based resource specifications that can be generated by tools
such as \urlref{wxDesigner}{http://www.roebling.de}.
You can find this in {\tt src/xrc}, {\tt include/wx/xrc}, {\tt samples/xrc}.
For more information, see the \helpref{XML-based resource system overview}{xrcoverview}.
\item[{\bf Object Graphics Library}]
OGL defines an API for applications that need to display objects connected by lines.
The objects can be moved around and interacted with.
You can find this in {\tt contrib/src/ogl}, {\tt contrib/include/wx/ogl}, and {\tt contrib/samples/ogl}.
\item[{\bf Frame Layout library}]
FL provides sophisticated pane dragging and docking facilities.
You can find this in {\tt contrib/src/fl}, {\tt contrib/include/wx/fl}, and {\tt contrib/samples/fl}.
\item[{\bf Gizmos library}]
Gizmos is a collection of useful widgets and other classes. Classes include wxLEDNumberCtrl,
wxEditableListBox, wxMultiCellCanvas.
You can find this in {\tt contrib/src/gizmos}, {\tt contrib/include/wx/gizmos}, and {\tt contrib/samples/gizmos}.
\item[{\bf Net library}]
Net is a collection of very simple mail and web related classes. Currently
there is only wxEmail, which makes it easy to send email messages via MAPI on Windows or sendmail on Unix.
You can find this in {\tt contrib/src/net} and {\tt contrib/include/wx/net}.
\item[{\bf Animate library}]
Animate allows you to load animated GIFs and play them on a window. The library can be extended
to use other animation formats.
You can find this in {\tt contrib/src/animate}, {\tt contrib/include/wx/animate}, and {\tt contrib/samples/animate}.
\item[{\bf MMedia library}]
Mmedia supports a variety of multimedia functionality. The status of this library is currently unclear.
You can find this in {\tt contrib/src/mmedia}, {\tt contrib/include/wx/mmedia}, and {\tt contrib/samples/mmedia}.
\item[{\bf Styled Text Control library}]
STC is a wrapper around Scintilla, a syntax-highlighting text editor.
You can find this in {\tt contrib/src/stc}, {\tt contrib/include/wx/stc}, and {\tt contrib/samples/stc}.
\item[{\bf Plot}]
Plot is a simple curve plotting library.
You can find this in {\tt contrib/src/plot}, {\tt contrib/include/wx/plot}, and {\tt contrib/samples/plot}.
\end{description}

\chapter{Programming strategies}\label{strategies}
\setheader{{\it CHAPTER \thechapter}}{}{}{}{}{{\it CHAPTER \thechapter}}%
\setfooter{\thepage}{}{}{}{}{\thepage}%

This chapter is intended to list strategies that may be useful when
writing and debugging wxWidgets programs. If you have any good tips,
please submit them for inclusion here.

\section{Strategies for reducing programming errors}\label{reducingerrors}

\subsection{Use ASSERT}\label{useassert}

Although I haven't done this myself within wxWidgets, it is good
practice to use ASSERT statements liberally, that check for conditions that
should or should not hold, and print out appropriate error messages.
These can be compiled out of a non-debugging version of wxWidgets
and your application. Using ASSERT is an example of `defensive programming':
it can alert you to problems later on.

\subsection{Use wxString in preference to character arrays}\label{usewxstring}

Using wxString can be much safer and more convenient than using char *.
Again, I haven't practiced what I'm preaching, but I'm now trying to use
wxString wherever possible. You can reduce the possibility of memory
leaks substantially, and it is much more convenient to use the overloaded
operators than functions such as strcmp. wxString won't add a significant
overhead to your program; the overhead is compensated for by easier
manipulation (which means less code).

The same goes for other data types: use classes wherever possible.

\section{Strategies for portability}\label{portability}

\subsection{Use relative positioning or constraints}\label{userelativepositioning}

Don't use absolute panel item positioning if you can avoid it. Different GUIs have
very differently sized panel items. Consider using the constraint system, although this
can be complex to program.

Alternatively, you could use alternative .wrc (wxWidgets resource files) on different
platforms, with slightly different dimensions in each. Or space your panel items out
to avoid problems.

\subsection{Use wxWidgets resource files}\label{useresources}

Use .xrc (wxWidgets resource files) where possible, because they can be easily changed
independently of source code.

\section{Strategies for debugging}\label{debugstrategies}

\subsection{Positive thinking}\label{positivethinking}

It is common to blow up the problem in one's imagination, so that it seems to threaten
weeks, months or even years of work. The problem you face may seem insurmountable:
but almost never is. Once you have been programming for some time, you will be able
to remember similar incidents that threw you into the depths of despair. But
remember, you always solved the problem, somehow!

Perseverance is often the key, even though a seemingly trivial problem
can take an apparently inordinate amount of time to solve. In the end,
you will probably wonder why you worried so much. That's not to say it
isn't painful at the time. Try not to worry -- there are many more important
things in life.

\subsection{Simplify the problem}\label{simplifyproblem}

Reduce the code exhibiting the problem to the smallest program possible
that exhibits the problem. If it is not possible to reduce a large and
complex program to a very small program, then try to ensure your code
doesn't hide the problem (you may have attempted to minimize the problem
in some way: but now you want to expose it).

With luck, you can add a small amount of code that causes the program
to go from functioning to non-functioning state. This should give a clue
to the problem. In some cases though, such as memory leaks or wrong
deallocation, this can still give totally spurious results!

\subsection{Use a debugger}\label{usedebugger}

This sounds like facetious advice, but it is surprising how often people
don't use a debugger. Often it is an overhead to install or learn how to
use a debugger, but it really is essential for anything but the most
trivial programs.

\subsection{Use logging functions}\label{uselogging}

There is a variety of logging functions that you can use in your program:
see \helpref{Logging functions}{logfunctions}.

Using tracing statements may be more convenient than using the debugger
in some circumstances (such as when your debugger doesn't support a lot
of debugging code, or you wish to print a bunch of variables).

\subsection{Use the wxWidgets debugging facilities}\label{usedebuggingfacilities}

You can use wxDebugContext to check for
memory leaks and corrupt memory: in fact in debugging mode, wxWidgets will
automatically check for memory leaks at the end of the program if wxWidgets is suitably
configured. Depending on the operating system and compiler, more or less
specific information about the problem will be logged.

You should also use \helpref{debug macros}{debugmacros} as part of a `defensive programming' strategy,
scattering wxASSERTs liberally to test for problems in your code as early as possible. Forward thinking
will save a surprising amount of time in the long run.

See the \helpref{debugging overview}{debuggingoverview} for further information.

⌨️ 快捷键说明

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