source: trunk/tools/writing_editor/scripts/dialogMap.py @ 250

Revision 250, 3.0 KB checked in by bretzel_parpg, 10 years ago (diff)

Added some functionality to the dialog map

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
19from scripts.parser import Parser
20
21
22class DialogMap(QtGui.QTreeWidget):
23    """
24    The dialog map which will show the flow of the dialog
25    """
26    def __init__(self, settings, main_edit, parent):
27        """
28        Initialize the dialog map
29        @type settings: settings.Settings
30        @param settings: the settings for the editor
31        @type main_edit: QtGui.QTextEdit
32        @param main_edit: The main text editor
33        @type parent: Any Qt widget
34        @param parent: The widgets' parent
35        @return: None
36        """
37        QtGui.QWidget.__init__(self, parent)
38       
39        self.settings = settings
40        self.parent = parent
41        self.resize(int(self.settings.res_width), int(self.settings.res_height))
42        self.parser = Parser(main_edit, self.handleResult)
43        self.itemCount = 0
44
45        self.setColumnCount(1)
46        self.setEditTriggers(self.NoEditTriggers)
47        self.setHeaderLabel("")
48       
49    def handleResult(self, result, type_):
50        """
51        Take the result, determine where to put it in the dialog map, then put it there
52        @type result: string
53        @param result: the result to be handled
54        @type type_: string
55        @param type_: the type of result
56        @return: None
57        """
58        text = result.split(' ')
59        if (type_ == "SCRIPTNAME"):
60            self.setHeaderLabel(text[1])
61
62        elif (type_ == "SAY"):
63            sayText = text[0] + " says " + text[2]
64            print "text: " + sayText
65            self.sayItem = QtGui.QTreeWidgetItem()
66            self.sayItem.setText(0, sayText)
67            self.insertItem(self.sayItem)
68
69        elif (type_ == "ATTACK"):
70            attackText = text[0] + " attacks " + text[2]
71            self.attackItem = QtGui.QTreeWidgetItem()
72            self.attackItem.setText(0, attackText)
73            self.insertItem(self.attackItem)
74
75    def insertItem(self, item):
76        """
77        Insert an item at the correct place in the dialog tree
78        @type item: QtGui.QTreeWidgetItem
79        @param item: the item to insert
80        @return: None
81        """
82        self.insertTopLevelItem(0, item)
83
84    def clear(self):
85        """
86        Clear the dialog map
87        """
88        self.setHeaderLabel("")
89        for i in xrange(self.topLevelItemCount()):
90            item = self.itemAt(0, i)
91            self.removeItemWidget(item, 0)
Note: See TracBrowser for help on using the repository browser.