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

Revision 251, 3.7 KB checked in by bretzel_parpg, 10 years ago (diff)

Started on putting options in the dialog map

RevLine 
[234]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
[250]21
[234]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))
[250]42        self.parser = Parser(main_edit, self.handleResult)
[234]43
[251]44        self.parentItem = None
45        self.inOption = False
46
[234]47        self.setColumnCount(1)
48        self.setEditTriggers(self.NoEditTriggers)
[250]49        self.setHeaderLabel("")
50       
51    def handleResult(self, result, type_):
52        """
53        Take the result, determine where to put it in the dialog map, then put it there
54        @type result: string
55        @param result: the result to be handled
56        @type type_: string
57        @param type_: the type of result
58        @return: None
59        """
60        text = result.split(' ')
[251]61
[250]62        if (type_ == "SCRIPTNAME"):
63            self.setHeaderLabel(text[1])
64
65        elif (type_ == "SAY"):
66            sayText = text[0] + " says " + text[2]
67            self.sayItem = QtGui.QTreeWidgetItem()
68            self.sayItem.setText(0, sayText)
69            self.insertItem(self.sayItem)
70
71        elif (type_ == "ATTACK"):
72            attackText = text[0] + " attacks " + text[2]
73            self.attackItem = QtGui.QTreeWidgetItem()
74            self.attackItem.setText(0, attackText)
75            self.insertItem(self.attackItem)
76
[251]77        elif (type_ == "OPTION"):
78            optionText = "Option " + text[1]
79            self.optionItem = QtGui.QTreeWidgetItem()
80            self.optionItem.setText(0, optionText)
81            self.insertItem(self.optionItem)
82            self.parentItem = self.optionItem
83            self.inOption = True
84
85        elif (self.inOption and type_ == "."):
86            option_text = result.split('.')
87            itemText = option_text[0] + ': ' + option_text[1]
88            self.optionItem = QtGui.QTreeWidgetItem()
89            self.optionItem.setText(0, itemText)
90            self.parentItem.addChild(self.optionItem)
91
92        elif (type_ == "ENDOPTION"):
93            self.inOption = False
94
[250]95    def insertItem(self, item):
96        """
97        Insert an item at the correct place in the dialog tree
98        @type item: QtGui.QTreeWidgetItem
99        @param item: the item to insert
100        @return: None
101        """
[251]102        if (self.parentItem == None):
103            self.insertTopLevelItem(self.topLevelItemCount(), item)
104        else:
105            self.parentItem.addChild(item)
[250]106
107    def clear(self):
108        """
109        Clear the dialog map
110        """
111        self.setHeaderLabel("")
[251]112        self.invisibleRootItem().takeChildren()
Note: See TracBrowser for help on using the repository browser.