source: trunk/PARPG/tools/Writing Editor/ui/popupWindows.py @ 224

Revision 224, 10.0 KB checked in by bretzel_parpg, 10 years ago (diff)

More updates to the help window

Line 
1#!/usr/bin/python
2
3#   This file is part of PARPG.
4
5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
9
10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18from PyQt4 import QtGui, QtCore
19
20class AboutWindow(QtGui.QMainWindow):
21    """
22    The about window
23    """
24    def __init__(self, parent=None):
25        """
26        Initialize the windows
27        """
28        QtGui.QWidget.__init__(self, parent)
29        self.setObjectName("aboutWindow")
30        self.setWindowTitle("About")
31        self.setWindowIcon(QtGui.QIcon("data/images/about.png"))
32        self.resize(225,245)
33        self.central_widget = QtGui.QWidget(self)
34        self.central_widget.setGeometry(QtCore.QRect(0,0,225,245))
35
36        self.info_icon = QtGui.QLabel(self.central_widget)
37        self.info_icon.setPixmap(QtGui.QPixmap("data/images/about_large.png")) 
38        self.info_icon.setGeometry(QtCore.QRect(48,1,128,128))
39
40        self.credits_text = QtGui.QLabel(self.central_widget)
41        ctext = "PARPG Writing Editor written by: Brett Patterson A.K.A Bretzel\n"\
42            "Written using the PyQt4 library\n"\
43            "Copyright 2009"
44        self.credits_text.setText(QtCore.QString(ctext))
45        self.credits_text.setWordWrap(True)
46        self.credits_text.setGeometry(QtCore.QRect(3,65,225,220))
47
48        self.close_button = QtGui.QPushButton(self.central_widget)
49        self.close_button.setText("Close")
50        self.close_button.setGeometry(QtCore.QRect(75,215,65,25))
51
52        QtCore.QObject.connect(self.close_button, QtCore.SIGNAL("pressed()"),
53                               self.close)
54
55class ChangesWindow(QtGui.QMessageBox):
56    """
57    The Save, Cancel, Discard Changes window
58    """
59    def __init__(self, parent=None):
60        """
61        Creates the message box and then returns the button pressed
62        """
63        QtGui.QWidget.__init__(self, parent)
64        self.setText("The document has been modified.")
65        self.setInformativeText("What do you want to do?")
66        self.setStandardButtons(QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
67                                  QtGui.QMessageBox.Cancel)
68        self.setDefaultButton(QtGui.QMessageBox.Save)
69        self.setWindowTitle("Changes have been made")
70        self.setWindowIcon(QtGui.QIcon("data/images/question.png"))
71
72    def run(self):
73        ret = self.exec_()
74        return ret
75       
76class PrintDialog(QtGui.QPrintDialog):
77    """
78    The print dialog
79    """
80    def __init__(self, printer, parent=None):
81        """
82        Creates the printer dialog
83        """
84        QtGui.QWidget.__init__(self, printer, parent)
85
86    def run(self):
87        ret = self.exec_()
88        return ret
89
90class PrefWindow(QtGui.QMainWindow):
91    """
92    The preferences window
93    """
94    def __init__(self, parent, settings):
95        """
96        Initializes the class
97        @type parent: QtGui.QWidget?
98        @param parent: the parent widget
99        @type settings: scripts.settings.Settings
100        @param settings: the settings for the application
101        """
102        QtGui.QWidget.__init__(self, parent)
103       
104        self.parent = parent
105        self.settings = settings
106
107        self.setObjectName("prefWindow")
108        self.setWindowTitle("Preferences")
109        self.setWindowIcon(QtGui.QIcon("data/images/preferences.png"))
110        self.resize(500,475)
111        self.central_widget = QtGui.QWidget(self)
112        self.central_widget.setGeometry(QtCore.QRect(0,0,500,350))
113        self.button_widget = QtGui.QWidget(self)
114        self.button_widget.setGeometry(QtCore.QRect(0,355,500,120))
115
116        self.main_layout = QtGui.QFormLayout()
117
118        self.heading = QtGui.QLabel()
119        self.heading.setText("Editor preferences:\n\n")
120        self.main_layout.addRow(self.heading, None)
121
122        self.res_width_label = QtGui.QLabel()
123        self.res_width_label.setText("Resolution Width:")
124        self.res_width = QtGui.QLineEdit()
125        self.res_width.setMaxLength(4)
126        self.res_width.setMaximumWidth(35)
127        self.res_width.setText(self.settings.res_width)
128        self.main_layout.addRow(self.res_width_label, self.res_width)
129        self.res_height_label = QtGui.QLabel()
130        self.res_height_label.setText("Resolution Height: ")
131        self.res_height = QtGui.QLineEdit()
132        self.res_height.setMaxLength(4)
133        self.res_height.setMaximumWidth(35)
134        self.res_height.setText(self.settings.res_height)
135        self.main_layout.addRow(self.res_height_label, self.res_height)
136
137        self.button_layout = QtGui.QHBoxLayout()
138       
139        self.button_cancel = QtGui.QPushButton()
140        self.button_cancel.setText("Cancel")
141        self.button_layout.addWidget(self.button_cancel)
142        self.button_layout.insertStretch(1)
143        self.button_apply = QtGui.QPushButton()
144        self.button_apply.setText("Apply")
145        self.button_layout.addWidget(self.button_apply)
146        self.button_ok = QtGui.QPushButton()
147        self.button_ok.setText("Ok")
148        self.button_layout.addWidget(self.button_ok)
149        self.button_widget.setLayout(self.button_layout)
150
151        self.central_widget.setLayout(self.main_layout)
152       
153        self.connectSignals()
154
155    def connectSignals(self):
156        """
157        Connect all the widgets to their corresponding signals
158        @return: None
159        """
160        QtCore.QObject.connect(self.button_ok, QtCore.SIGNAL("pressed()"),
161                               lambda: self.okOptions("data/options.txt"))
162        QtCore.QObject.connect(self.button_apply, QtCore.SIGNAL("pressed()"),
163                               lambda: self.applyOptions("data/options.txt"))
164        QtCore.QObject.connect(self.button_cancel, QtCore.SIGNAL("pressed()"),
165                               self.close)
166       
167
168    def applyOptions(self, options_file):
169        """
170        Apply the current options
171        @type options_file: string
172        @param options_file: the file to write to
173        @return: None
174        """
175        self.settings.res_width = self.res_width.text()
176        self.settings.res_height = self.res_height.text()
177   
178        self.settings.writeSettingsToFile(options_file)
179        self.button_apply.setEnabled(False)
180
181        self.parent.resize(int(self.settings.res_width),int(self.settings.res_height))
182
183    def okOptions(self, options_file):
184        """
185        Apply the current options then close the window
186        @type options_file: string
187        @param options_file: the file to write to
188        @return: None
189        """
190        self.applyOptions(options_file)
191        self.close()
192
193class HelpWindow(QtGui.QMainWindow):
194    """
195    The help window
196    """
197    def __init__(self, help_type, settings, parent=None):
198        """
199        @type help_type: string
200        @param help_type: whether the window should be for help with the editor or scripting
201                          can be either "editor" or "scripting"
202        @type settings: settings.Settings
203        @param settings: The editor's settings
204        @return: None
205        """
206        QtGui.QWidget.__init__(self, parent)
207        self.settings = settings
208
209        if (help_type == "editor"):
210            self.setWindowTitle("Help with the Editor")
211
212        elif (help_type == "scripting"):
213            self.setWindowTitle("Help with Scripting")
214
215        else:
216            print "Invalid argument for help_type. Should be either \"editor\" or \"scripting\""
217
218        width = int(self.settings.res_width)
219        height = int(self.settings.res_height)
220        self.resize(width, height)
221        self.setWindowIcon(QtGui.QIcon("data/images/help.png"))
222
223        self.central_widget = QtGui.QWidget(self)
224        self.central_widget.setGeometry(QtCore.QRect(0,0,width-10,height-50))
225
226        self.main_layout = QtGui.QHBoxLayout()
227
228        self.search_pane = QtGui.QWidget()
229        self.search_pane.setMaximumWidth(175)   
230        self.search_layout = QtGui.QVBoxLayout()
231        self.search_label = QtGui.QLabel()
232        self.search_label.setText("Search:")
233        self.search_layout.addWidget(self.search_label)
234
235        self.search_bar_layout = QtGui.QHBoxLayout()
236        self.search_bar = QtGui.QLineEdit()
237        self.search_bar.setMaximumWidth(120)
238        self.search_bar_layout.addWidget(self.search_bar)
239        self.go_button = QtGui.QPushButton()
240        self.go_button.setText("Go")
241        self.go_button.setMaximumWidth(30)
242        self.search_bar_layout.addWidget(self.go_button)
243        self.search_layout.addLayout(self.search_bar_layout)
244        self.search_layout.insertStretch(2)
245
246        self.search_view = QtGui.QListView()
247        self.search_view.setMinimumHeight(height-150)
248        self.search_view.setMinimumWidth(self.search_pane.width())
249        self.search_layout.addWidget(self.search_view)
250        self.search_pane.setLayout(self.search_layout)
251        self.main_layout.addWidget(self.search_pane)
252
253        self.main_help_window = QtGui.QTextEdit()
254        self.main_layout.addWidget(self.main_help_window)
255
256        self.central_widget.setLayout(self.main_layout)       
257       
258        self.connectSignals()
259
260    def connectSignals(self):
261        """
262        Connect all the widgets to their respective functions
263        @return: None
264        """
265        QtCore.QObject.connect(self.search_bar, QtCore.SIGNAL("returnPressed()"),
266                               self.search)
267        QtCore.QObject.connect(self.go_button, QtCore.SIGNAL("pressed()"),
268                               self.search)
269       
270    def search(self):
271        """
272        Search through the documentation for the contents of self.search_bar
273        @return: None
274        """
275        self.search_text = self.search_bar.text()
Note: See TracBrowser for help on using the repository browser.