We bind a wx. This way we show a rename dialog if we double click on a specific element in the listbox. We call the NewItem method by clicking on the New button. This method shows a wx. TextEntryDialog using the wrapper wx.
GetTextFromUser method. The text that we enter is returned to the text variable. If the text is not empty, we append it to the listbox with the Append method. We rename an item by deleting it and inserting a new item at the same position. We also set the selection back to the modified item. To delete an item, we find the index of the selected item by calling the GetSelection method.
Then we delete the item with the Delete method. The parameter to the Delete method is the selected index. The easiest thing is to clear the whole listbox. We simply call the Clear method. The wx. It is not a full-fledged browser. We can do some interesting things with wx. HtmlWindow widget. HtmlWindow is created. We can use wx. HtmlWindow to provide help in our application. We can create a standalone window or we can create a window that is going to be a part of the application.
The following script will create a help window using the latter idea. The help window is hidden in the beginning. We can show it by clicking on the Help button on the toolbar or by pressing F1. The help window appears on the right side of the application.
To hide the help window, we click on the Close button. We create left a right panels and split them vertically. After that, we call the Unsplit method. By default the method hides the right or bottom panes. We divide the right panel into two parts. The header and the body of the panel. The header is an adjusted wx. The header consists of a static text and a bitmap button.
We put wx. Window into the body of the panel. The bitmap button style is set to wx. The background colour is set to the colour of the header panel. This is done in order to make the button appear as a part of the header. We create a wx.
HtmlWindow widget on the right panel. We have our HTML code in a separate file. We set focus on the left panel. We can launch the help window with the F1 key. In order to control a window with a keyboard, it must have the focus.
If we did not set the focus, we would have to first click on the panel and only then we could launch the help window with the F1 key press. To show the help window, we call the OnHelp method. It splits the two panels vertically. We must not forget to set the focus again, because the initial focus is lost by splitting. ListCtrl is a graphical representation of a list of items. ListBox can only have one column. ListCtrl can have more than one column. ListCtrl is a very common and useful widget.
For example a file manager uses a wx. ListCtrl to display directories and files on the file system. A cd burner application displays files to be burned inside a wx. ListCtrl can be used in three different formats. In a list view, report view or a icon view. These formats are controled by the wx.
This is Advanced wxPython e-book. This e-book is a tutorial, which covers several interesting parts of the library. The first chapter presents the Cairo graphics library. We work with colours, shapes, and gradients. Reflection, star animation, aliens example are among other code examples. Layout management is considered to be one of the most difficult areas of GUI programming. Writers usually only skim the topic, covering the very basics of it. Based on my experience while writing a complete e-book dedicated to layout management, this chapter was a piece of cake.
Once you know the principles behind the process, you can utilize them in other GUI toolkits too. The third chapter is dedicated to images. In this chapter, we show how to scale or crop the image, create a grayscale image, a watermark, or create an application which takes a screenshot.
In the fourth chapter, we show how to create three custom widgets: a ProgressMeter widget, a Thermometer widget and a ColourWheel widget. The fifth chapter covers advanced widgets; we have plenty of examples covering the wx. TextCtrl , wx. ListCtrl , wx. TreeCtrl , wx. Grid , and the wx.
0コメント