2015-05-28 13:32:09 +12:00
#!/usr/bin/env python
#--!-- coding: utf8 --!--
2015-06-23 07:34:11 +12:00
2015-06-04 04:40:19 +12:00
from qt import *
2015-05-28 13:32:09 +12:00
from ui . mainWindow import *
2015-06-04 05:25:03 +12:00
from ui . helpLabel import helpLabel
2015-05-31 16:03:07 +12:00
from loadSave import *
2015-06-01 22:29:06 +12:00
from enums import *
2015-06-02 10:06:17 +12:00
from models . outlineModel import *
2015-06-29 09:46:51 +12:00
from models . persosModel import *
2015-06-22 04:13:14 +12:00
from models . plotModel import *
2015-06-29 09:46:51 +12:00
#from models.persosProxyModel import *
2015-06-05 06:22:37 +12:00
from functions import *
2015-06-10 10:20:32 +12:00
from settingsWindow import *
2015-06-16 06:09:16 +12:00
import settings
2015-06-25 04:39:38 +12:00
import imp
2015-05-28 13:32:09 +12:00
2015-06-07 05:10:44 +12:00
# Spell checker support
try :
import enchant
except ImportError :
enchant = None
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
class MainWindow ( QMainWindow , Ui_MainWindow ) :
2015-06-23 07:34:11 +12:00
2015-06-08 08:06:57 +12:00
dictChanged = pyqtSignal ( str )
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
def __init__ ( self ) :
QMainWindow . __init__ ( self )
self . setupUi ( self )
2015-06-23 10:19:40 +12:00
self . currentProject = None
2015-05-31 16:03:07 +12:00
self . readSettings ( )
2015-06-23 07:34:11 +12:00
2015-05-29 05:15:57 +12:00
# UI
2015-06-04 05:25:03 +12:00
self . setupMoreUi ( )
2015-06-23 10:19:40 +12:00
# Welcome
2015-06-24 04:22:39 +12:00
self . welcome . updateValues ( )
#self.welcome.btnCreate.clicked.connect
self . stack . setCurrentIndex ( 0 )
2015-06-23 10:19:40 +12:00
2015-05-31 16:03:07 +12:00
# Word count
self . mprWordCount = QSignalMapper ( self )
2015-05-28 13:32:09 +12:00
for t , i in [
( self . txtSummarySentance , 0 ) ,
( self . txtSummaryPara , 1 ) ,
( self . txtSummaryPage , 2 ) ,
( self . txtSummaryFull , 3 )
] :
2015-05-31 16:03:07 +12:00
t . textChanged . connect ( self . mprWordCount . map )
self . mprWordCount . setMapping ( t , i )
self . mprWordCount . mapped . connect ( self . wordCount )
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
# Snowflake Method Cycle
self . mapperCycle = QSignalMapper ( self )
for t , i in [
( self . btnStepTwo , 0 ) ,
( self . btnStepThree , 1 ) ,
( self . btnStepFour , 2 ) ,
( self . btnStepFive , 3 ) ,
( self . btnStepSix , 4 ) ,
( self . btnStepSeven , 5 ) ,
( self . btnStepEight , 6 )
] :
t . clicked . connect ( self . mapperCycle . map )
self . mapperCycle . setMapping ( t , i )
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
self . mapperCycle . mapped . connect ( self . clickCycle )
2015-06-21 21:29:35 +12:00
self . cmbSummary . currentIndexChanged . connect ( self . summaryPageChanged )
self . cmbSummary . setCurrentIndex ( 0 )
self . cmbSummary . currentIndexChanged . emit ( 0 )
2015-06-23 07:34:11 +12:00
2015-06-10 10:20:32 +12:00
# Main Menu
2015-06-23 10:19:40 +12:00
for i in [ self . actSave , self . actSaveAs , self . actCloseProject ,
self . menuEdit , self . menuMode , self . menuView , self . menuTools ,
self . menuHelp ] :
i . setEnabled ( False )
2015-06-24 04:22:39 +12:00
self . actOpen . triggered . connect ( self . welcome . openFile )
2015-06-17 22:00:03 +12:00
self . actSave . triggered . connect ( self . saveDatas )
2015-06-24 04:22:39 +12:00
self . actSaveAs . triggered . connect ( self . welcome . saveAsFile )
2015-06-10 10:20:32 +12:00
self . actLabels . triggered . connect ( self . settingsLabel )
self . actStatus . triggered . connect ( self . settingsStatus )
2015-06-17 19:33:25 +12:00
self . actSettings . triggered . connect ( self . settingsWindow )
2015-06-24 04:22:39 +12:00
self . actCloseProject . triggered . connect ( self . closeProject )
2015-06-10 10:20:32 +12:00
self . actQuit . triggered . connect ( self . close )
2015-06-16 06:09:16 +12:00
self . generateViewMenu ( )
2015-06-23 10:19:40 +12:00
2015-06-25 01:43:35 +12:00
self . makeUIConnections ( )
2015-06-23 10:19:40 +12:00
#self.loadProject(os.path.join(appPath(), "test_project.zip"))
2015-06-23 07:34:11 +12:00
###############################################################################
# SUMMARY
###############################################################################
2015-06-21 21:29:35 +12:00
def summaryPageChanged ( self , index ) :
fractalButtons = [
self . btnStepTwo ,
self . btnStepThree ,
self . btnStepFive ,
self . btnStepSeven ,
]
for b in fractalButtons :
b . setVisible ( fractalButtons . index ( b ) == index )
2015-06-23 07:34:11 +12:00
###############################################################################
# OUTLINE
###############################################################################
2015-06-03 00:40:48 +12:00
def outlineRemoveItems ( self ) :
for idx in self . treeRedacOutline . selectedIndexes ( ) :
if idx . isValid ( ) :
self . mdlOutline . removeIndex ( idx )
2015-06-23 07:34:11 +12:00
###############################################################################
# PERSOS
###############################################################################
2015-06-01 08:41:32 +12:00
2015-06-29 09:46:51 +12:00
#def createPerso(self):
#"""Creates a perso by adding a row in mdlPersos
#and a column in mdlPersosInfos with same ID"""
#p = QStandardItem(self.tr("New character"))
#pid = self.getPersosID()
##self.checkPersosID() # Attributes a persoID (which is logically pid)
#self.mdlPersos.appendRow([p, QStandardItem(pid), QStandardItem("0")])
#self.setPersoColor(self.mdlPersos.rowCount() - 1,
#randomColor(QColor(Qt.white)))
## Add column in persos infos
#self.mdlPersosInfos.insertColumn(self.mdlPersosInfos.columnCount(),
#[QStandardItem(pid)])
#self.mdlPersosInfos.setHorizontalHeaderItem(
#self.mdlPersosInfos.columnCount() - 1,
#QStandardItem("Valeur"))
#def getPersosID(self):
#"""Returns an unused perso ID (row 1)."""
#vals = []
#for i in range(self.mdlPersos.rowCount()):
#item = self.mdlPersos.item(i, Perso.ID.value)
#if item and item.text():
#vals.append(int(item.text()))
#k = 0
#while k in vals:
#k += 1
#return str(k)
#def checkPersosID(self):
#"""Checks whether some persos ID (row 1) are empty.
#If so, assign an ID"""
#for i in range(self.mdlPersos.rowCount()):
#item = self.mdlPersos.item(i, Perso.ID.value)
#if not item:
#item = QStandardItem()
#item.setText(self.getPersosID())
#self.mdlPersos.setItem(i, Perso.ID.value, item)
#def removePerso(self):
#if self.mdlPersosProxy:
#i = self.mdlPersosProxy.mapToSource(self.lstPersos.currentIndex())
#else:
#i = self.lstPersos.currentIndex()
#self.mdlPersos.takeRow(i.row())
#self.mdlPersosInfos.takeColumn(i.row() + 1)
2015-06-23 07:34:11 +12:00
2015-06-01 08:41:32 +12:00
def changeCurrentPerso ( self , trash = None ) :
2015-06-29 09:46:51 +12:00
index = self . lstPersos . currentPersoIndex ( )
2015-06-23 07:34:11 +12:00
2015-06-29 09:46:51 +12:00
if not index . isValid ( ) :
self . tabPlot . setEnabled ( False )
return
2015-06-23 07:34:11 +12:00
2015-06-29 09:46:51 +12:00
self . tabPersos . setEnabled ( True )
2015-06-29 20:22:18 +12:00
for w in [
self . txtPersoName ,
self . sldPersoImportance ,
self . txtPersoMotivation ,
self . txtPersoGoal ,
self . txtPersoConflict ,
self . txtPersoEpiphany ,
self . txtPersoSummarySentance ,
self . txtPersoSummaryPara ,
self . txtPersoSummaryFull ,
self . txtPersoNotes ,
] :
w . setCurrentModelIndex ( index )
2015-06-29 09:46:51 +12:00
2015-06-29 21:28:34 +12:00
# Button color
2015-06-29 09:46:51 +12:00
self . mdlPersos . updatePersoColor ( index )
2015-06-29 21:28:34 +12:00
# Perso Infos
self . tblPersoInfos . setRootIndex ( index )
if self . mdlPersos . rowCount ( index ) :
self . updatePersoInfoView ( )
2015-06-29 09:46:51 +12:00
#if self.mdlPersosProxy:
#idx = self.mdlPersosProxy.mapToSource(self.lstPersos.currentIndex())
#else:
#idx = self.lstPersos.currentIndex()
#self.mprPersos.setCurrentModelIndex(idx)
## detailed infos
#pid = self.mdlPersos.item(idx.row(), Perso.ID.value).text()
#for c in range(self.mdlPersosInfos.columnCount()):
#pid2 = self.mdlPersosInfos.item(0, c).text()
#self.tblPersoInfos.setColumnHidden(c, c != 0 and pid != pid2)
#self.resizePersosInfos()
2015-06-29 21:28:34 +12:00
def updatePersoInfoView ( self ) :
# Hide columns
for i in range ( self . mdlPersos . columnCount ( ) ) :
self . tblPersoInfos . hideColumn ( i )
self . tblPersoInfos . showColumn ( Perso . infoName . value )
self . tblPersoInfos . showColumn ( Perso . infoData . value )
self . tblPersoInfos . horizontalHeader ( ) . setSectionResizeMode (
Perso . infoName . value , QHeaderView . ResizeToContents )
self . tblPersoInfos . horizontalHeader ( ) . setSectionResizeMode (
Perso . infoData . value , QHeaderView . Stretch )
self . tblPersoInfos . verticalHeader ( ) . hide ( )
2015-06-29 09:46:51 +12:00
#def updatePersoColor(self):
#if self.mdlPersosProxy:
#idx = self.mdlPersosProxy.mapToSource(self.lstPersos.currentIndex())
#else:
#idx = self.lstPersos.currentIndex()
#icon = self.mdlPersos.item(idx.row()).icon()
#color = iconColor(icon).name() if icon else ""
#self.btnPersoColor.setStyleSheet("background:{};".format(color))
#def resizePersosInfos(self):
#self.tblPersoInfos.resizeColumnToContents(0)
#w = self.tblPersoInfos.viewport().width()
#w2 = self.tblPersoInfos.columnWidth(0)
#if self.mdlPersosProxy:
#current = self.mdlPersosProxy.mapToSource(
#self.lstPersos.currentIndex()).row() + 1
#else:
#current = self.lstPersos.currentIndex().row() + 1
#self.tblPersoInfos.setColumnWidth(current, w - w2)
#def chosePersoColor(self):
#if self.mdlPersosProxy:
#idx = self.mdlPersosProxy.mapToSource(self.lstPersos.currentIndex())
#else:
#idx = self.lstPersos.currentIndex()
#item = self.mdlPersos.item(idx.row(), Perso.name.value)
#if item:
#color = iconColor(item.icon())
#else:
#color = Qt.white
#self.colorDialog = QColorDialog(color, self)
#color = self.colorDialog.getColor(color)
#if color.isValid():
#self.setPersoColor(idx.row(), color)
#self.updatePersoColor()
#def setPersoColor(self, row, color):
#px = QPixmap(32, 32)
#px.fill(color)
#self.mdlPersos.item(row, Perso.name.value).setIcon(QIcon(px))
2015-06-23 07:34:11 +12:00
###############################################################################
# PLOTS
###############################################################################
2015-06-22 23:11:45 +12:00
def changeCurrentPlot ( self ) :
2015-06-23 06:30:43 +12:00
index = self . lstPlots . currentPlotIndex ( )
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
if not index . isValid ( ) :
self . tabPlot . setEnabled ( False )
return
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
self . tabPlot . setEnabled ( True )
self . txtPlotName . setCurrentModelIndex ( index )
self . txtPlotDescription . setCurrentModelIndex ( index )
self . txtPlotResult . setCurrentModelIndex ( index )
self . sldPlotImportance . setCurrentModelIndex ( index )
2015-06-23 07:34:11 +12:00
self . lstPlotPerso . setRootIndex ( index . sibling ( index . row ( ) ,
Plot . persos . value ) )
self . lstSubPlots . setRootIndex ( index . sibling ( index . row ( ) ,
Plot . subplots . value ) )
2015-06-22 23:11:45 +12:00
#self.txtSubPlotSummary.setCurrentModelIndex(QModelIndex())
self . txtSubPlotSummary . setEnabled ( False )
2015-06-23 07:07:38 +12:00
self . _updatingSubPlot = True
2015-06-22 23:11:45 +12:00
self . txtSubPlotSummary . setPlainText ( " " )
2015-06-23 07:07:38 +12:00
self . _updatingSubPlot = False
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
def changeCurrentSubPlot ( self , index ) :
2015-06-23 07:34:11 +12:00
# Got segfaults when using textEditView model system, so ad hoc stuff.
2015-06-22 23:11:45 +12:00
index = index . sibling ( index . row ( ) , 3 )
item = self . mdlPlots . itemFromIndex ( index )
if not item :
self . txtSubPlotSummary . setEnabled ( False )
return
self . txtSubPlotSummary . setEnabled ( True )
txt = item . text ( )
self . _updatingSubPlot = True
self . txtSubPlotSummary . setPlainText ( txt )
self . _updatingSubPlot = False
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
def updateSubPlotSummary ( self ) :
if self . _updatingSubPlot :
return
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
index = self . lstSubPlots . currentIndex ( )
if not index . isValid ( ) :
return
index = index . sibling ( index . row ( ) , 3 )
item = self . mdlPlots . itemFromIndex ( index )
2015-06-23 07:34:11 +12:00
2015-06-22 23:11:45 +12:00
self . _updatingSubPlot = True
item . setText ( self . txtSubPlotSummary . toPlainText ( ) )
self . _updatingSubPlot = False
2015-06-23 07:34:11 +12:00
###############################################################################
2015-06-24 04:22:39 +12:00
# LOAD AND SAVE
2015-06-23 07:34:11 +12:00
###############################################################################
2015-06-24 04:22:39 +12:00
def loadProject ( self , project , loadFromFile = True ) :
""" Loads the project ``project``.
If ` ` loadFromFile ` ` is False , then it does not load datas from file .
It assumes that the datas have been populated in a different way . """
if loadFromFile and not os . path . exists ( project ) :
print ( self . tr ( " The file {} does not exist. Try again. " ) . format ( project ) )
self . statusBar ( ) . showMessage (
self . tr ( " The file {} does not exist. Try again. " ) . format ( project ) ,
5000 )
return
2015-06-01 08:41:32 +12:00
self . currentProject = project
2015-06-24 04:22:39 +12:00
QSettings ( ) . setValue ( " lastProject " , project )
if loadFromFile :
2015-06-25 20:01:28 +12:00
# Load empty settings
imp . reload ( settings )
# Load data
2015-06-24 04:22:39 +12:00
self . loadEmptyDatas ( )
self . loadDatas ( )
2015-06-25 20:01:28 +12:00
2015-06-22 06:00:03 +12:00
self . makeConnections ( )
2015-06-23 07:34:11 +12:00
2015-06-17 22:00:03 +12:00
# Load settings
2015-06-30 00:21:57 +12:00
for i in settings . openIndexes :
idx = self . mdlOutline . indexFromPath ( i )
self . mainEditor . setCurrentModelIndex ( idx , newTab = True )
2015-06-16 06:09:16 +12:00
self . generateViewMenu ( )
2015-06-28 00:06:35 +12:00
self . mainEditor . sldCorkSizeFactor . setValue ( settings . corkSizeFactor )
2015-06-16 06:09:16 +12:00
self . actSpellcheck . setChecked ( settings . spellcheck )
2015-06-30 00:21:57 +12:00
self . toggleSpellcheck ( settings . spellcheck )
2015-06-16 06:09:16 +12:00
self . updateMenuDict ( )
self . setDictionary ( )
2015-06-30 00:21:57 +12:00
2015-06-28 00:06:35 +12:00
self . mainEditor . setFolderView ( settings . folderView )
2015-06-30 00:21:57 +12:00
self . mainEditor . updateFolderViewButtons ( settings . folderView )
2015-06-16 06:30:18 +12:00
self . tabMain . setCurrentIndex ( settings . lastTab )
2015-06-28 00:06:35 +12:00
self . mainEditor . updateCorkBackground ( )
2015-06-23 07:34:11 +12:00
2015-06-17 22:00:03 +12:00
# Set autosave
2015-06-18 04:40:55 +12:00
self . saveTimer = QTimer ( )
self . saveTimer . setInterval ( settings . autoSaveDelay * 60 * 1000 )
self . saveTimer . setSingleShot ( False )
self . saveTimer . timeout . connect ( self . saveDatas )
2015-06-17 22:00:03 +12:00
if settings . autoSave :
self . saveTimer . start ( )
2015-06-23 07:34:11 +12:00
2015-06-18 04:40:55 +12:00
# Set autosave if no changes
self . saveTimerNoChanges = QTimer ( )
2015-06-23 07:34:11 +12:00
self . saveTimerNoChanges . setInterval ( settings . autoSaveNoChangesDelay
* 1000 )
2015-06-18 04:40:55 +12:00
self . saveTimerNoChanges . setSingleShot ( True )
2015-06-24 04:22:39 +12:00
self . mdlFlatData . dataChanged . connect ( self . startTimerNoChanges )
2015-06-18 04:40:55 +12:00
self . mdlOutline . dataChanged . connect ( self . startTimerNoChanges )
2015-06-18 06:48:20 +12:00
self . mdlPersos . dataChanged . connect ( self . startTimerNoChanges )
2015-06-29 09:46:51 +12:00
#self.mdlPersosInfos.dataChanged.connect(self.startTimerNoChanges)
2015-06-18 06:48:20 +12:00
self . mdlStatus . dataChanged . connect ( self . startTimerNoChanges )
self . mdlLabels . dataChanged . connect ( self . startTimerNoChanges )
2015-06-23 07:34:11 +12:00
2015-06-18 04:40:55 +12:00
self . saveTimerNoChanges . timeout . connect ( self . saveDatas )
self . saveTimerNoChanges . stop ( )
2015-06-23 07:34:11 +12:00
2015-06-17 22:00:03 +12:00
# UI
2015-06-23 10:19:40 +12:00
for i in [ self . actSave , self . actSaveAs , self . actCloseProject ,
self . menuEdit , self . menuMode , self . menuView , self . menuTools ,
self . menuHelp ] :
i . setEnabled ( True )
2015-06-17 22:00:03 +12:00
#FIXME: set Window's name: project name
2015-06-23 07:34:11 +12:00
2015-06-01 08:41:32 +12:00
# Stuff
2015-06-29 09:46:51 +12:00
#self.checkPersosID() # Should'n be necessary any longer
2015-06-24 04:22:39 +12:00
# Show main Window
self . stack . setCurrentIndex ( 1 )
def closeProject ( self ) :
# Save datas
self . saveDatas ( )
self . currentProject = None
QSettings ( ) . setValue ( " lastProject " , " " )
# Clear datas
self . loadEmptyDatas ( )
self . saveTimer . stop ( )
# UI
for i in [ self . actSave , self . actSaveAs , self . actCloseProject ,
self . menuEdit , self . menuMode , self . menuView , self . menuTools ,
self . menuHelp ] :
i . setEnabled ( False )
# Reload recent files
self . welcome . updateValues ( )
# Show welcome dialog
self . stack . setCurrentIndex ( 0 )
2015-06-23 07:34:11 +12:00
2015-06-24 04:22:39 +12:00
def readSettings ( self ) :
# Load State and geometry
sttgns = QSettings ( qApp . organizationName ( ) , qApp . applicationName ( ) )
if sttgns . contains ( " geometry " ) :
self . restoreGeometry ( sttgns . value ( " geometry " ) )
if sttgns . contains ( " windowState " ) :
self . restoreState ( sttgns . value ( " windowState " ) )
def closeEvent ( self , event ) :
# Save State and geometry
sttgns = QSettings ( qApp . organizationName ( ) , qApp . applicationName ( ) )
sttgns . setValue ( " geometry " , self . saveGeometry ( ) )
sttgns . setValue ( " windowState " , self . saveState ( ) )
# Specific settings to save before quitting
settings . lastTab = self . tabMain . currentIndex ( )
if self . currentProject :
2015-06-30 00:21:57 +12:00
# Remembering the current items
sel = [ ]
for i in range ( self . mainEditor . tab . count ( ) ) :
sel . append ( self . mdlOutline . pathToIndex ( self . mainEditor . tab . widget ( i ) . currentIndex ) )
settings . openIndexes = sel
2015-06-24 04:22:39 +12:00
# Save data from models
if self . currentProject and settings . saveOnQuit :
self . saveDatas ( )
# closeEvent
2015-06-29 20:22:18 +12:00
#QMainWindow.closeEvent(self, event) # Causin segfaults?
2015-06-24 04:22:39 +12:00
def startTimerNoChanges ( self ) :
if settings . autoSaveNoChanges :
self . saveTimerNoChanges . start ( )
def saveDatas ( self , projectName = None ) :
""" Saves the current project (in self.currentProject).
If ` ` projectName ` ` is given , currentProject becomes projectName .
In other words , it " saves as... " .
"""
if projectName :
self . currentProject = projectName
QSettings ( ) . setValue ( " lastProject " , projectName )
# Saving
files = [ ]
files . append ( ( saveStandardItemModelXML ( self . mdlFlatData ) ,
" flatModel.xml " ) )
files . append ( ( saveStandardItemModelXML ( self . mdlPersos ) ,
" perso.xml " ) )
2015-06-29 09:46:51 +12:00
#files.append((saveStandardItemModelXML(self.mdlPersosInfos),
#"persoInfos.xml"))
2015-06-24 04:22:39 +12:00
files . append ( ( saveStandardItemModelXML ( self . mdlLabels ) ,
" labels.xml " ) )
files . append ( ( saveStandardItemModelXML ( self . mdlStatus ) ,
" status.xml " ) )
files . append ( ( saveStandardItemModelXML ( self . mdlPlots ) ,
" plots.xml " ) )
files . append ( ( self . mdlOutline . saveToXML ( ) ,
" outline.xml " ) )
files . append ( ( settings . save ( ) ,
" settings.pickle " ) )
saveFilesToZip ( files , self . currentProject )
# Giving some feedback
print ( self . tr ( " Project {} saved. " ) . format ( self . currentProject ) )
self . statusBar ( ) . showMessage (
self . tr ( " Project {} saved. " ) . format ( self . currentProject ) , 5000 )
def loadEmptyDatas ( self ) :
2015-06-25 06:32:50 +12:00
self . mdlFlatData = QStandardItemModel ( self )
2015-06-29 09:46:51 +12:00
self . mdlPersos = persosModel ( self )
#self.mdlPersosProxy = persosProxyModel(self)
#self.mdlPersosInfos = QStandardItemModel(self)
2015-06-25 06:32:50 +12:00
self . mdlLabels = QStandardItemModel ( self )
self . mdlStatus = QStandardItemModel ( self )
self . mdlPlots = plotModel ( self )
self . mdlOutline = outlineModel ( self )
2015-06-24 04:22:39 +12:00
def loadDatas ( self ) :
# Loading
files = loadFilesFromZip ( self . currentProject )
errors = [ ]
2015-06-23 10:19:40 +12:00
2015-06-24 04:22:39 +12:00
if " flatModel.xml " in files :
loadStandardItemModelXML ( self . mdlFlatData ,
files [ " flatModel.xml " ] , fromString = True )
2015-06-23 10:19:40 +12:00
else :
2015-06-24 04:22:39 +12:00
errors . append ( " flatModel.xml " )
if " perso.xml " in files :
loadStandardItemModelXML ( self . mdlPersos ,
files [ " perso.xml " ] , fromString = True )
else :
errors . append ( " perso.xml " )
2015-06-29 09:46:51 +12:00
#if "persoInfos.xml" in files:
#loadStandardItemModelXML(self.mdlPersosInfos,
#files["persoInfos.xml"], fromString=True)
#else:
#errors.append("perso.xml")
2015-06-24 04:22:39 +12:00
if " labels.xml " in files :
loadStandardItemModelXML ( self . mdlLabels ,
files [ " labels.xml " ] , fromString = True )
else :
errors . append ( " perso.xml " )
if " status.xml " in files :
loadStandardItemModelXML ( self . mdlStatus ,
files [ " status.xml " ] , fromString = True )
else :
errors . append ( " perso.xml " )
if " plots.xml " in files :
loadStandardItemModelXML ( self . mdlPlots ,
files [ " plots.xml " ] , fromString = True )
else :
errors . append ( " perso.xml " )
if " outline.xml " in files :
self . mdlOutline . loadFromXML ( files [ " outline.xml " ] , fromString = True )
else :
errors . append ( " perso.xml " )
if " settings.pickle " in files :
settings . load ( files [ " settings.pickle " ] , fromString = True )
else :
errors . append ( " perso.xml " )
2015-06-23 10:19:40 +12:00
2015-06-24 04:22:39 +12:00
# Giving some feedback
if not errors :
print ( self . tr ( " Project {} loaded. " ) . format ( self . currentProject ) )
self . statusBar ( ) . showMessage (
self . tr ( " Project {} loaded. " ) . format ( self . currentProject ) , 5000 )
else :
print ( self . tr ( " Project {} loaded with some errors: " ) . format ( self . currentProject ) )
for e in errors :
print ( self . tr ( " * {} wasn ' t found in project file. " ) . format ( e ) )
self . statusBar ( ) . showMessage (
self . tr ( " Project {} loaded with some errors. " ) . format ( self . currentProject ) , 5000 )
###############################################################################
# MAIN CONNECTIONS
###############################################################################
2015-06-22 06:00:03 +12:00
2015-06-25 01:43:35 +12:00
def makeUIConnections ( self ) :
" Connections that have to be made once only, event when new project is loaded. "
2015-06-29 09:46:51 +12:00
self . lstPersos . currentItemChanged . connect ( self . changeCurrentPerso , AUC )
2015-06-25 01:43:35 +12:00
self . txtPlotFilter . textChanged . connect ( self . lstPlots . setFilter , AUC )
self . lstPlots . currentItemChanged . connect ( self . changeCurrentPlot , AUC )
self . txtSubPlotSummary . document ( ) . contentsChanged . connect (
self . updateSubPlotSummary , AUC )
self . lstSubPlots . activated . connect ( self . changeCurrentSubPlot , AUC )
self . btnRedacAddFolder . clicked . connect ( self . treeRedacOutline . addFolder , AUC )
self . btnPlanAddFolder . clicked . connect ( self . treePlanOutline . addFolder , AUC )
self . btnRedacAddText . clicked . connect ( self . treeRedacOutline . addText , AUC )
self . btnPlanAddText . clicked . connect ( self . treePlanOutline . addText , AUC )
self . btnRedacRemoveItem . clicked . connect ( self . outlineRemoveItems , AUC )
self . btnPlanRemoveItem . clicked . connect ( self . outlineRemoveItems , AUC )
2015-06-28 23:03:57 +12:00
self . mainEditor . btnRedacShowOutline . toggled . connect ( self . treeRedacWidget . setVisible )
self . mainEditor . btnRedacShowOutline . setChecked ( True )
self . mainEditor . btnRedacShowInfos . toggled . connect ( self . tabRedacInfos . setVisible )
self . mainEditor . btnRedacShowInfos . setChecked ( True )
2015-06-25 01:43:35 +12:00
2015-06-22 06:00:03 +12:00
def makeConnections ( self ) :
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
# Flat datas (Summary and general infos)
for widget , col in [
( self . txtSummarySituation , 0 ) ,
( self . txtSummarySentance , 1 ) ,
( self . txtSummarySentance_2 , 1 ) ,
( self . txtSummaryPara , 2 ) ,
( self . txtSummaryPara_2 , 2 ) ,
( self . txtPlotSummaryPara , 2 ) ,
( self . txtSummaryPage , 3 ) ,
( self . txtSummaryPage_2 , 3 ) ,
( self . txtPlotSummaryPage , 3 ) ,
( self . txtSummaryFull , 4 ) ,
( self . txtPlotSummaryFull , 4 ) ,
] :
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
widget . setModel ( self . mdlFlatData )
widget . setColumn ( col )
widget . setCurrentModelIndex ( self . mdlFlatData . index ( 1 , col ) )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
for widget , col in [
( self . txtGeneralTitle , 0 ) ,
( self . txtGeneralSubtitle , 1 ) ,
( self . txtGeneralSerie , 2 ) ,
( self . txtGeneralVolume , 3 ) ,
( self . txtGeneralGenre , 4 ) ,
( self . txtGeneralLicense , 5 ) ,
( self . txtGeneralAuthor , 6 ) ,
( self . txtGeneralEmail , 7 ) ,
] :
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
widget . setModel ( self . mdlFlatData )
widget . setColumn ( col )
widget . setCurrentModelIndex ( self . mdlFlatData . index ( 0 , col ) )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
# Persos
2015-06-29 09:46:51 +12:00
self . lstPersos . setPersosModel ( self . mdlPersos )
2015-06-29 21:28:34 +12:00
self . tblPersoInfos . setModel ( self . mdlPersos )
2015-06-29 09:46:51 +12:00
self . btnAddPerso . clicked . connect ( self . mdlPersos . addPerso , AUC )
self . btnRmPerso . clicked . connect ( self . mdlPersos . removePerso , AUC )
self . btnPersoColor . clicked . connect ( self . mdlPersos . chosePersoColor , AUC )
#if self.mdlPersosProxy:
#self.mdlPersosProxy.setSourceModel(self.mdlPersos)
#self.lstPersos.setModel(self.mdlPersosProxy)
#else:
#self.lstPersos.setModel(self.mdlPersos)
#self.tblPersoInfos.setModel(self.mdlPersosInfos)
#self.tblPersoInfos.setRowHidden(0, True)
2015-06-29 21:28:34 +12:00
self . btnPersoAddInfo . clicked . connect ( self . mdlPersos . addPersoInfo , AUC )
self . btnPersoRmInfo . clicked . connect ( self . mdlPersos . removePersoInfo , AUC )
2015-06-29 20:22:18 +12:00
#self.mprPersos = QDataWidgetMapper()
#self.mprPersos.setModel(self.mdlPersos)
#mapping = [
#(self.txtPersoName, Perso.name.value),
#(self.txtPersoMotivation, Perso.motivation.value),
#(self.txtPersoGoal, Perso.goal.value),
#(self.txtPersoConflict, Perso.conflict.value),
#(self.txtPersoEpiphany, Perso.epiphany.value),
#(self.txtPersoSummarySentance, Perso.summarySentance.value),
#(self.txtPersoSummaryPara, Perso.summaryPara.value),
#(self.txtPersoSummaryFull, Perso.summaryFull.value),
#(self.txtPersoNotes, Perso.notes.value)
#]
#for w, i in mapping:
#self.mprPersos.addMapping(w, i)
#self.mprPersos.addMapping(self.sldPersoImportance,
#Perso.importance.value, "importance")
#self.sldPersoImportance.importanceChanged.connect(self.mprPersos.submit, AUC)
#self.tabMain.currentChanged.connect(self.mprPersos.submit, AUC)
#self.mprPersos.setCurrentIndex(0)
for w , c in [
2015-06-22 06:00:03 +12:00
( self . txtPersoName , Perso . name . value ) ,
2015-06-29 20:22:18 +12:00
( self . sldPersoImportance , Perso . importance . value ) ,
2015-06-22 06:00:03 +12:00
( self . txtPersoMotivation , Perso . motivation . value ) ,
( self . txtPersoGoal , Perso . goal . value ) ,
( self . txtPersoConflict , Perso . conflict . value ) ,
( self . txtPersoEpiphany , Perso . epiphany . value ) ,
( self . txtPersoSummarySentance , Perso . summarySentance . value ) ,
( self . txtPersoSummaryPara , Perso . summaryPara . value ) ,
( self . txtPersoSummaryFull , Perso . summaryFull . value ) ,
( self . txtPersoNotes , Perso . notes . value )
2015-06-29 20:22:18 +12:00
] :
w . setModel ( self . mdlPersos )
w . setColumn ( c )
self . tabPersos . setEnabled ( False )
#self.lstPersos.selectionModel().currentChanged.connect(
#self.mdlPersos.updatePersoColor, AUC)
2015-06-29 09:46:51 +12:00
#self.tabPersos.currentChanged.connect(self.resizePersosInfos)
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
# Plots
2015-06-22 23:11:45 +12:00
self . lstPlots . setPlotModel ( self . mdlPlots )
self . lstPlotPerso . setModel ( self . mdlPlots )
self . lstSubPlots . setModel ( self . mdlPlots )
2015-06-23 07:07:38 +12:00
self . _updatingSubPlot = False
2015-06-25 01:43:35 +12:00
self . btnAddPlot . clicked . connect ( self . mdlPlots . addPlot , AUC )
2015-06-23 07:34:11 +12:00
self . btnRmPlot . clicked . connect ( lambda :
2015-06-25 01:43:35 +12:00
self . mdlPlots . removePlot ( self . lstPlots . currentPlotIndex ( ) ) , AUC )
self . btnAddSubPlot . clicked . connect ( self . mdlPlots . addSubPlot , AUC )
self . btnRmSubPlot . clicked . connect ( self . mdlPlots . removeSubPlot , AUC )
self . btnRmPlotPerso . clicked . connect ( self . mdlPlots . removePlotPerso , AUC )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
for w , c in [
( self . txtPlotName , Plot . name . value ) ,
( self . txtPlotDescription , Plot . description . value ) ,
( self . txtPlotResult , Plot . result . value ) ,
( self . sldPlotImportance , Plot . importance . value ) ,
] :
w . setModel ( self . mdlPlots )
w . setColumn ( c )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
self . tabPlot . setEnabled ( False )
2015-06-29 20:22:18 +12:00
self . mdlPlots . updatePlotPersoButton ( )
self . mdlPersos . dataChanged . connect ( self . mdlPlots . updatePlotPersoButton )
2015-06-23 06:30:43 +12:00
self . lstOutlinePlots . setPlotModel ( self . mdlPlots )
self . lstOutlinePlots . setShowSubPlot ( True )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
# Outline
self . treeRedacOutline . setModel ( self . mdlOutline )
self . treePlanOutline . setModelPersos ( self . mdlPersos )
self . treePlanOutline . setModelLabels ( self . mdlLabels )
self . treePlanOutline . setModelStatus ( self . mdlStatus )
2015-06-23 07:34:11 +12:00
self . redacMetadata . setModels ( self . mdlOutline , self . mdlPersos ,
self . mdlLabels , self . mdlStatus )
self . outlineItemEditor . setModels ( self . mdlOutline , self . mdlPersos ,
self . mdlLabels , self . mdlStatus )
2015-06-22 06:00:03 +12:00
self . treePlanOutline . setModel ( self . mdlOutline )
2015-06-28 00:06:35 +12:00
#self.redacEditor.setModel(self.mdlOutline)
2015-06-23 07:34:11 +12:00
self . treePlanOutline . selectionModel ( ) . selectionChanged . connect ( lambda :
2015-06-25 01:43:35 +12:00
self . outlineItemEditor . selectionChanged ( self . treePlanOutline ) , AUC )
2015-06-23 07:34:11 +12:00
self . treePlanOutline . clicked . connect ( lambda :
2015-06-25 01:43:35 +12:00
self . outlineItemEditor . selectionChanged ( self . treePlanOutline ) , AUC )
2015-06-30 00:21:57 +12:00
# Sync selection
#self.treeRedacOutline.setSelectionModel(self.treePlanOutline
#.selectionModel())
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
self . treeRedacOutline . selectionModel ( ) . selectionChanged . connect (
2015-06-25 01:43:35 +12:00
lambda : self . redacMetadata . selectionChanged ( self . treeRedacOutline ) , AUC )
2015-06-22 06:00:03 +12:00
self . treeRedacOutline . clicked . connect (
2015-06-25 01:43:35 +12:00
lambda : self . redacMetadata . selectionChanged ( self . treeRedacOutline ) , AUC )
2015-06-23 07:34:11 +12:00
2015-06-22 06:00:03 +12:00
#self.treeRedacOutline.selectionModel().currentChanged.connect(self.redacEditor.setCurrentModelIndex)
2015-06-28 00:06:35 +12:00
self . treeRedacOutline . selectionModel ( ) . selectionChanged . connect ( self . mainEditor . selectionChanged , AUC )
2015-06-30 00:21:57 +12:00
#self.treeRedacOutline.doubleClicked.connect(self.mainEditor.setCurrentModelIndex, AUC)
#self.treeRedacOutline.selectionModel().currentChanged.connect(self.mainEditor.setCurrentModelIndex, AUC)
2015-06-23 07:34:11 +12:00
2015-06-28 00:06:35 +12:00
#self.treeRedacOutline.selectionModel().selectionChanged.connect(self.outlineSelectionChanged, AUC)
2015-06-25 01:43:35 +12:00
#self.treeRedacOutline.selectionModel().selectionChanged.connect(self.outlineSelectionChanged, AUC)
#self.treePlanOutline.selectionModel().selectionChanged.connect(self.outlineSelectionChanged, AUC)
#self.treePlanOutline.selectionModel().selectionChanged.connect(self.outlineSelectionChanged, AUC)
2015-06-23 07:34:11 +12:00
2015-06-24 04:22:39 +12:00
#Debug
self . mdlFlatData . setVerticalHeaderLabels ( [ " Infos générales " , " Summary " ] )
self . tblDebugFlatData . setModel ( self . mdlFlatData )
self . tblDebugPersos . setModel ( self . mdlPersos )
2015-06-29 21:28:34 +12:00
self . tblDebugPersosInfos . setModel ( self . mdlPersos )
self . tblDebugPersos . selectionModel ( ) . currentChanged . connect (
lambda : self . tblDebugPersosInfos . setRootIndex ( self . mdlPersos . index (
self . tblDebugPersos . selectionModel ( ) . currentIndex ( ) . row ( ) ,
Perso . name . value ) ) , AUC )
2015-06-24 04:22:39 +12:00
self . tblDebugPlots . setModel ( self . mdlPlots )
self . tblDebugPlotsPersos . setModel ( self . mdlPlots )
self . tblDebugSubPlots . setModel ( self . mdlPlots )
self . tblDebugPlots . selectionModel ( ) . currentChanged . connect (
lambda : self . tblDebugPlotsPersos . setRootIndex ( self . mdlPlots . index (
self . tblDebugPlots . selectionModel ( ) . currentIndex ( ) . row ( ) ,
2015-06-25 01:43:35 +12:00
Plot . persos . value ) ) , AUC )
2015-06-24 04:22:39 +12:00
self . tblDebugPlots . selectionModel ( ) . currentChanged . connect (
lambda : self . tblDebugSubPlots . setRootIndex ( self . mdlPlots . index (
self . tblDebugPlots . selectionModel ( ) . currentIndex ( ) . row ( ) ,
2015-06-25 01:43:35 +12:00
Plot . subplots . value ) ) , AUC )
2015-06-24 04:22:39 +12:00
self . treeDebugOutline . setModel ( self . mdlOutline )
self . lstDebugLabels . setModel ( self . mdlLabels )
self . lstDebugStatus . setModel ( self . mdlStatus )
2015-06-29 21:28:34 +12:00
#self.mdlPersos.setHorizontalHeaderLabels([i.name for i in Perso])
2015-06-24 04:22:39 +12:00
2015-06-25 01:43:35 +12:00
2015-06-24 04:22:39 +12:00
###############################################################################
# GENERAL AKA UNSORTED
###############################################################################
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
def clickCycle ( self , i ) :
2015-06-23 07:34:11 +12:00
if i == 0 : # step 2 - paragraph summary
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 1 )
2015-06-23 07:34:11 +12:00
if i == 1 : # step 3 - characters summary
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 0 )
2015-06-23 07:34:11 +12:00
if i == 2 : # step 4 - page summary
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 2 )
2015-06-23 07:34:11 +12:00
if i == 3 : # step 5 - characters description
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 1 )
2015-06-23 07:34:11 +12:00
if i == 4 : # step 6 - four page synopsis
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 3 )
2015-06-23 07:34:11 +12:00
if i == 5 : # step 7 - full character charts
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 2 )
2015-06-23 07:34:11 +12:00
if i == 6 : # step 8 - scene list
2015-05-28 13:32:09 +12:00
self . tabMain . setCurrentIndex ( 3 )
2015-06-23 07:34:11 +12:00
2015-05-31 16:03:07 +12:00
def wordCount ( self , i ) :
2015-06-23 07:34:11 +12:00
src = {
0 : self . txtSummarySentance ,
1 : self . txtSummaryPara ,
2 : self . txtSummaryPage ,
3 : self . txtSummaryFull
2015-05-28 13:32:09 +12:00
} [ i ]
2015-06-23 07:34:11 +12:00
2015-05-28 13:32:09 +12:00
lbl = {
2015-06-23 07:34:11 +12:00
0 : self . lblSummaryWCSentance ,
1 : self . lblSummaryWCPara ,
2 : self . lblSummaryWCPage ,
3 : self . lblSummaryWCFull
2015-05-28 13:32:09 +12:00
} [ i ]
2015-06-23 07:34:11 +12:00
2015-06-05 06:22:37 +12:00
wc = wordCount ( src . toPlainText ( ) )
2015-06-23 07:34:11 +12:00
if i in [ 2 , 3 ] :
pages = self . tr ( " (~ {} pages) " ) . format ( int ( wc / 25 ) / 10. )
else :
pages = " "
2015-06-08 22:01:45 +12:00
lbl . setText ( self . tr ( " Words: {} {} " ) . format ( wc , pages ) )
2015-06-23 07:34:11 +12:00
2015-06-04 05:25:03 +12:00
def setupMoreUi ( self ) :
# Splitters
self . splitterPersos . setStretchFactor ( 0 , 25 )
self . splitterPersos . setStretchFactor ( 1 , 75 )
2015-06-23 07:34:11 +12:00
2015-06-04 05:25:03 +12:00
self . splitterPlot . setStretchFactor ( 0 , 20 )
2015-06-05 06:22:37 +12:00
self . splitterPlot . setStretchFactor ( 1 , 60 )
self . splitterPlot . setStretchFactor ( 2 , 30 )
2015-06-23 07:34:11 +12:00
2015-06-05 06:22:37 +12:00
self . splitterOutlineH . setStretchFactor ( 0 , 25 )
self . splitterOutlineH . setStretchFactor ( 1 , 75 )
self . splitterOutlineV . setStretchFactor ( 0 , 75 )
self . splitterOutlineV . setStretchFactor ( 1 , 25 )
2015-06-23 07:34:11 +12:00
2015-06-04 05:25:03 +12:00
self . splitterRedac . setStretchFactor ( 0 , 20 )
self . splitterRedac . setStretchFactor ( 1 , 60 )
self . splitterRedac . setStretchFactor ( 2 , 20 )
2015-06-29 21:28:34 +12:00
2015-06-04 05:25:03 +12:00
# Help box
references = [
( self . lytTabOverview ,
2015-06-21 21:29:35 +12:00
self . tr ( " Enter infos about your book, and yourself. " ) ,
0 ) ,
( self . lytSituation ,
self . tr ( " The basic situation, in the form of a ' What if...? ' question. Ex: ' What if the most dangerous evil wizard could wasn ' t abled to kill a baby? ' (Harry Potter) " ) ,
1 ) ,
( self . lytSummary ,
self . tr ( " Take time to think about a one sentance (~50 words) summary of your book. Then expand it to a paragraph, then to a page, then to a full summary. " ) ,
1 ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabPersos ,
2015-06-21 21:29:35 +12:00
self . tr ( " Create your characters. " ) ,
0 ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabPlot ,
2015-06-21 21:29:35 +12:00
self . tr ( " Develop plots. " ) ,
0 ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabOutline ,
2015-06-21 21:29:35 +12:00
self . tr ( " Create the outline of your masterpiece. " ) ,
0 ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabRedac ,
2015-06-21 21:29:35 +12:00
self . tr ( " Write. " ) ,
0 ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabDebug ,
2015-06-21 21:29:35 +12:00
self . tr ( " Debug infos. Sometimes useful. " ) ,
0 )
2015-06-04 05:25:03 +12:00
]
2015-06-21 21:29:35 +12:00
for widget , text , pos in references :
2015-06-25 06:32:50 +12:00
label = helpLabel ( text , self )
2015-06-25 01:43:35 +12:00
self . actShowHelp . toggled . connect ( label . setVisible , AUC )
2015-06-21 21:29:35 +12:00
widget . layout ( ) . insertWidget ( pos , label )
2015-06-23 07:34:11 +12:00
2015-06-07 05:10:44 +12:00
self . actShowHelp . setChecked ( False )
2015-06-23 07:34:11 +12:00
2015-06-07 05:10:44 +12:00
# Spellcheck
if enchant :
2015-06-08 22:01:45 +12:00
self . menuDict = QMenu ( self . tr ( " Dictionary " ) )
2015-06-07 05:10:44 +12:00
self . menuDictGroup = QActionGroup ( self )
2015-06-16 06:09:16 +12:00
self . updateMenuDict ( )
2015-06-07 05:10:44 +12:00
self . menuTools . addMenu ( self . menuDict )
2015-06-23 07:34:11 +12:00
2015-06-25 01:43:35 +12:00
self . actSpellcheck . toggled . connect ( self . toggleSpellcheck , AUC )
2015-06-28 00:06:35 +12:00
self . dictChanged . connect ( self . mainEditor . setDict , AUC )
2015-06-25 01:43:35 +12:00
self . dictChanged . connect ( self . redacMetadata . setDict , AUC )
self . dictChanged . connect ( self . outlineItemEditor . setDict , AUC )
2015-06-23 07:34:11 +12:00
2015-06-07 05:10:44 +12:00
else :
# No Spell check support
self . actSpellcheck . setVisible ( False )
2015-06-08 22:01:45 +12:00
a = QAction ( self . tr ( " Install PyEnchant to use spellcheck " ) , self )
2015-06-07 05:10:44 +12:00
a . setIcon ( self . style ( ) . standardIcon ( QStyle . SP_MessageBoxWarning ) )
2015-06-25 01:43:35 +12:00
a . triggered . connect ( self . openPyEnchantWebPage , AUC )
2015-06-07 05:10:44 +12:00
self . menuTools . addAction ( a )
2015-06-23 07:34:11 +12:00
2015-06-24 04:22:39 +12:00
###############################################################################
# SPELLCHECK
###############################################################################
2015-06-16 06:09:16 +12:00
def updateMenuDict ( self ) :
2015-06-23 07:34:11 +12:00
2015-06-16 18:15:24 +12:00
if not enchant :
return
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
self . menuDict . clear ( )
for i in enchant . list_dicts ( ) :
a = QAction ( str ( i [ 0 ] ) , self )
a . setCheckable ( True )
2015-06-23 07:34:11 +12:00
if settings . dict is None :
2015-06-16 06:09:16 +12:00
settings . dict = enchant . get_default_language ( )
if str ( i [ 0 ] ) == settings . dict :
a . setChecked ( True )
2015-06-30 00:21:57 +12:00
a . triggered . connect ( self . setDictionary , AUC )
2015-06-16 06:09:16 +12:00
self . menuDictGroup . addAction ( a )
self . menuDict . addAction ( a )
2015-06-23 07:34:11 +12:00
2015-06-07 05:10:44 +12:00
def setDictionary ( self ) :
2015-06-16 18:15:24 +12:00
if not enchant :
return
2015-06-23 07:34:11 +12:00
2015-06-07 05:10:44 +12:00
for i in self . menuDictGroup . actions ( ) :
if i . isChecked ( ) :
2015-06-30 00:21:57 +12:00
#self.dictChanged.emit(i.text().replace("&", ""))
2015-06-16 06:09:16 +12:00
settings . dict = i . text ( ) . replace ( " & " , " " )
2015-06-23 07:34:11 +12:00
2015-06-22 06:01:58 +12:00
# Find all textEditView from self, and toggle spellcheck
2015-06-23 07:34:11 +12:00
for w in self . findChildren ( textEditView , QRegExp ( " .* " ) ,
Qt . FindChildrenRecursively ) :
2015-06-22 06:01:58 +12:00
w . setDict ( settings . dict )
2015-06-07 05:10:44 +12:00
def openPyEnchantWebPage ( self ) :
2015-06-10 10:20:32 +12:00
QDesktopServices . openUrl ( QUrl ( " http://pythonhosted.org/pyenchant/ " ) )
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
def toggleSpellcheck ( self , val ) :
settings . spellcheck = val
2015-06-30 00:21:57 +12:00
#self.mainEditor.toggleSpellcheck(val)
#self.redacMetadata.toggleSpellcheck(val)
#self.outlineItemEditor.toggleSpellcheck(val)
2015-06-23 07:34:11 +12:00
2015-06-22 04:13:14 +12:00
# Find all textEditView from self, and toggle spellcheck
2015-06-23 07:34:11 +12:00
for w in self . findChildren ( textEditView , QRegExp ( " .* " ) ,
Qt . FindChildrenRecursively ) :
2015-06-22 04:13:14 +12:00
w . toggleSpellcheck ( val )
2015-06-23 07:34:11 +12:00
###############################################################################
# SETTINGS
###############################################################################
2015-06-10 10:20:32 +12:00
def settingsLabel ( self ) :
2015-06-18 06:45:24 +12:00
self . settingsWindow ( " Labels " )
2015-06-23 07:34:11 +12:00
2015-06-10 10:20:32 +12:00
def settingsStatus ( self ) :
2015-06-18 06:45:24 +12:00
self . settingsWindow ( " Status " )
2015-06-23 07:34:11 +12:00
2015-06-10 10:20:32 +12:00
def settingsWindow ( self , tab = None ) :
self . sw = settingsWindow ( self )
self . sw . hide ( )
self . sw . setWindowModality ( Qt . ApplicationModal )
self . sw . setWindowFlags ( Qt . Dialog )
r = self . sw . geometry ( )
r2 = self . geometry ( )
self . sw . move ( r2 . center ( ) - r . center ( ) )
if tab :
2015-06-18 06:45:24 +12:00
self . sw . setTab ( tab )
2015-06-10 10:20:32 +12:00
self . sw . show ( )
2015-06-23 07:34:11 +12:00
###############################################################################
# VIEW MENU
###############################################################################
def generateViewMenu ( self ) :
2015-06-16 06:09:16 +12:00
values = [
( self . tr ( " Nothing " ) , " Nothing " ) ,
( self . tr ( " POV " ) , " POV " ) ,
( self . tr ( " Label " ) , " Label " ) ,
( self . tr ( " Progress " ) , " Progress " ) ,
( self . tr ( " Compile " ) , " Compile " ) ,
]
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
menus = [
( self . tr ( " Tree " ) , " Tree " ) ,
( self . tr ( " Index cards " ) , " Cork " ) ,
( self . tr ( " Outline " ) , " Outline " )
]
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
submenus = {
" Tree " : [
( self . tr ( " Icon color " ) , " Icon " ) ,
( self . tr ( " Text color " ) , " Text " ) ,
( self . tr ( " Background color " ) , " Background " ) ,
] ,
" Cork " : [
( self . tr ( " Icon " ) , " Icon " ) ,
( self . tr ( " Text " ) , " Text " ) ,
( self . tr ( " Background " ) , " Background " ) ,
( self . tr ( " Border " ) , " Border " ) ,
( self . tr ( " Corner " ) , " Corner " ) ,
] ,
" Outline " : [
( self . tr ( " Icon color " ) , " Icon " ) ,
( self . tr ( " Text color " ) , " Text " ) ,
( self . tr ( " Background color " ) , " Background " ) ,
] ,
}
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
self . menuView . clear ( )
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
#print("Generating menus with", settings.viewSettings)
2015-06-23 07:34:11 +12:00
2015-06-16 06:09:16 +12:00
for mnu , mnud in menus :
m = QMenu ( mnu , self . menuView )
for s , sd in submenus [ mnud ] :
m2 = QMenu ( s , m )
agp = QActionGroup ( m2 )
for v , vd in values :
a = QAction ( v , m )
a . setCheckable ( True )
a . setData ( " {} , {} , {} " . format ( mnud , sd , vd ) )
if settings . viewSettings [ mnud ] [ sd ] == vd :
a . setChecked ( True )
2015-06-25 01:43:35 +12:00
a . triggered . connect ( self . setViewSettingsAction , AUC )
2015-06-16 06:09:16 +12:00
agp . addAction ( a )
m2 . addAction ( a )
m . addMenu ( m2 )
self . menuView . addMenu ( m )
2015-06-23 07:34:11 +12:00
2015-06-18 04:40:55 +12:00
def setViewSettingsAction ( self ) :
2015-06-16 06:09:16 +12:00
action = self . sender ( )
item , part , element = action . data ( ) . split ( " , " )
2015-06-18 04:40:55 +12:00
self . setViewSettings ( item , part , element )
2015-06-23 07:34:11 +12:00
2015-06-18 04:40:55 +12:00
def setViewSettings ( self , item , part , element ) :
2015-06-16 09:15:10 +12:00
settings . viewSettings [ item ] [ part ] = element
if item == " Cork " :
2015-06-28 00:06:35 +12:00
self . mainEditor . updateCorkView ( )
2015-06-18 03:15:13 +12:00
if item == " Outline " :
2015-06-28 00:06:35 +12:00
self . mainEditor . updateTreeView ( )
2015-06-18 03:15:13 +12:00
self . treePlanOutline . viewport ( ) . update ( )
if item == " Tree " :
self . treeRedacOutline . viewport ( ) . update ( )