2015-05-28 13:32:09 +12:00
#!/usr/bin/env python
#--!-- coding: utf8 --!--
from __future__ import print_function
from __future__ import unicode_literals
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-06-04 12:04:47 +12:00
from ui . treeOutlineDelegates import *
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-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
dictChanged = pyqtSignal ( unicode )
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-02 10:06:17 +12:00
# Outline
self . mdlOutline = outlineModel ( )
self . treeRedacOutline . setModel ( self . mdlOutline )
self . treePlanOutline . setModel ( self . mdlOutline )
2015-06-04 12:04:47 +12:00
self . treePlanOutlinePersoDelegate = treeOutlinePersoDelegate ( self . mdlPersos )
self . treePlanOutline . setItemDelegateForColumn ( Outline . POV . value , self . treePlanOutlinePersoDelegate )
self . treePlanOutlineCompileDelegate = treeOutlineCompileDelegate ( )
self . treePlanOutline . setItemDelegateForColumn ( Outline . compile . value , self . treePlanOutlineCompileDelegate )
2015-06-04 12:51:37 +12:00
self . treePlanOutlineStatusDelegate = treeOutlineStatusDelegate ( )
self . treePlanOutline . setItemDelegateForColumn ( Outline . status . value , self . treePlanOutlineStatusDelegate )
2015-06-05 21:37:01 +12:00
self . treePlanOutlineGoalPercentageDelegate = treeOutlineGoalPercentageDelegate ( )
self . treePlanOutline . setItemDelegateForColumn ( Outline . goalPercentage . value , self . treePlanOutlineGoalPercentageDelegate )
2015-06-04 12:51:37 +12:00
2015-06-04 12:04:47 +12:00
self . cmbPlanPOV . setModels ( self . mdlPersos , self . mdlOutline )
2015-06-06 11:13:27 +12:00
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . title . value , QHeaderView . Stretch )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . POV . value , QHeaderView . ResizeToContents )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . status . value , QHeaderView . ResizeToContents )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . compile . value , QHeaderView . ResizeToContents )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . wordCount . value , QHeaderView . ResizeToContents )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . goal . value , QHeaderView . ResizeToContents )
self . treePlanOutline . header ( ) . setSectionResizeMode ( Outline . goalPercentage . value , QHeaderView . ResizeToContents )
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-02 10:06:17 +12:00
for c in range ( 1 , self . mdlOutline . columnCount ( ) ) :
self . treeRedacOutline . hideColumn ( c )
self . treePlanOutline . hideColumn ( c )
2015-06-05 06:22:37 +12:00
for c in [ Outline . POV . value , Outline . status . value , Outline . compile . value , Outline . wordCount . value , Outline . goal . value , Outline . goalPercentage . value ] :
2015-06-04 12:04:47 +12:00
self . treePlanOutline . showColumn ( c )
2015-06-05 06:22:37 +12:00
2015-06-02 10:06:17 +12:00
self . btnRedacAddFolder . clicked . connect ( lambda : self . outlineAddItem ( " folder " ) )
2015-06-04 12:04:47 +12:00
self . btnPlanAddFolder . clicked . connect ( lambda : self . outlineAddItem ( " folder " ) )
2015-06-02 10:06:17 +12:00
self . btnRedacAddScene . clicked . connect ( lambda : self . outlineAddItem ( " scene " ) )
2015-06-04 12:04:47 +12:00
self . btnPlanAddScene . clicked . connect ( lambda : self . outlineAddItem ( " scene " ) )
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-04 12:51:37 +12:00
self . cmbRedacStatus . setModel ( 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-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-06 11:13:27 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . redacEditor . setCurrentModelIndex )
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-06 11:32:52 +12:00
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . outlineSelectionChanged )
self . treeRedacOutline . selectionModel ( ) . currentChanged . connect ( self . outlineSelectionChanged )
self . treePlanOutline . selectionModel ( ) . currentChanged . connect ( self . outlineSelectionChanged )
self . treePlanOutline . selectionModel ( ) . currentChanged . connect ( self . outlineSelectionChanged )
2015-06-04 12:04:47 +12:00
2015-06-03 00:40:48 +12:00
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-05-31 16:03:07 +12:00
2015-06-07 00:21:48 +12:00
# Playing with qStyle
self . cmbStyle . addItems ( QStyleFactory . keys ( ) )
self . cmbStyle . setCurrentIndex ( [ i . lower ( ) for i in QStyleFactory . keys ( ) ] . index ( qApp . style ( ) . objectName ( ) ) )
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-06 11:32:52 +12:00
def outlineSelectionChanged ( self , idx ) :
if idx . isValid ( ) :
self . lblRedacPOV . setHidden ( idx . internalPointer ( ) . isFolder ( ) )
self . cmbRedacPOV . setHidden ( idx . internalPointer ( ) . isFolder ( ) )
self . lblPlanPOV . setHidden ( idx . internalPointer ( ) . isFolder ( ) )
self . cmbPlanPOV . setHidden ( idx . internalPointer ( ) . isFolder ( ) )
2015-06-02 10:06:17 +12:00
def outlineAddItem ( self , type = " folder " ) :
2015-06-03 00:44:04 +12:00
if len ( self . treeRedacOutline . selectedIndexes ( ) ) == 0 :
parent = QModelIndex ( )
else :
parent = self . treeRedacOutline . currentIndex ( )
2015-06-05 21:37:01 +12:00
item = outlineItem ( title = " Nouveau " , type = type )
2015-06-03 00:44:04 +12:00
self . mdlOutline . appendItem ( item , parent )
2015-06-02 10:06:17 +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-04 12:04:47 +12:00
def outlinePlanResizeTree ( self , * * kargs ) :
print ( " Coucou " )
stretch = Outline . title . value
w2 = 0
for c in range ( self . mdlOutline . columnCount ( ) ) :
if not self . treePlanOutline . isColumnHidden ( c ) and c < > stretch :
self . treePlanOutline . resizeColumnToContents ( c )
w2 + = self . treePlanOutline . columnWidth ( c )
w = self . treePlanOutline . viewport ( ) . width ( )
self . treePlanOutline . setColumnWidth ( stretch , w - w2 )
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-05-31 16:03:07 +12:00
p = QStandardItem ( " Nouveau perso " )
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 ( )
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-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-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-05-28 13:32:09 +12:00
if i in [ 2 , 3 ] : pages = " (~ {} pages) " . format ( int ( wc / 25 ) / 10. )
else : pages = " "
2015-06-04 05:25:03 +12:00
lbl . setText ( " Mots: {} {} " . format ( wc , pages ) )
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 ,
" Entrez toutes les informations relatives au livre, ainsi qu ' à vous. " ) ,
( self . lytTabSummary ,
" Prenez le temps de réfléchir à un résumé de votre livre, en une phrase. Puis augmentez cette phrase en un paragraphe, puis en une page, puis en un résumé complet. " ) ,
( self . lytTabPersos ,
" Créez ici vos personnage. " ) ,
( self . lytTabPlot ,
" Développez vos intrigues. " ) ,
( self . lytTabOutline ,
" Créez le plan de votre chef-d ' œuvre. " ) ,
( self . lytTabRedac ,
" Écrivez. " ) ,
( self . lytTabDebug ,
" Des infos pour débugger des fois pendant qu ' on code c ' est utile. " ) ,
]
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 :
self . menuDict = QMenu ( " Dictionary " )
self . menuDictGroup = QActionGroup ( self )
for i in enchant . list_dicts ( ) :
a = QAction ( unicode ( i [ 0 ] ) , self )
a . setCheckable ( True )
a . triggered . connect ( self . setDictionary )
if unicode ( i [ 0 ] ) == enchant . get_default_language ( ) : # "fr_CH"
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 )
a = QAction ( " Install PyEnchant to use spellcheck " , self )
a . setIcon ( self . style ( ) . standardIcon ( QStyle . SP_MessageBoxWarning ) )
a . triggered . connect ( self . openPyEnchantWebPage )
self . menuTools . addAction ( a )
def setDictionary ( self ) :
for i in self . menuDictGroup . actions ( ) :
if i . isChecked ( ) :
self . dictChanged . emit ( i . text ( ) . replace ( " & " , " " ) )
def openPyEnchantWebPage ( self ) :
QDesktopServices . openUrl ( QUrl ( " http://pythonhosted.org/pyenchant/ " ) )