The quickest way to build wxWidgets GUIs
标签: DialogBlocks, wxWidgets
+++++仿佛轻云应笑我--相携水岸弄朝霞--此生只为听天籁--坐拥书城看落花+++++
标签: DialogBlocks, wxWidgets
class MyTaskBarIcon(wx.TaskBarIcon):
...
##
# The task bar application
#
class TaskBarApp(wx.Frame):
##
# \brief the constructor
#
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title, size = (1, 1),
style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)
self.tbicon = MyTaskBarIcon(self)




标签: wxFormBuilder, wxGlade, wxWidgets
wxPython介绍+一个实用的例子
1. wxPython简介
wxPython是wxWidget的库的一个python的封装。提供了一些库和一些工具。
这样wxPython即有python语言的优点:
语法强悍,少写了不少代码:)
也有wxWidget图形库的优点:
直接拉控件到大概位置就行了,不需要去调整控件的对齐,也不需要关心gui界面是否支持各种分辨率的桌面。而且界面都是可以运行时切换,只要写很少的切换代码。跨平台的图形库...
后悔,我怎么以前会用vb开发gui的 -_-!。
缺点,网上资料还比较少。而且在线文档都是英文的。不过如果英文好的话,到真的无所谓,因为wxPython的安装包本身提供的工具和资料也足够多,足够好了。
2. 开发入门
我使用ultraedit作为编辑器,wxPython自带的XRCed作为编辑xrc文件(一种xml格式的资源文件,类似于VC6中的RC文件)。
文档主要参考wxPython自带的在线文档和demo代码。不过关于如何使用xrc文件设计gui,wxPython自带的资料似乎还不够详细,这也是我写本文的原因。
通常情况下google"cvs def wxpython相关的关键字"可以快速找到开源的源代码参考。
如果这些例子还不够的话,就参考我的程序吧,这是一个商用程序的原型,我相信该程序的内容已经足够丰富了,应该比网上的一些wxPython教程中的hello world程序更有借鉴意义。
3. 源代码
两个文件,main.py是主程序,main.xrc是资源文件。只要安装了了python和wxpython,然后将这两个文件放在同一个目录中,运行main.py就可以了。
http://www.builder.com.cn/2008/0527/887121.shtml
很重要,此文的实现基于.xrc文件。
注:转载请注明出处
一、下载 Python 2.5.1
这一步是必须做的,下载 Python 语言的 SDK
下载地址(直接复制到迅雷):点击下载
下载完成后安装 Python 2.5.1,注意安装路径中不要有空格,不然会引起一些问题。
二、下载 wxPython 2.8
这将下载 Python 的可视化开发库,拥有它就可以进行可视化的开发了。
下载地址:
建议下载 Unicode 的,用 Ansi 版的话,组件标题不能写 Unicode 字符,代码包含 Unicode 字符也会出错。安装时注意,安装路径中不能有空格。
到这一步为止,类库就齐全了,下面我们需要一个 IDE
三、下载 Boa Constructor
Python 拥有非常多的开发环境,也就是 IDE。但是到现在为止,能完全支持可视开发的只有 Boa Constructor。使用它可以像使用 Delphi 那样,直接拖出控件进行快速的开发。
下载地址:点击下载
Boa Constructor 还是开源的,如果需要它的源码,可以点击下载。
注意,Boa Constructor 的安装路径也不能有空格。
四、配置 Boa Constructor
打开 Boa Constructor,如果你是中文的系统,IDE 的语言会变成中文,你必须把它修改成英文的,在 工具->语言设置 菜单中将它换成英文。如果使用中文的 IDE,打开,保存文件时会发生错误(感谢纳米Baby提供这一信息,我自己的系统是英文的,试不出此问题)。
点击 Tools->Python Interpreter Chooser,设置 Python.exe 的所在目录。
关闭 Boa Constructor并重新启动它,配置即告完成。
五、一个简单的 Hello World 实例
在工具栏中点击 wx.App 按钮,创建一个 wx 工程,这个工程将生成 2 个文件,一个是工程文件,另一个是窗体文件。

然后将两个文件分别保存为 HelloWorld.py(工程文件) 和 Form.py(窗体文件)。在 Form.py 的显示窗口下按 F12,调出可视设计器。

如上图所示,拖入一个 TextCtrl 和一个 Button。设置 TextCtrl 的 Name 为 txtHello,Value 为空。设置 Button 的 Name 为 btnHello,Label 为 Hello。
然后我们要让 Button 按下时,TextCtrl 显示出 Hello World 字样。所以需要绑定 Button 的 OnButton 事件。在事件管理器中找到 OnButton,然后双击,点击 Apply 按钮。此时代码编辑器中会生成该事件相关的代码。

