Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

""" This module involves all about the settings in the pySUMO GUI. 

 

This module contains: 

 

- WSettings: The settings of pySUMO's widgets. 

- PluginManager: The manager for the plugin system in pySUMO. 

- OptionDialog: The dialog that displays options of pySUMO. 

 

""" 

 

import pysumo 

from PySide.QtCore import QSettings, Qt 

from PySide.QtGui import QApplication, QColor 

from pysumo.syntaxcontroller import Ontology 

 

class LayoutManager(QSettings): 

    """ 

    The layout manager handles the save and restore state of the main window and it's components. 

    """ 

    def __init__(self, MainWindow): 

        """ 

        Initializes the layout manager. 

         

        Parameter : 

         

        - MainWindow : The main window which owns the manager. 

        """ 

        super(LayoutManager, self).__init__(pysumo.CONFIG_PATH + "/user-layout.ini", QSettings.IniFormat) 

        self.mainwindow = MainWindow 

 

    def saveLayout(self): 

        """  

        Save layout of the main window and persist it in a setting file. 

        """ 

        self.clear() 

        self.savePositionState(self.mainwindow) 

        self.saveSizeState(self.mainwindow) 

        self.setValue("mainWindow/state", self.mainwindow.saveState()) 

        self.saveStatusBarState() 

        actions = self.mainwindow.menuTextEditorWidgets.actions() 

        count = len(actions) 

        self.setValue("TextEditorWidgets/count", count) 

        actions = self.mainwindow.menuDocumentationWidgets.actions() 

        count = len(actions) 

        self.setValue("DocumentationWidgets/count", count) 

        actions = self.mainwindow.menuHierarchyWidgets.actions() 

        count = len(actions) 

        self.setValue("HierarchyWidgets/count", count) 

        actions = self.mainwindow.menuGraphWidgets.actions() 

        count = len(actions) 

        self.setValue("GraphWidgets/count", count) 

        self.saveRecentOntologyHistory() 

 

    def restoreLayout(self): 

        """ 

        Restore the layout of the main window from the persitent setting file. 

        """ 

        self.mainwindow.restoreState(self.value("mainWindow/state")) 

        self.restoreSizeState(self.mainwindow) 

        self.restorePositionState(self.mainwindow) 

        self.restoreStatusBarState() 

        # restore Text Editor Widgets 

        self.restoreTextEditorWidgets() 

        # restore Documentation Widgets 

        self.restoreDocumentationWidgets() 

        # restore Hierarchy Widgets 

        self.restoreHierarchyWidgets() 

        # restore graph widgets 

        self.restoreGraphWidgets() 

        self.restoreRecentOntologyHistory() 

 

    def saveRecentOntologyHistory(self): 

        """ 

        Save the list recently opened ontologies. 

        """ 

        actions = self.mainwindow.menuRecent_Ontologies.actions() 

        self.beginWriteArray("RecentOntologies") 

        idx = 0 

        for action in actions : 

            data = action.data() 

            if not data is None and type(data) == Ontology : 

                self.setArrayIndex(idx) 

                self.setValue("name", data.name) 

                self.setValue("path", data.path) 

                self.setValue("url", data.url) 

                action_log = data.action_log 

                log_io = action_log.log_io 

                lpath = log_io.path 

                self.setValue("lpath", lpath) 

                idx = idx + 1 

        self.endArray() 

 

    def restoreRecentOntologyHistory(self): 

        """ 

        Restore the recent opened ontologies and add them to index. 

        """ 

        size = self.beginReadArray("RecentOntologies") 

        for i in range(size) : 

            self.setArrayIndex(i) 

            name = self.value("name") 

            path = self.value("path") 

            url = self.value("url") 

            lpath = self.value("lpath") 

            ontology = Ontology(path=path, name=name, url=url, lpath=lpath) 

            self.mainwindow.addRecentOntology(ontology) 

        self.endArray() 

 

    def restoreGraphWidgets(self): 

        """ 

        Restore the graph widgets in the main window layout. 

        """ 

        graphWidgetsCount = self.value("GraphWidgets/count") 

        if graphWidgetsCount is None : 

            graphWidgetsCount = 0 

        graphWidgetsCount = int(graphWidgetsCount) 

        count = 0 

        while count < graphWidgetsCount : 

            widget = self.mainwindow.createPySumoWidget("GraphWidget", self.mainwindow.menuGraphWidgets) 

            self.mainwindow.addOrRestoreWidget(widget, self.mainwindow.menuGraphWidgets) 

            count = count + 1 

 

    def restoreTextEditorWidgets(self): 

        """  

        Restore the text editor widgets in the main window layout. 

        """ 

        textEditorWidgetsCount = self.value("TextEditorWidgets/count") 

        if textEditorWidgetsCount == None: 

            textEditorWidgetsCount = 0 

        textEditorWidgetsCount = int(textEditorWidgetsCount) 

        count = 0 

        while count < textEditorWidgetsCount: 

            widget = self.mainwindow.createPySumoWidget("TextEditorWidget", self.mainwindow.menuTextEditorWidgets) 

            self.mainwindow.addOrRestoreWidget(widget, self.mainwindow.menuTextEditorWidgets) 

            count = count + 1 

 

    def restoreDocumentationWidgets(self): 

        """ 

        Restore the documentation widgets in the main window layout. 

        """ 

        documentationWidgetsCount = self.value("DocumentationWidgets/count") 

        if documentationWidgetsCount == None: 

            documentationWidgetsCount = 0 

        documentationWidgetsCount = int(documentationWidgetsCount) 

        count = 0 

        while count < documentationWidgetsCount: 

            widget = self.mainwindow.createPySumoWidget("DocumentationWidget", self.mainwindow.menuDocumentationWidgets) 

            self.mainwindow.addOrRestoreWidget(widget, self.mainwindow.menuDocumentationWidgets) 

            count = count + 1 

 

    def restoreHierarchyWidgets(self): 

        """ 

        Restore the hierarchy widgets in the main window layout. 

        """ 

        hierarchyWidgetsCount = self.value("HierarchyWidgets/count") 

        if hierarchyWidgetsCount == None: 

            hierarchyWidgetsCount = 0 

        hierarchyWidgetsCount = int(hierarchyWidgetsCount) 

        count = 0 

        while count < hierarchyWidgetsCount: 

            widget = self.mainwindow.createPySumoWidget("HierarchyWidget", self.mainwindow.menuHierarchyWidgets) 

            self.mainwindow.addOrRestoreWidget(widget, self.mainwindow.menuHierarchyWidgets) 

            count = count + 1 

 

    def saveVisibilityState(self, qItem): 

        """ 

        Saves the visibility state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which visibility has to be saved. 

        """ 

        objName = qItem.objectName() 

        self.setValue(objName + "/visible", qItem.isVisible()) 

 

    def restoreVisibilityState(self, qItem, qAction=None): 

        """ 

        Restores the visibility state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which visibility has to be saved. 

        - qAction : The action which toggles the visibility state of the qItem. 

        """ 

        objName = qItem.objectName() 

        visible = self.value(objName + "/visible") 

        visible = str(visible).lower() 

        if visible == "false": 

            visible = False 

        elif visible == "true": 

            visible = True 

        else: 

            visible = None 

        # if not visible : 

        #   qAction.triggered.emit() 

        #  qAction.setChecked(False) 

        if visible != None: 

            if qAction != None: 

                qAction.setChecked(visible) 

            qItem.setVisible(visible) 

 

    def savePositionState(self, qItem): 

        """ 

        Saves the position state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which position state has to be saved. 

        """ 

        objName = qItem.objectName() 

        pos = qItem.pos() 

        xPos = pos.x() 

        yPos = pos.y() 

        self.setValue(objName + "/x", xPos) 

        self.setValue(objName + "/y", yPos) 

 

    def restorePositionState(self, qItem): 

        """ 

        Restores the position state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which position state should be restored. 

        """ 

        objName = qItem.objectName() 

        xPos = self.value(objName + "/x") 

        yPos = self.value(objName + "/y") 

        if xPos == None or yPos == None: 

            return 

        xPos = int(xPos) 

        yPos = int(yPos) 

        qItem.move(xPos, yPos) 

 

    def saveSizeState(self, qItem): 

        """ 

        Saves the size state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which size state has to be saved. 

        """ 

        objName = qItem.objectName() 

        size = qItem.size() 

        width = size.width() 

        height = size.height() 

        self.setValue(objName + "/width", width) 

        self.setValue(objName + "/height", height) 

 

    def restoreSizeState(self, qItem): 

        """ 

        Restore the size state of a QWidget. 

         

        Parameter : 

         

        - qItem : The QWidget which size state has to be restored. 

        """ 

        objName = qItem.objectName() 

        width = self.value(objName + "/width") 

        height = self.value(objName + "/height") 

        if width == None or height == None: 

            return 

        width = int(width) 

        height = int(height) 

        qItem.resize(width, height) 

 

    def saveStatusBarState(self): 

        """ Save the status bar state. """ 

        self.saveVisibilityState(self.mainwindow.statusBar) 

 

    def restoreStatusBarState(self): 

        """ Restore the status bar state. """ 

        self.restoreVisibilityState(self.mainwindow.statusBar, self.mainwindow.actionStatusbar) 

 

