2015-05-28 13:32:09 +12:00
#!/usr/bin/env python
#--!-- coding: utf8 --!--
2015-06-08 08:06:57 +12:00
2015-05-28 13:32:09 +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-04 17:08:49 +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-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-05-28 13:32:09 +12:00
class MainWindow ( QMainWindow , Ui_MainWindow ) :
2015-06-07 05:10:44 +12:00
2015-06-08 08:06:57 +12:00
dictChanged = pyqtSignal ( str )
2015-06-07 05:10:44 +12:00
2015-05-28 13:32:09 +12:00
def __init__ ( self ) :
QMainWindow . __init__ ( self )
self . setupUi ( self )
2015-05-31 16:03:07 +12:00
self . readSettings ( )
2015-05-29 05:15:57 +12:00
# UI
2015-06-04 05:25:03 +12:00
self . setupMoreUi ( )
2015-05-28 13:32:09 +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-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 )
self . mapperCycle . mapped . connect ( self . clickCycle )
2015-05-31 16:03:07 +12:00
# Données
self . mdlFlatData = QStandardItemModel ( 2 , 8 )
self . tblDebugFlatData . setModel ( self . mdlFlatData )
self . mprSummary = QDataWidgetMapper ( )
self . mprSummary . setModel ( self . mdlFlatData )
self . mprSummary . addMapping ( self . txtSummarySentance , 0 )
self . mprSummary . addMapping ( self . txtSummarySentance_2 , 0 )
self . mprSummary . addMapping ( self . txtSummaryPara , 1 )
self . mprSummary . addMapping ( self . txtSummaryPara_2 , 1 )
self . mprSummary . addMapping ( self . txtPlotSummaryPara , 1 )
self . mprSummary . addMapping ( self . txtSummaryPage , 2 )
self . mprSummary . addMapping ( self . txtSummaryPage_2 , 2 )
self . mprSummary . addMapping ( self . txtPlotSummaryPage , 2 )
self . mprSummary . addMapping ( self . txtSummaryFull , 3 )
self . mprSummary . addMapping ( self . txtPlotSummaryFull , 3 )
self . mprSummary . setCurrentIndex ( 1 )
self . mprInfos = QDataWidgetMapper ( )
self . mprInfos . setModel ( self . mdlFlatData )
self . mprInfos . addMapping ( self . txtGeneralTitle , 0 )
self . mprInfos . addMapping ( self . txtGeneralSubtitle , 1 )
self . mprInfos . addMapping ( self . txtGeneralSerie , 2 )
self . mprInfos . addMapping ( self . txtGeneralVolume , 3 )
self . mprInfos . addMapping ( self . txtGeneralGenre , 4 )
self . mprInfos . addMapping ( self . txtGeneralLicense , 5 )
self . mprInfos . addMapping ( self . txtGeneralAuthor , 6 )
self . mprInfos . addMapping ( self . txtGeneralEmail , 7 )
self . mprInfos . setCurrentIndex ( 0 )
# Persos
self . mdlPersos = QStandardItemModel ( 0 , 10 )
2015-06-04 17:08:49 +12:00
self . mdlPersosProxy = persosProxyModel ( )
2015-06-04 17:59:49 +12:00
#self.mdlPersoProxyFilter = QSortFilterProxyModel()
2015-06-04 17:08:49 +12:00
self . mdlPersosProxy . setSourceModel ( self . mdlPersos )
2015-06-01 08:41:32 +12:00
self . mdlPersosInfos = QStandardItemModel ( 1 , 0 )
2015-06-01 22:29:06 +12:00
self . mdlPersosInfos . insertColumn ( 0 , [ QStandardItem ( " ID " ) ] )
2015-05-31 16:03:07 +12:00
self . mdlPersosInfos . setHorizontalHeaderLabels ( [ " Description " ] )
2015-06-04 17:08:49 +12:00
#self.lstPersos.setModel(self.mdlPersos)
self . lstPersos . setModel ( self . mdlPersosProxy )
2015-05-31 16:03:07 +12:00
self . tblPersoInfos . setModel ( self . mdlPersosInfos )
2015-06-01 08:41:32 +12:00
self . tblPersoInfos . setRowHidden ( 0 , True )
2015-05-31 16:03:07 +12:00
self . btnAddPerso . clicked . connect ( self . createPerso )
self . btnRmPerso . clicked . connect ( self . removePerso )
self . btnPersoAddInfo . clicked . connect ( lambda : self . mdlPersosInfos . insertRow ( self . mdlPersosInfos . rowCount ( ) ) )
self . mprPersos = QDataWidgetMapper ( )
self . mprPersos . setModel ( self . mdlPersos )
mapping = [
2015-06-01 22:29:06 +12:00
( 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 ) ,
2015-06-02 10:06:17 +12:00
( self . txtPersoSummaryFull , Perso . summaryFull . value ) ,
( self . txtPersoNotes , Perso . notes . value )
2015-05-31 16:03:07 +12:00
]
2015-06-01 08:41:32 +12:00
for w , i in mapping :
self . mprPersos . addMapping ( w , i )
2015-06-01 22:29:06 +12:00
self . mprPersos . addMapping ( self . sldPersoImportance , Perso . importance . value , " importance " )
2015-05-31 16:03:07 +12:00
self . sldPersoImportance . importanceChanged . connect ( self . mprPersos . submit )
2015-06-05 21:37:01 +12:00
self . tabMain . currentChanged . connect ( self . mprPersos . submit )
2015-05-31 16:03:07 +12:00
self . mprPersos . setCurrentIndex ( 0 )
self . lstPersos . selectionModel ( ) . currentChanged . connect ( self . changeCurrentPerso )
2015-06-01 08:41:32 +12:00
self . tabPersos . currentChanged . connect ( self . resizePersosInfos )
2015-05-31 16:03:07 +12:00
2015-06-10 00:03:22 +12:00
# Labels
self . mdlLabels = QStandardItemModel ( )
for color , text in [
( Qt . transparent , " " ) ,
2015-06-11 01:57:44 +12:00
( Qt . yellow , self . tr ( " Idea " ) ) ,
( Qt . green , self . tr ( " Note " ) ) ,
( Qt . blue , self . tr ( " Chapter " ) ) ,
( Qt . red , self . tr ( " Scene " ) )
2015-06-10 00:03:22 +12:00
] :
2015-06-10 10:20:32 +12:00
self . mdlLabels . appendRow ( QStandardItem ( iconFromColor ( color ) , text ) )
2015-06-10 00:03:22 +12:00
2015-06-11 01:57:44 +12:00
# Status
self . mdlStatus = QStandardItemModel ( )
for text in [
" " ,
self . tr ( " TODO " ) ,
self . tr ( " First draft " ) ,
self . tr ( " Second draft " ) ,
self . tr ( " Final " )
] :
self . mdlStatus . appendRow ( QStandardItem ( text ) )
2015-06-02 10:06:17 +12:00
# Outline
self . mdlOutline = outlineModel ( )
self . treeRedacOutline . setModel ( self . mdlOutline )
2015-06-09 22:32:43 +12:00
self . treePlanOutline . setModelPersos ( self . mdlPersos )
2015-06-10 00:03:22 +12:00
self . treePlanOutline . setModelLabels ( self . mdlLabels )
2015-06-11 01:57:44 +12:00
self . treePlanOutline . setModelStatus ( self . mdlStatus )
2015-06-02 10:06:17 +12:00
self . treePlanOutline . setModel ( self . mdlOutline )
2015-06-04 12:04:47 +12:00
self . cmbPlanPOV . setModels ( self . mdlPersos , self . mdlOutline )
2015-06-11 05:45:42 +12:00
self . redacEditor . setModel ( self . mdlOutline )
2015-06-04 12:04:47 +12:00
self . mprPlan = QDataWidgetMapper ( )
self . mprPlan . setModel ( self . mdlOutline )
mapping = [
( self . txtPlanSummarySentance , Outline . summarySentance . value ) ,
2015-06-06 11:13:27 +12:00
( self . txtPlanSummaryFull , Outline . summaryFull . value ) ,
( self . txtOutlineGoal , Outline . setGoal . value )
2015-06-04 12:04:47 +12:00
]
for w , i in mapping :
self . mprPlan . addMapping ( w , i )
2015-06-05 06:22:37 +12:00
self . treePlanOutline . selectionModel ( ) . currentChanged . connect ( lambda idx : self . mprPlan . setRootIndex ( idx . parent ( ) ) )
2015-06-04 12:04:47 +12:00
self . treePlanOutline . selectionModel ( ) . currentChanged . connect ( self . mprPlan . setCurrentModelIndex )
self . treePlanOutline . selectionModel ( ) . currentChanged . connect ( self . cmbPlanPOV . setCurrentModelIndex )
2015-06-05 21:37:01 +12:00
self . tabMain . currentChanged . connect ( self . mprPlan . submit )
2015-06-04 12:51:37 +12:00
2015-06-02 10:06:17 +12:00
self . treeRedacOutline . setSelectionModel ( self . treePlanOutline . selectionModel ( ) )
2015-06-05 06:22:37 +12:00
2015-06-10 08:37:43 +12:00
self . btnRedacAddFolder . clicked . connect ( self . treeRedacOutline . addFolder )
self . btnPlanAddFolder . clicked . connect ( self . treePlanOutline . addFolder )
self . btnRedacAddScene . clicked . connect ( self . treeRedacOutline . addScene )
self . btnPlanAddScene . clicked . connect ( self . treePlanOutline . addScene )
2015-06-03 00:40:48 +12:00
self . btnRedacRemoveItem . clicked . connect ( self . outlineRemoveItems )
2015-06-04 12:04:47 +12:00
self . btnPlanRemoveItem . clicked . connect ( self . outlineRemoveItems )
self . cmbRedacPOV . setModels ( self . mdlPersos , self . mdlOutline )
2015-06-10 00:03:22 +12:00
self . cmbRedacLabel . setModels ( self . mdlLabels , self . mdlOutline )
2015-06-11 01:57:44 +12:00
self . cmbRedacStatus . setModels ( self . mdlStatus , self . mdlOutline )
2015-06-05 06:22:37 +12:00
#self.chkRedacCompile.setModel(self.mdlOutline)
2015-06-04 12:04:47 +12:00
self . mprOutline = QDataWidgetMapper ( )
self . mprOutline . setModel ( self . mdlOutline )
mapping = [
( self . txtRedacSummarySentance , Outline . summarySentance . value ) ,
( self . txtRedacSummaryFull , Outline . summaryFull . value ) ,
( self . txtRedacNotes , Outline . notes . value ) ,
2015-06-05 06:22:37 +12:00
( self . txtRedacTitle , Outline . title . value ) ,
2015-06-05 21:37:01 +12:00
( self . txtRedacGoal , Outline . setGoal . value )
2015-06-04 12:04:47 +12:00
]
for w , i in mapping :
self . mprOutline . addMapping ( w , i )
2015-06-05 06:22:37 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( lambda idx : self . mprOutline . setRootIndex ( idx . parent ( ) ) )
2015-06-04 12:04:47 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . mprOutline . setCurrentModelIndex )
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . cmbRedacPOV . setCurrentModelIndex )
2015-06-10 00:03:22 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . cmbRedacLabel . setCurrentModelIndex )
2015-06-04 12:51:37 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . cmbRedacStatus . setCurrentModelIndex )
2015-06-05 06:22:37 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . chkRedacCompile . setCurrentModelIndex )
2015-06-11 05:45:42 +12:00
#self.treeRedacOutline.selectionModel().currentChanged.connect(self.redacEditor.setCurrentModelIndex)
self . treeRedacOutline . selectionModel ( ) . selectionChanged . connect ( self . redacEditor . setView )
2015-06-07 05:10:44 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . redacEditor . txtRedacText . setCurrentModelIndex )
2015-06-05 21:37:01 +12:00
self . tabMain . currentChanged . connect ( self . mprOutline . submit )
2015-06-05 06:22:37 +12:00
2015-06-11 05:45:42 +12:00
self . treeRedacOutline . selectionModel ( ) . selectionChanged . connect ( self . outlineSelectionChanged )
self . treeRedacOutline . selectionModel ( ) . selectionChanged . connect ( self . outlineSelectionChanged )
self . treePlanOutline . selectionModel ( ) . selectionChanged . connect ( self . outlineSelectionChanged )
self . treePlanOutline . selectionModel ( ) . selectionChanged . connect ( self . outlineSelectionChanged )
2015-06-04 12:04:47 +12:00
2015-06-09 09:36:15 +12:00
self . sldCorkSizeFactor . valueChanged . connect ( self . redacEditor . setCorkSizeFactor )
self . btnRedacFolderCork . toggled . connect ( self . sldCorkSizeFactor . setVisible )
2015-06-09 22:32:43 +12:00
self . btnRedacFolderText . clicked . connect ( lambda v : self . redacEditor . setFolderView ( " text " ) )
self . btnRedacFolderCork . clicked . connect ( lambda v : self . redacEditor . setFolderView ( " cork " ) )
self . btnRedacFolderOutline . clicked . connect ( lambda v : self . redacEditor . setFolderView ( " outline " ) )
2015-06-03 00:40:48 +12:00
2015-06-10 10:20:32 +12:00
# Main Menu
self . actLabels . triggered . connect ( self . settingsLabel )
self . actStatus . triggered . connect ( self . settingsStatus )
self . actQuit . triggered . connect ( self . close )
2015-05-31 16:03:07 +12:00
#Debug
self . mdlFlatData . setVerticalHeaderLabels ( [ " Infos générales " , " Summary " ] )
self . tblDebugFlatData . setModel ( self . mdlFlatData )
2015-06-01 22:29:06 +12:00
self . tblDebugPersos . setModel ( self . mdlPersos )
self . tblDebugPersosInfos . setModel ( self . mdlPersosInfos )
2015-06-02 10:06:17 +12:00
self . treeDebugOutline . setModel ( self . mdlOutline )
2015-06-10 00:03:22 +12:00
self . lstDebugLabels . setModel ( self . mdlLabels )
2015-06-11 01:57:44 +12:00
self . lstDebugStatus . setModel ( self . mdlStatus )
2015-05-31 16:03:07 +12:00
2015-06-07 00:21:48 +12:00
# Playing with qStyle
2015-06-08 08:06:57 +12:00
self . cmbStyle . addItems ( list ( QStyleFactory . keys ( ) ) )
self . cmbStyle . setCurrentIndex ( [ i . lower ( ) for i in list ( QStyleFactory . keys ( ) ) ] . index ( qApp . style ( ) . objectName ( ) ) )
2015-06-07 00:21:48 +12:00
self . cmbStyle . currentIndexChanged [ str ] . connect ( qApp . setStyle )
2015-05-31 16:03:07 +12:00
self . loadProject ( " test_project " )
2015-06-02 10:06:17 +12:00
####################################################################################################
# OUTLINE #
####################################################################################################
2015-06-11 05:45:42 +12:00
def outlineSelectionChanged ( self ) :
if len ( self . treeRedacOutline . selectionModel ( ) . selection ( ) . indexes ( ) ) == 0 :
hidden = False
else :
idx = self . treeRedacOutline . currentIndex ( )
if idx . isValid ( ) :
hidden = not idx . internalPointer ( ) . isFolder ( )
else :
hidden = False
self . btnRedacFolderText . setHidden ( hidden )
self . btnRedacFolderCork . setHidden ( hidden )
self . btnRedacFolderOutline . setHidden ( hidden )
self . sldCorkSizeFactor . setHidden ( hidden )
2015-06-06 11:32:52 +12:00
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-02 10:06:17 +12:00
2015-06-01 08:41:32 +12:00
####################################################################################################
# PERSOS #
####################################################################################################
2015-05-31 16:03:07 +12:00
def createPerso ( self ) :
2015-06-01 08:41:32 +12:00
" Creates a perso by adding a row in mdlPersos and a column in mdlPersosInfos with same ID "
2015-06-08 22:01:45 +12:00
p = QStandardItem ( self . tr ( " New character " ) )
2015-06-01 08:41:32 +12:00
self . mdlPersos . appendRow ( p )
pid = self . getPersosID ( )
self . checkPersosID ( ) # Attributes a persoID (which is logically pid)
# Add column in persos infos
self . mdlPersosInfos . insertColumn ( self . mdlPersosInfos . columnCount ( ) , [ QStandardItem ( pid ) ] )
2015-05-31 16:03:07 +12:00
self . mdlPersosInfos . setHorizontalHeaderItem ( self . mdlPersosInfos . columnCount ( ) - 1 , QStandardItem ( " Valeur " ) )
2015-06-01 08:41:32 +12:00
def getPersosID ( self ) :
" Returns an unused perso ID (row 1) "
vals = [ ]
for i in range ( self . mdlPersos . rowCount ( ) ) :
2015-06-01 22:29:06 +12:00
item = self . mdlPersos . item ( i , Perso . ID . value )
2015-06-01 08:41:32 +12:00
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 "
empty = [ ]
for i in range ( self . mdlPersos . rowCount ( ) ) :
2015-06-01 22:29:06 +12:00
item = self . mdlPersos . item ( i , Perso . ID . value )
2015-06-01 08:41:32 +12:00
if not item :
item = QStandardItem ( )
item . setText ( self . getPersosID ( ) )
2015-06-01 22:29:06 +12:00
self . mdlPersos . setItem ( i , Perso . ID . value , item )
2015-05-31 16:03:07 +12:00
def removePerso ( self ) :
2015-06-04 17:08:49 +12:00
i = self . mdlPersosProxy . mapToSource ( self . lstPersos . currentIndex ( ) )
2015-05-31 16:03:07 +12:00
self . mdlPersos . takeRow ( i . row ( ) )
self . mdlPersosInfos . takeColumn ( i . row ( ) + 1 )
2015-06-01 08:41:32 +12:00
def changeCurrentPerso ( self , trash = None ) :
2015-06-04 17:08:49 +12:00
idx = self . mdlPersosProxy . mapToSource ( self . lstPersos . currentIndex ( ) )
self . mprPersos . setCurrentModelIndex ( idx )
2015-06-01 22:29:06 +12:00
pid = self . mdlPersos . item ( idx . row ( ) , Perso . ID . value ) . text ( )
2015-06-01 08:48:27 +12:00
for c in range ( self . mdlPersosInfos . columnCount ( ) ) :
pid2 = self . mdlPersosInfos . item ( 0 , c ) . text ( )
2015-06-08 08:06:57 +12:00
self . tblPersoInfos . setColumnHidden ( c , c != 0 and pid != pid2 )
2015-05-31 16:03:07 +12:00
2015-06-01 08:41:32 +12:00
self . resizePersosInfos ( )
def resizePersosInfos ( self ) :
self . tblPersoInfos . resizeColumnToContents ( 0 )
w = self . tblPersoInfos . viewport ( ) . width ( )
w2 = self . tblPersoInfos . columnWidth ( 0 )
2015-06-04 17:08:49 +12:00
current = self . mdlPersosProxy . mapToSource ( self . lstPersos . currentIndex ( ) ) . row ( ) + 1
2015-06-01 08:41:32 +12:00
self . tblPersoInfos . setColumnWidth ( current , w - w2 )
####################################################################################################
# GENERAL #
####################################################################################################
def loadProject ( self , project ) :
self . currentProject = project
loadStandardItemModelXML ( self . mdlFlatData , " {} /flatModel.xml " . format ( project ) )
loadStandardItemModelXML ( self . mdlPersos , " {} /perso.xml " . format ( project ) )
loadStandardItemModelXML ( self . mdlPersosInfos , " {} /persoInfos.xml " . format ( project ) )
2015-06-10 00:03:22 +12:00
loadStandardItemModelXML ( self . mdlLabels , " {} /labels.xml " . format ( project ) )
2015-06-11 01:57:44 +12:00
loadStandardItemModelXML ( self . mdlStatus , " {} /status.xml " . format ( project ) )
2015-06-04 04:40:19 +12:00
self . mdlOutline . loadFromXML ( " {} /outline.xml " . format ( project ) )
2015-06-01 08:41:32 +12:00
# Stuff
self . checkPersosID ( )
2015-06-01 22:29:06 +12:00
# Adds header labels
self . mdlPersos . setHorizontalHeaderLabels (
[ i . name for i in Perso ] )
2015-06-01 08:41:32 +12:00
2015-05-31 16:03:07 +12:00
def readSettings ( self ) :
# Load State and geometry
settings = QSettings ( qApp . organizationName ( ) , qApp . applicationName ( ) )
2015-06-04 04:40:19 +12:00
self . restoreGeometry ( settings . value ( " geometry " ) )
self . restoreState ( settings . value ( " windowState " ) )
2015-05-31 16:03:07 +12:00
def closeEvent ( self , event ) :
# Save State and geometry
settings = QSettings ( qApp . organizationName ( ) , qApp . applicationName ( ) )
settings . setValue ( " geometry " , self . saveGeometry ( ) )
settings . setValue ( " windowState " , self . saveState ( ) )
# Save data from models
saveStandardItemModelXML ( self . mdlFlatData , " {} /flatModel.xml " . format ( self . currentProject ) )
saveStandardItemModelXML ( self . mdlPersos , " {} /perso.xml " . format ( self . currentProject ) )
saveStandardItemModelXML ( self . mdlPersosInfos , " {} /persoInfos.xml " . format ( self . currentProject ) )
2015-06-10 00:03:22 +12:00
saveStandardItemModelXML ( self . mdlLabels , " {} /labels.xml " . format ( self . currentProject ) )
2015-06-11 01:57:44 +12:00
saveStandardItemModelXML ( self . mdlStatus , " {} /status.xml " . format ( self . currentProject ) )
2015-06-04 04:40:19 +12:00
self . mdlOutline . saveToXML ( " {} /outline.xml " . format ( self . currentProject ) )
2015-05-31 16:03:07 +12:00
# closeEvent
QMainWindow . closeEvent ( self , event )
2015-05-28 13:32:09 +12:00
def clickCycle ( self , i ) :
if i == 0 : # step 2 - paragraph summary
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 1 )
if i == 1 : # step 3 - characters summary
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 0 )
if i == 2 : # step 4 - page summary
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 2 )
if i == 3 : # step 5 - characters description
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 1 )
if i == 4 : # step 6 - four page synopsis
self . tabMain . setCurrentIndex ( 1 )
self . tabSummary . setCurrentIndex ( 3 )
if i == 5 : # step 7 - full character charts
self . tabMain . setCurrentIndex ( 2 )
self . tabPersos . setCurrentIndex ( 2 )
if i == 6 : # step 8 - scene list
self . tabMain . setCurrentIndex ( 3 )
2015-05-31 16:03:07 +12:00
def wordCount ( self , i ) :
src = {
0 : self . txtSummarySentance ,
1 : self . txtSummaryPara ,
2 : self . txtSummaryPage ,
3 : self . txtSummaryFull
2015-05-28 13:32:09 +12:00
} [ i ]
lbl = {
0 : self . lblSummaryWCSentance ,
1 : self . lblSummaryWCPara ,
2 : self . lblSummaryWCPage ,
3 : self . lblSummaryWCFull
} [ i ]
2015-06-05 06:22:37 +12:00
wc = wordCount ( src . toPlainText ( ) )
2015-06-08 22:01:45 +12:00
if i in [ 2 , 3 ] : pages = self . tr ( " (~ {} pages) " ) . format ( int ( wc / 25 ) / 10. )
2015-05-28 13:32:09 +12:00
else : pages = " "
2015-06-08 22:01:45 +12:00
lbl . setText ( self . tr ( " Words: {} {} " ) . format ( wc , pages ) )
2015-06-04 05:25:03 +12:00
def setupMoreUi ( self ) :
# Splitters
self . splitterPersos . setStretchFactor ( 0 , 25 )
self . splitterPersos . setStretchFactor ( 1 , 75 )
self . splitterPlot . setStretchFactor ( 0 , 20 )
2015-06-05 06:22:37 +12:00
self . splitterPlot . setStretchFactor ( 1 , 60 )
self . splitterPlot . setStretchFactor ( 2 , 30 )
self . splitterOutlineH . setStretchFactor ( 0 , 25 )
self . splitterOutlineH . setStretchFactor ( 1 , 75 )
self . splitterOutlineV . setStretchFactor ( 0 , 75 )
self . splitterOutlineV . setStretchFactor ( 1 , 25 )
2015-06-04 05:25:03 +12:00
self . splitterRedac . setStretchFactor ( 0 , 20 )
self . splitterRedac . setStretchFactor ( 1 , 60 )
self . splitterRedac . setStretchFactor ( 2 , 20 )
# Help box
references = [
( self . lytTabOverview ,
2015-06-08 22:01:45 +12:00
self . tr ( " Enter infos about your book, and yourself. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabSummary ,
2015-06-08 22:01:45 +12:00
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. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabPersos ,
2015-06-08 22:01:45 +12:00
self . tr ( " Create your characters. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabPlot ,
2015-06-08 22:01:45 +12:00
self . tr ( " Develop plots. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabOutline ,
2015-06-08 22:01:45 +12:00
self . tr ( " Create the outline of your masterpiece. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabRedac ,
2015-06-08 22:01:45 +12:00
self . tr ( " Write. " ) ) ,
2015-06-04 05:25:03 +12:00
( self . lytTabDebug ,
2015-06-08 22:01:45 +12:00
self . tr ( " Debug infos. Sometimes useful. " ) , )
2015-06-04 05:25:03 +12:00
]
for widget , text in references :
label = helpLabel ( text )
self . actShowHelp . toggled . connect ( label . setVisible )
widget . layout ( ) . insertWidget ( 0 , label )
2015-06-07 05:10:44 +12:00
self . actShowHelp . setChecked ( False )
# 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 )
for i in enchant . list_dicts ( ) :
2015-06-08 08:06:57 +12:00
a = QAction ( str ( i [ 0 ] ) , self )
2015-06-07 05:10:44 +12:00
a . setCheckable ( True )
a . triggered . connect ( self . setDictionary )
2015-06-08 08:06:57 +12:00
if str ( i [ 0 ] ) == enchant . get_default_language ( ) : # "fr_CH"
2015-06-07 05:10:44 +12:00
a . setChecked ( True )
self . menuDictGroup . addAction ( a )
self . menuDict . addAction ( a )
self . menuTools . addMenu ( self . menuDict )
self . actSpellcheck . toggled . connect ( self . redacEditor . toggleSpellcheck )
self . dictChanged . connect ( self . redacEditor . setDict )
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 ) )
a . triggered . connect ( self . openPyEnchantWebPage )
self . menuTools . addAction ( a )
2015-06-07 08:39:43 +12:00
self . btnRedacFullscreen . clicked . connect ( self . redacEditor . showFullscreen )
2015-06-07 05:10:44 +12:00
def setDictionary ( self ) :
for i in self . menuDictGroup . actions ( ) :
if i . isChecked ( ) :
self . dictChanged . emit ( i . text ( ) . replace ( " & " , " " ) )
def openPyEnchantWebPage ( self ) :
2015-06-10 10:20:32 +12:00
QDesktopServices . openUrl ( QUrl ( " http://pythonhosted.org/pyenchant/ " ) )
####################################################################################################
# SETTINGS #
####################################################################################################
def settingsLabel ( self ) :
self . settingsWindow ( 0 )
def settingsStatus ( self ) :
self . settingsWindow ( 1 )
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 :
self . sw . tabWidget . setCurrentIndex ( tab )
self . sw . show ( )