source: branches/active/character_customization/tools/writing_editor/ui/popupWindows.py @ 736

Revision 736, 9.8 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

  • renamed scripts package to parpg
  • renamed parpg module to application
  • removed packaging and other related files (kept locally for reference, will reintroduce similar scripts to resolve bug #275
  • updated all import statements to respect changes above
Line 
1#!/usr/bin/env 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
19from parpg.syntaxHighlight import SyntaxHighlighter
20
21class AboutWindow(QtGui.QMainWindow):
22    """
23    The about window
24    """
25    def __init__(self, parent=None):
26        """
27        Initialize the windows
28        """
29        QtGui.QWidget.__init__(self, parent)
30        self.setObjectName("aboutWindow")
31        self.setWindowTitle("About")
32        self.setWindowIcon(QtGui.QIcon("data/images/about.png"))
33        self.resize(225,245)
34        self.central_widget = QtGui.QWidget(self)
35        self.central_widget.setGeometry(QtCore.QRect(0,0,225,245))
36
37        self.info_icon = QtGui.QLabel(self.central_widget)
38        self.info_icon.setPixmap(QtGui.QPixmap("data/images/about_large.png")) 
39        self.info_icon.setGeometry(QtCore.QRect(48,1,128,128))
40
41        self.credits_text = QtGui.QLabel(self.central_widget)
42        ctext = "PARPG Writing Editor written by:\nBrett Patterson A.K.A Bretzel\n"\
43            "Written using the PyQt4 library\n"\
44            "Copyright 2009"
45        self.credits_text.setText(QtCore.QString(ctext))
46        self.credits_text.setWordWrap(True)
47        self.credits_text.setGeometry(QtCore.QRect(3,65,225,220))
48
49        self.close_button = QtGui.QPushButton(self.central_widget)
50        self.close_button.setText("Close")
51        self.close_button.setGeometry(QtCore.QRect(75,215,65,25))
52
53        QtCore.QObject.connect(self.close_button, QtCore.SIGNAL("pressed()"),
54                               self.close)
55
56class ChangesWindow(QtGui.QMessageBox):
57    """
58    The Save, Cancel, Discard Changes window
59    """
60    def __init__(self, parent=None):
61        """
62        Creates the message box and then returns the button pressed
63        """
64        QtGui.QWidget.__init__(self, parent)
65        self.setText("The document has been modified.")
66        self.setInformativeText("What do you want to do?")
67        self.setStandardButtons(QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
68                                  QtGui.QMessageBox.Cancel)
69        self.setDefaultButton(QtGui.QMessageBox.Save)
70        self.setWindowTitle("Changes have been made")
71        self.setWindowIcon(QtGui.QIcon("data/images/question.png"))
72
73    def run(self):
74        ret = self.exec_()
75        return ret
76       
77class PrintDialog(QtGui.QPrintDialog):
78    """
79    The print dialog
80    """
81    def __init__(self, printer, parent=None):
82        """
83        Creates the printer dialog
84        """
85        QtGui.QWidget.__init__(self, printer, parent)
86
87    def run(self):
88        ret = self.exec_()
89        return ret
90
91class PrefWindow(QtGui.QMainWindow):
92    """
93    The preferences window
94    """
95    def __init__(self, parent, settings):
96        """
97        Initializes the class
98        @type parent: QtGui.QWidget?
99        @param parent: the parent widget
100        @type settings: parpg.settings.Settings
101        @param settings: the settings for the application
102        """
103        QtGui.QWidget.__init__(self, parent)
104       
105        self.parent = parent
106        self.settings = settings
107
108        self.setObjectName("prefWindow")
109        self.setWindowTitle("Preferences")
110        self.setWindowIcon(QtGui.QIcon("data/images/preferences.png"))
111        self.resize(500,475)
112        self.central_widget = QtGui.QWidget(self)
113        self.central_widget.setGeometry(QtCore.QRect(0,0,500,350))
114        self.button_widget = QtGui.QWidget(self)
115        self.button_widget.setGeometry(QtCore.QRect(0,355,500,120))
116
117        self.main_layout = QtGui.QFormLayout()
118
119        self.heading = QtGui.QLabel()
120        self.heading.setText("Editor preferences:\n\n")
121        self.main_layout.addRow(self.heading, None)
122
123        self.res_width_label = QtGui.QLabel()
124        self.res_width_label.setText("Resolution Width:")
125        self.res_width = QtGui.QLineEdit()
126        self.res_width.setMaxLength(4)
127        self.res_width.setMaximumWidth(35)
128        self.res_width.setText(self.settings.res_width)
129        self.main_layout.addRow(self.res_width_label, self.res_width)
130        self.res_height_label = QtGui.QLabel()
131        self.res_height_label.setText("Resolution Height: ")
132        self.res_height = QtGui.QLineEdit()
133        self.res_height.setMaxLength(4)
134        self.res_height.setMaximumWidth(35)
135        self.res_height.setText(self.settings.res_height)
136        self.main_layout.addRow(self.res_height_label, self.res_height)
137
138        self.button_layout = QtGui.QHBoxLayout()
139       
140        self.button_cancel = QtGui.QPushButton()
141        self.button_cancel.setText("Cancel")
142        self.button_layout.addWidget(self.button_cancel)
143        self.button_layout.insertStretch(1)
144        self.button_apply = QtGui.QPushButton()
145        self.button_apply.setText("Apply")
146        self.button_layout.addWidget(self.button_apply)
147        self.button_ok = QtGui.QPushButton()
148        self.button_ok.setText("Ok")
149        self.button_layout.addWidget(self.button_ok)
150        self.button_widget.setLayout(self.button_layout)
151
152        self.central_widget.setLayout(self.main_layout)
153       
154        self.connectSignals()
155
156    def connectSignals(self):
157        """
158        Connect all the widgets to their corresponding signals
159        @return: None
160        """
161        QtCore.QObject.connect(self.button_ok, QtCore.SIGNAL("pressed()"),
162                               lambda: self.okOptions("data/options.txt"))
163        QtCore.QObject.connect(self.button_apply, QtCore.SIGNAL("pressed()"),
164                               lambda: self.applyOptions("data/options.txt"))
165        QtCore.QObject.connect(self.button_cancel, QtCore.SIGNAL("pressed()"),
166                               self.close)
167       
168
169    def applyOptions(self, options_file):
170        """
171        Apply the current options
172        @type options_file: string
173        @param options_file: the file to write to
174        @return: None
175        """
176        self.settings.res_width = self.res_width.text()
177        self.settings.res_height = self.res_height.text()
178   
179        self.settings.writeSettingsToFile(options_file)
180        self.button_apply.setEnabled(False)
181
182        self.parent.resize(int(self.settings.res_width),int(self.settings.res_height))
183
184    def okOptions(self, options_file):
185        """
186        Apply the current options then close the window
187        @type options_file: string
188        @param options_file: the file to write to
189        @return: None
190        """
191        self.applyOptions(options_file)
192        self.close()
193
194class HelpWindow(QtGui.QMainWindow):
195    """
196    The help window
197    """
198    def __init__(self, settings, parent=None):
199        """
200        @type settings: settings.Settings
201        @param settings: The editor's settings
202        @return: None
203        """
204        QtGui.QWidget.__init__(self, parent)
205        self.settings = settings
206
207        self.setWindowTitle("Help")
208
209        width = int(self.settings.res_width)
210        height = int(self.settings.res_height)
211        self.resize(width, height)
212        self.setWindowIcon(QtGui.QIcon("data/images/help.png"))
213
214        self.file_names = {"Home":"docs/html/index.html",
215                           "Scripting":"docs/html/scripting.html",
216                           "Dialog Example":"docs/html/example.html"}
217
218        self.central_widget = QtGui.QWidget(self)
219        self.central_widget.setGeometry(QtCore.QRect(0,0,width-10,height-50))
220
221        self.main_layout = QtGui.QHBoxLayout()
222
223        self.list_pane = QtGui.QWidget()
224        self.list_pane.setMaximumWidth(175)   
225        self.list_layout = QtGui.QVBoxLayout()
226
227        self.list_label = QtGui.QLabel()
228        self.list_label.setText("Topics:")
229        self.list_layout.addWidget(self.list_label)
230
231        self.list = QtGui.QStandardItemModel()
232        self.list.appendRow([QtGui.QStandardItem("Home")])
233        self.list.appendRow([QtGui.QStandardItem("Scripting")])
234        self.list.appendRow([QtGui.QStandardItem("Dialog Example")])
235
236        self.list_view = QtGui.QListView()
237        self.list_view.setMinimumHeight(height-150)
238        self.list_view.setMinimumWidth(self.list_pane.width())
239        self.list_view.setModel(self.list)
240        self.list_view.setEditTriggers(self.list_view.NoEditTriggers)
241        self.list_layout.addWidget(self.list_view)
242        self.list_pane.setLayout(self.list_layout)
243        self.main_layout.addWidget(self.list_pane)
244
245        self.main_help_window = QtGui.QTextBrowser()
246        self.main_help_window.setHtml(open("docs/html/index.html", 'r').read())
247        self.main_layout.addWidget(self.main_help_window)
248
249        self.central_widget.setLayout(self.main_layout)       
250        self.syntax = SyntaxHighlighter(self.main_help_window)
251        self.connectSignals()
252       
253    def openFile(self, index):
254        """
255        Open the html file according to its index in the list
256        @type index: int
257        @param index: the index in self.list_view
258        @return: None
259        """
260        page_name = index.data().toString()
261        file_name = self.file_names[str(page_name)]
262        self.main_help_window.setHtml(open(file_name, 'r').read())
263       
264
265    def connectSignals(self):
266        """
267        Connect all the widgets to their respective functions
268        @return: None
269        """
270        QtCore.QObject.connect(self.list_view, QtCore.SIGNAL("clicked(QModelIndex)"),
271                               self.openFile)
Note: See TracBrowser for help on using the repository browser.