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

Revision 217, 6.6 KB checked in by bretzel_parpg, 10 years ago (diff)

This is what I have so far for the writing editor. All the features in it are fully functional except
for the dialog map.
NOTE: You will have to have PyQt4 installed for this application to run. There are some instructions in
the readme but it is incomplete

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,220)
33        self.central_widget = QtGui.QWidget(self)
34        self.central_widget.setGeometry(QtCore.QRect(0,0,225,220))
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
48class ChangesWindow(QtGui.QMessageBox):
49    """
50    The Save, Cancel, Discard Changes window
51    """
52    def __init__(self, parent=None):
53        """
54        Creates the message box and then returns the button pressed
55        """
56        QtGui.QWidget.__init__(self, parent)
57        self.setText("The document has been modified.")
58        self.setInformativeText("What do you want to do?")
59        self.setStandardButtons(QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard |
60                                  QtGui.QMessageBox.Cancel)
61        self.setDefaultButton(QtGui.QMessageBox.Save)
62        self.setWindowTitle("Changes have been made")
63        self.setWindowIcon(QtGui.QIcon("data/images/question.png"))
64
65    def run(self):
66        ret = self.exec_()
67        return ret
68       
69class PrintDialog(QtGui.QPrintDialog):
70    """
71    The print dialog
72    """
73    def __init__(self, printer, parent=None):
74        """
75        Creates the printer dialog
76        """
77        QtGui.QWidget.__init__(self, printer, parent)
78
79    def run(self):
80        ret = self.exec_()
81        return ret
82
83class PrefWindow(QtGui.QMainWindow):
84    """
85    The preferences window
86    """
87    def __init__(self, parent, settings):
88        """
89        Initializes the class
90        @type parent: QtGui.QWidget?
91        @param parent: the parent widget
92        @type settings: scripts.settings.Settings
93        @param settings: the settings for the application
94        """
95        QtGui.QWidget.__init__(self, parent)
96       
97        self.parent = parent
98        self.settings = settings
99
100        self.setObjectName("prefWindow")
101        self.setWindowTitle("Preferences")
102        self.setWindowIcon(QtGui.QIcon("data/images/preferences.png"))
103        self.resize(500,475)
104        self.central_widget = QtGui.QWidget(self)
105        self.central_widget.setGeometry(QtCore.QRect(0,0,500,350))
106        self.button_widget = QtGui.QWidget(self)
107        self.button_widget.setGeometry(QtCore.QRect(0,355,500,120))
108
109        self.main_layout = QtGui.QFormLayout()
110
111        self.heading = QtGui.QLabel()
112        self.heading.setText("Editor preferences:\n\n")
113        self.main_layout.addRow(self.heading, None)
114
115        self.res_width_label = QtGui.QLabel()
116        self.res_width_label.setText("Resolution Width:")
117        self.res_width = QtGui.QLineEdit()
118        self.res_width.setMaxLength(4)
119        self.res_width.setMaximumWidth(35)
120        self.res_width.setText(self.settings.res_width)
121        self.main_layout.addRow(self.res_width_label, self.res_width)
122        self.res_height_label = QtGui.QLabel()
123        self.res_height_label.setText("Resolution Height: ")
124        self.res_height = QtGui.QLineEdit()
125        self.res_height.setMaxLength(4)
126        self.res_height.setMaximumWidth(35)
127        self.res_height.setText(self.settings.res_height)
128        self.main_layout.addRow(self.res_height_label, self.res_height)
129
130        self.button_layout = QtGui.QHBoxLayout()
131       
132        self.button_cancel = QtGui.QPushButton()
133        self.button_cancel.setText("Cancel")
134        self.button_layout.addWidget(self.button_cancel)
135        self.button_layout.insertStretch(1)
136        self.button_apply = QtGui.QPushButton()
137        self.button_apply.setText("Apply")
138        self.button_layout.addWidget(self.button_apply)
139        self.button_ok = QtGui.QPushButton()
140        self.button_ok.setText("Ok")
141        self.button_layout.addWidget(self.button_ok)
142        self.button_widget.setLayout(self.button_layout)
143
144        self.central_widget.setLayout(self.main_layout)
145       
146        self.connectSignals()
147
148    def connectSignals(self):
149        """
150        Connect all the widgets to their corresponding signals
151        @return: None
152        """
153        QtCore.QObject.connect(self.button_ok, QtCore.SIGNAL("pressed()"),
154                               lambda: self.okOptions("data/options.txt"))
155        QtCore.QObject.connect(self.button_apply, QtCore.SIGNAL("pressed()"),
156                               lambda: self.applyOptions("data/options.txt"))
157        QtCore.QObject.connect(self.button_cancel, QtCore.SIGNAL("pressed()"),
158                               self.close)
159       
160
161    def applyOptions(self, options_file):
162        """
163        Apply the current options
164        @type options_file: string
165        @param options_file: the file to write to
166        @return: None
167        """
168        self.settings.res_width = self.res_width.text()
169        self.settings.res_height = self.res_height.text()
170   
171        self.settings.writeSettingsToFile(options_file)
172        self.button_apply.setEnabled(False)
173
174        self.parent.resize(int(self.settings.res_width),int(self.settings.res_height))
175
176    def okOptions(self, options_file):
177        """
178        Apply the current options then close the window
179        @type options_file: string
180        @param options_file: the file to write to
181        @return: None
182        """
183        self.applyOptions(options_file)
184        self.close()
185       
186
187
188
189
Note: See TracBrowser for help on using the repository browser.