如图所示,添加一行代码即可。然后运行程序,就能看到效果了。
TinyXML 是一個小巧的 C++ XML parser Library,十分容易就可以整合到你的程式,而且學習曲線十分的短。
TinyXML 使用 TiXmlDocument 這個 class 來載入/儲存 xml file。A document binds together all the XML pieces. It can be saved, loaded, and printed to the screen.
TiXmlDocument doc;doc.Load( "myfile.xml" );
存取的時候,要先取得下一層的 Child Element:
TiXmlElement* element = doc.FirstChildElement();
也可以指定標籤來取得特定的 Element,如同下面的例子:
TiXmlElement* element = doc.FirstChildElement("Node");
例如上面的片斷,我們可以使用 GetText() 取得被包起來的文字:<foo>This is textfoo>
const char* str = fooElement->GetText();
TinyXML 預設以 UTF-8 編碼,wxWidgets 編譯成 Unicode mode 時,傳入的參數需要轉碼,wxString 可以使用 mb_str() 轉碼,就可以與 TinyXML一起使用。
如果要轉換 UTF-8 char * 字串為 wxString,使用下列的方式:
http://www.cppblog.com/tx7do/archive/2006/04/24/6153.htmlconst char* str = fooElement->GetText();wxString myString(str, wxConvUTF8);
标签: wxWidgets
wxWidgets formerly known as wxWindows is a framework for developing cross-platform GUI applications in C++. Julian Smart started the framework in 1992 at the Artificial Intelligence Applications Institute, University of Edinburgh. In 1995, a port to Xt was released by Markus Holzem. In May 1997, the Windows and the GTK+ ports were merged and put into a CVS repository.
wxWidgets gives you a single, easy-to-use API for writing GUI applications on multiple platforms. Link it with the appropriate library for your platform (Windows/Unix/Mac) and compiler (almost any popular C++ compiler), and your application will adopt the look and feel appropriate to that platform. On top of the great GUI functionality, wxWindows gives you: online help, network programming, streams, clipboard and drag and drop, multithreading, image loading and saving in a variety of popular formats, database support, HTML viewing and printing, and much more.
wxWidgets is a framework very much similar to MFC, except for a few negative points of its own. Those MFC programmers who are aware of the growing number of Linux users and who want to write cross platform GUI applications can use wxWidgets. With wxWidgets, it is very easy to use a framework based on C++ and it has a proven record of 13 years. In fact, wxWidgets is very stable and is supported on:
Currently several major databases, along with other widely used databases, have been tested and supported through the wxODBC classes. The list of supported databases is certain to grow as more users start implementing software with these classes, but at the time of the writing of this document, users have successfully used the classes with the following datasources:
An up-to-date list can be obtained by looking in the comments of the function wxDb::Dbms in db.cpp, or in the enumerated type wxDBMS in db.h.
**dBase is not truly an ODBC datasource, but there are drivers which can emulate much of the functionality of an ODBC connection to a dBase table. See the wxODBC Known Issues section of this overview for details.
http://docs.wxwidgets.org/2.8.0/wx_odbcoverview.html#wxodbcconfiguringyoursystem
One of the failings of C++ used to be that no run-time information was provided about a class and its position in the inheritance hierarchy. Another, which still persists, is that instances of a class cannot be created just by knowing the name of a class, which makes facilities such as persistent storage hard to implement.
Most C++ GUI frameworks overcome these limitations by means of a set of macros and functions and wxWidgets is no exception. As it originated before the addition of RTTI to the C++ standard and as support for it is still missing from some (albeit old) compilers, wxWidgets doesn't (yet) use it, but provides its own macro-based RTTI system.
In the future, the standard C++ RTTI will be used though and you're encouraged to use whenever possible the wxDynamicCast() macro which, for the implementations that support it, is defined just as dynamic_cast<> and uses wxWidgets RTTI for all the others. This macro is limited to wxWidgets classes only and only works with pointers (unlike the real dynamic_cast<> which also accepts references).
Each class that you wish to be known to the type system should have a macro such as DECLARE_DYNAMIC_CLASS just inside the class declaration. The macro IMPLEMENT_DYNAMIC_CLASS should be in the implementation file. Note that these are entirely optional; use them if you wish to check object types, or create instances of classes using the class name. However, it is good to get into the habit of adding these macros for all classes.
Variations on these macros are used for multiple inheritance, and abstract classes that cannot be instantiated dynamically or otherwise.
DECLARE_DYNAMIC_CLASS inserts a static wxClassInfo declaration into the class, initialized by IMPLEMENT_DYNAMIC_CLASS. When initialized, the wxClassInfo object inserts itself into a linked list (accessed through wxClassInfo::first and wxClassInfo::next pointers). The linked list is fully created by the time all global initialisation is done.
IMPLEMENT_DYNAMIC_CLASS is a macro that not only initialises the static wxClassInfo member, but defines a global function capable of creating a dynamic object of the class in question. A pointer to this function is stored in wxClassInfo, and is used when an object should be created dynamically.
wxObject::IsKindOf uses the linked list of wxClassInfo. It takes a wxClassInfo argument, so use CLASSINFO(className) to return an appropriate wxClassInfo pointer to use in this function.
The function wxCreateDynamicObject can be used to construct a new object of a given type, by supplying a string name. If you have a pointer to the wxClassInfo object instead, then you can simply call wxClassInfo::CreateObject.
http://docs.wxwidgets.org/stable/wx_runtimeclassoverview.html
The biggest feature is that it is a piece of cake to work with an in memory XML Document from your C++ code. Instead of having to write specialized C++ classes/structures to represent your xml, you can simply use the iDOMDocument as-is. You can think of the XML4WX DOM as a giant Hash table that also has a stateless search and reporting engines built in.
Other XML DOMS (xmllib2, Xerces, MS XML) require you to write large ammounts of C++ code to access the data. If your xml changes, you'll have to re-write the container classes and re-compile your application. With XML4WX, if you write your XPath queries carefully, your C++ code will continue to work.
标签: wxWidgets
|
|
|
|
上面就是程序的总体框架了,程序就是从这里开始执行的,下面时程序的窗体部分:
|
|
|
|
上面部分就是主窗体,主要包含了菜单,状态栏,编辑框等控件,还包含了事件响应部分,感觉这部分有点像MFC的处理方式。
代码很少(代码是看例子写的),也很简洁,就不用说明了吧(上面还不够详细?)有问题请留言。
标签: wxWidgets
标签: C/C++, Code::Blocks, wxWidgets