class PySumoSettings(QSettings): 

    """  

    Settings of PySumo. 

    """ 

 

    def __init__(self, MainWindow, filepath): 

        """ 

        Initializes the settings of pysumo. 

         

        Parameter : 

         

        - MainWindow : The main window of pysumo. 

        - filepath : The path where to save settings. 

        """ 

        super(PySumoSettings, self).__init__(filepath, QSettings.IniFormat) 

 

    def loadDefaults(self): 

        """  

        Loads defaults settings of pysumo. 

        """ 

        self.setValue("configPath", pysumo.CONFIG_PATH) 

        self.setValue("maxQueueSize", 10) 

        self.setValue("maxUndoRedoQueueSize", 10) 

        self.setValue("flushWriteQueuesTimeout", 10) 

        self.setValue("logOutputPath", pysumo.CONFIG_PATH) 

        self.setValue("socketOutputPath", pysumo.CONFIG_PATH) 

        self.setValue("logLevel", 10) 

        defFont = QApplication.font().family() 

        defSize = QApplication.font().pointSize() 

        self.setValue("keywordsFontFamily", defFont) 

        self.setValue("keywordsFontSize", defSize) 

        self.setValue("keywordsFontColor", QColor(Qt.darkGreen).name()) 

        self.setValue("keywordsBoldStyle", True) 

        self.setValue("keywordsItalicStyle", False) 

        self.setValue("keywordsUnderlinedStyle", False) 

        self.setValue("logicExprFontFamily", defFont) 

        self.setValue("logicExprFontSize", defSize) 

        self.setValue("logicExprFontColor", QColor(Qt.black).name()) 

        self.setValue("logicExprBoldStyle", True) 

        self.setValue("logicExprItalicStyle", False) 

        self.setValue("logicExprUnderlinedStyle", False) 

        self.setValue("commentFontFamily", defFont) 

        self.setValue("commentFontSize", defSize) 

        self.setValue("commentFontColor", QColor(Qt.darkMagenta).name()) 

        self.setValue("commentBoldStyle", False) 

        self.setValue("commentItalicStyle", True) 

        self.setValue("commentUnderlinedStyle", False) 

        self.setValue("stringsFontFamily", defFont) 

        self.setValue("stringsFontSize", defSize) 

        self.setValue("stringsFontColor", QColor(Qt.red).name()) 

        self.setValue("stringsBoldStyle", False) 

        self.setValue("stringsItalicStyle", False) 

        self.setValue("stringsUnderlinedStyle", False) 

        self.setValue("maxTextEditorWidgets", 10) 

        self.setValue("maxDocumentationWidgets", 10) 

        self.setValue("maxHierarchyWidgets", 10) 

        self.setValue("maxGraphWidgets", 10) 

        self.setValue("defaultFontSize", defSize) 

        self.setValue("defaultFontFamily", defFont) 

        self.setValue("defaultFontColor", QApplication.palette().text().color().name()) 

        self.setValue("useHighlightingFontSize", False)