c5288.htm

来自「GUI Programming with Python」· HTM 代码 · 共 327 行

HTM
327
字号
<HTML><HEAD><TITLE>A More Complex Framework: Multiple Documents, Multiple    Views</TITLE><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.72"><LINKREL="HOME"TITLE="GUI Programming with Python: QT Edition"HREF="book1.htm"><LINKREL="UP"TITLE="Creating real applications with PyQt"HREF="p4627.htm"><LINKREL="PREVIOUS"TITLE="Conclusion"HREF="x5285.htm"><LINKREL="NEXT"TITLE="Document/View Manager"HREF="x5339.htm"></HEAD><BODYCLASS="CHAPTER"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">GUI Programming with Python: QT Edition</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="x5285.htm"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="x5339.htm"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="CHAPTER"><H1><ANAME="CH10">Chapter 15. A More Complex Framework: Multiple Documents, Multiple    Views</A></H1><DIVCLASS="TOC"><DL><DT><B>Table of Contents</B></DT><DT><AHREF="c5288.htm#AEN5290">Introduction</A></DT><DT><AHREF="x5339.htm">Document/View Manager</A></DT><DT><AHREF="x5388.htm">The Document Manager</A></DT><DT><AHREF="x5451.htm">Document</A></DT><DT><AHREF="x5458.htm">View</A></DT><DT><AHREF="x5469.htm">The actual application</A></DT><DT><AHREF="x5581.htm">Conclusion</A></DT></DL></DIV><DIVCLASS="SECT1"><H1CLASS="SECT1"><ANAME="AEN5290">Introduction</A></H1><P>In <AHREF="c4631.htm">Chapter 12</A> we saw a fairly      simple framework. The document-view framework allowed one      document and one view on that document. In this chapter we will      explore more complex configurations.</P><P>In this chapter, we will go full tilt      immediately, with a framework that supports multiple documents,      and with more than one view on those documents. Of course, this      means that you have to keep track of which view shows which      document. If a document changes, all its views must be updated.      If the last view on a document is closed, then the document must      be closed. Getting these features right demands quite complex      code.</P><P>And this is only the conceptual framework.      The actual GUI interface is interesting too. There are two or      three schools in multiple-document interface design: MDI, MTW,      and MTI.</P><P>These are cryptic acronyms, but the      differences are easy to understand. MDI stands for Multiple      Document Interface. This is an interface in which you have      several windows inside a an application workspace (which is a      window on the desktop). It was invented by Microsoft, who      recently tried to bury it. Some users found it rather confusing.      However, other users clamored for its return, and Microsoft      appears to have appeased their wishes, and reinstated the MDI      paradigm in full. As found in most programming environments, in      the MDI paradigm there may be both dockable windows that snap to      the sides of the main window, and free-floating windows. PyQt      supports this way of working with the      <TTCLASS="CLASSNAME">QWorkSpace</TT> class. It's a pity that in      PyQt 2 dockable windows are not supported &#8212; for that you      need to use <TTCLASS="CLASSNAME">QDockWindow</TT> in PyQt 3.</P><DIVCLASS="MEDIAOBJECT"><P><DIVCLASS="CAPTION"><P>An MDI workspace</P></DIV></P></DIV><P>MTW stands for Multiple Toplevel Window.      This is more in favor with the Unix/X11 crowd. Here, an      application litters the entire desktop with various windows:      document windows, floating toolbars, dialog windows &#8212;      everything. This, too, can be enormously confusing. It works for      X11 because most users are sophisticated and have access to a      system with multiple desktops. Early versions of Visual Basic      also used this strategy, and even now, you can select it as an      option.</P><P>You can create as many      <TTCLASS="CLASSNAME">QMainWindow</TT> objects in PyQt as you wish,      so this style is not a problem at all.</P><DIVCLASS="MEDIAOBJECT"><P><DIVCLASS="CAPTION"><P>The Gimp littering my desktop</P></DIV></P></DIV><P>Finally, there is the style made popular by      IDE's such as JBuilder. Here, you have your documents in one      window, but with a row of tabs that you can use to switch      between windows (these tabs are located on the top, bottom or      side of the window). There is a legitimate complaint against      this style, too: you cannot compare two documents side by side.      This style is often used by what I refer to as &#8216;iso-standard'      IDE's: Visual Studio like environments, with a project pane,      output pane, and at the top-right corner a stack of tabbed      editor windows. BlackAdder conforms, too &#8212;      except that every project is an MDI-window.</P><DIVCLASS="MEDIAOBJECT"><P><DIVCLASS="CAPTION"><P>KDevelop &#8212; the epitome of          an interface with tabs.</P></DIV></P></DIV><P>I have chosen to disregard the more exotic      styles of multiple-document interfaces.  There are many      varieties of these, such as vi's, in which you have a set of      documents you can visit one after another (but not go back) and      Emacs, which gives you a set of buffers that may or may not be      presented in another window or another frame (where window and      frame are the exact opposite of what you'd expect). These      oddities should remain just that &#8212; oddities.</P><P>As an aside, it is interesting to note      that all these styles originated with programming environments.      It is often the case that a programming environment influences      the developer in his interface decisions &#8212; and this might      very well fail to support the needs of the user...</P><P>In this chapter, we first develop a      document/view manager that can be used to manage a situation in      which you have more than one document with more than one view.      It will also handle keeping track of modifications to the      documents, saving, saving under a new filename, and closing      documents without saving. This is quite complex enough for now;      in the next chapter, we will investigate the addition of      switchable interface styles. After that we will have, at last, a      framework that we can add a real application to.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="x5285.htm"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="book1.htm"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="x5339.htm"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Conclusion</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="p4627.htm"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Document/View Manager</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

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