BT source code learning experience (9): client source code analysis (Graphic Interface Analysis)

Source: Internet
Author: User
Tags gtk

BT source code learning experience (9): client source code analysis (Graphic Interface Analysis)
Author: Wolfenstein

The client will start from btdownloadgui. py for analysis, so that you can take a look at the GUI programming in Python. The GUI programming in Python also has a lot of content, so it is impossible to analyze it in depth. Just take the source code of Bt as an example.
In btdownloadgui. py, GTK is used as the development library for its graphic interface. This library provides a wide range of classes that can be used to create various widgets required in the graphic interface. In the initialization process of the main window class downloadinfoframe, the main task of a program is to create various widgets used in the window and add them to the form. Then use the connect function to connect events that may occur on a widget to a processing function. In this way, a GUI is created. For specific procedures, refer to the instructions for each class in GTK, which is not difficult.
Here we will briefly introduce other classes in btdownloadgui. py. They are usually the seed windows in the GUI, and need to pop up after a button or menu is selected. We can also see some clever design of the author's Gui.
Validator: A class inherited from a basic entry, but it can be used to judge the value entered by the user. Only the input that appears in the valid Character List is valid. Besides, this class inherits ipvalidator, portvalidator, percentvalidator, and minutesvalidator to verify various input data.
Ratesliderbox: this is a slide block indicating the speed. You can adjust the speed and network connection type based on the mouse. The slider position and corresponding rate are converted internally.
Stopstartbutton: Click the stop/start button to temporarily stop or resume download of all seeds.
Versionwindow (display version information), aboutwindow (display information), logwindow (display log), settingswindow (set some parameters), filelistwindow (File List window ), peerlistwindow (peer-to-peer client list window) and torw.infowindow (seed file information window) are all subwindows that will pop up when the corresponding functions are called. logwindow uses the content in logbuffer, that is, the log_text function of logbuffer is called wherever logs need to be recorded, and then logwindows can display them all.
Torrentbox is a base class represented by a downloading task on the graphic interface. It defines GUI elements such as name identifiers, status icons, progress bars, and so on. All download tasks use this class as the base class. Knowntorrentbox is a graphical interface that is no longer in the download task list. You can drag it to the download queue to continue downloading these tasks, if you drag a completed task to the download queue, the task continues to run. If you drag a failed task to the download queue, the task resumes download. Droppabletorrentbox is a class that adds the drag object processing function. Classes using droppabletorrentbox as the base class include queuedtorrentbox and pausedtorrentbox.
Runningtorrentbox corresponds to the download task, paused task, and running task in the queue respectively. Projects in the knowntorrentbox area can be dragged to the download queue. In addition, projects in queuedtorrentbox and pausedtorrentbox can be dragged freely to meet the queue management requirements for download tasks. It should also be mentioned that runningtorrentbox and pausedtorutbox cannot appear at the same time. It is managed by stopstartbutton mentioned at the beginning, that is, to pause/run all tasks.
Queuedtorrentbox is a type of task that cannot be downloaded for the moment due to the number of simultaneous download tasks. Even if stopstartbutton is in the running state, it will not be run, only after a download task is completed or aborted, the system selects one from the queue to enter the running queue.
The above are the widgets corresponding to each specific running project. The following shows their containers. hseparatedbox is the base class of a container, which is defined in BitTorrent/GUI. in py, this module also defines other functions and objects that are convenient for GUI display. In hseparatedbox, you can add several subwindows and rearrange them. In addition, it can use split lines to separate the added subwindows. Droppablebox is a subclass of hseparatedbox. It is added to handle drag objects and knownbox is a subclass of droppablebox. It will be filled in several knowntorrentboxes, corresponding to runningbox and queuedbox, fill in the corresponding download task widgets (note that pausedtorrentbox and runningtorrentbox cannot appear at the same time, they are all placed in the container runningbox), while runningandqueuebox is a container that simultaneously loads runningtorrentbox and ueuedbox.
In the system, each torrentbox only saves the information of a specific seed for display. When necessary, these widgets are deleted, created, or rearranged at any time, the statistical information of these seeds changes with the running time and is displayed through these widgets.
The BitTorrent/torrentqueue. py module completes the connection from the GUI to the actual downloading task module. It implements the feedback interface, so that when a downloading task of a seed changes (such as completion or error), it can be notified in time and displayed on the GUI. By analyzing other BT download programs (I .e. non-graphic download programs, such as btdownloadheadless. PY), you can also see that there is a class that inherits the feedback interface, but its implementation method is usually in the form of text to show the seed changes. In addition, the torrentqueue module can restore the last download (read some state files), through the analysis of all download programs (graphic interface or text
We can consider that the object actually executing the download task is the multitorrent object in BitTorrent/download. py. The torrentqueue code is still included in the GUI. By analyzing its code, we know that it has read the information in the corresponding seed file and processed it.
Since we mainly want to analyze the actual functional code of the BT client, the GUI part can only be briefly described, in fact, you can view the source code of the relevant graphic interface program (btdownloadgui. PY, btmaketorrentgui. PY. Next time, you can analyze the multitorrent in BitTorrent/download. py and go straight to the topic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.