2015-06-10 10:20:32 +12:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#--!-- coding: utf8 --!--
|
|
|
|
|
|
|
|
from qt import *
|
|
|
|
|
|
|
|
from ui.settings import *
|
|
|
|
from enums import *
|
|
|
|
from functions import *
|
2015-06-17 19:33:25 +12:00
|
|
|
import settings
|
2015-06-10 10:20:32 +12:00
|
|
|
# Spell checker support
|
|
|
|
try:
|
|
|
|
import enchant
|
|
|
|
except ImportError:
|
|
|
|
enchant = None
|
|
|
|
|
|
|
|
class settingsWindow(QWidget, Ui_Settings):
|
|
|
|
|
|
|
|
def __init__(self, mainWindow):
|
|
|
|
QWidget.__init__(self)
|
|
|
|
self.setupUi(self)
|
|
|
|
|
|
|
|
self.mw = mainWindow
|
|
|
|
|
2015-06-17 19:33:25 +12:00
|
|
|
# General
|
|
|
|
self.cmbStyle.addItems(list(QStyleFactory.keys()))
|
|
|
|
self.cmbStyle.setCurrentIndex([i.lower() for i in list(QStyleFactory.keys())].index(qApp.style().objectName()))
|
|
|
|
self.cmbStyle.currentIndexChanged[str].connect(self.setStyle)
|
|
|
|
|
|
|
|
self.txtAutoSave.setValidator(QIntValidator(0, 999, self))
|
|
|
|
self.chkAutoSave.setChecked(settings.autoSave)
|
|
|
|
self.txtAutoSave.setText(str(settings.autoSaveDelay))
|
|
|
|
self.chkSaveOnQuit.setChecked(settings.saveOnQuit)
|
|
|
|
self.chkAutoSave.stateChanged.connect(self.saveSettingsChanged)
|
|
|
|
self.chkSaveOnQuit.stateChanged.connect(self.saveSettingsChanged)
|
|
|
|
self.txtAutoSave.textEdited.connect(self.saveSettingsChanged)
|
|
|
|
|
2015-06-10 10:20:32 +12:00
|
|
|
# Labels
|
|
|
|
self.lstLabels.setModel(self.mw.mdlLabels)
|
|
|
|
self.lstLabels.setRowHidden(0, True)
|
|
|
|
self.lstLabels.clicked.connect(self.updateLabelColor)
|
|
|
|
self.btnLabelAdd.clicked.connect(self.addLabel)
|
|
|
|
self.btnLabelRemove.clicked.connect(self.removeLabel)
|
|
|
|
self.btnLabelColor.clicked.connect(self.setLabelColor)
|
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
# Statuses
|
|
|
|
self.lstStatus.setModel(self.mw.mdlStatus)
|
|
|
|
self.lstStatus.setRowHidden(0, True)
|
|
|
|
self.btnStatusAdd.clicked.connect(self.addStatus)
|
|
|
|
self.btnStatusRemove.clicked.connect(self.removeStatus)
|
|
|
|
|
2015-06-17 19:33:25 +12:00
|
|
|
def setStyle(self, style):
|
|
|
|
#Save style to Qt Settings
|
|
|
|
settings = QSettings(qApp.organizationName(), qApp.applicationName())
|
|
|
|
settings.setValue("applicationStyle", style)
|
|
|
|
qApp.setStyle(style)
|
|
|
|
|
|
|
|
def saveSettingsChanged(self):
|
|
|
|
if self.txtAutoSave.text() in ["", "0"]:
|
|
|
|
self.txtAutoSave.setText("1")
|
|
|
|
settings.autoSave = True if self.chkAutoSave.checkState() else False
|
|
|
|
settings.saveOnQuit = True if self.chkSaveOnQuit.checkState() else False
|
|
|
|
settings.autoSaveDelay = int(self.txtAutoSave.text())
|
2015-06-17 22:00:03 +12:00
|
|
|
self.mw.saveTimer.setInterval(settings.autoSaveDelay * 60 * 1000)
|
2015-06-17 19:33:25 +12:00
|
|
|
|
2015-06-11 01:57:44 +12:00
|
|
|
def addStatus(self):
|
|
|
|
self.mw.mdlStatus.appendRow(QStandardItem(self.tr("New status")))
|
|
|
|
|
|
|
|
def removeStatus(self):
|
|
|
|
for i in self.lstStatus.selectedIndexes():
|
|
|
|
self.mw.mdlStatus.removeRows(i.row(), 1)
|
|
|
|
|
2015-06-10 10:20:32 +12:00
|
|
|
def updateLabelColor(self, index):
|
|
|
|
px = QPixmap(64, 64)
|
|
|
|
px.fill(iconColor(self.mw.mdlLabels.item(index.row()).icon()))
|
|
|
|
self.btnLabelColor.setIcon(QIcon(px))
|
|
|
|
self.btnLabelColor.setEnabled(True)
|
|
|
|
|
|
|
|
def addLabel(self):
|
|
|
|
px = QPixmap(32, 32)
|
|
|
|
px.fill(Qt.transparent)
|
|
|
|
self.mw.mdlLabels.appendRow(QStandardItem(QIcon(px), self.tr("New label")))
|
|
|
|
|
|
|
|
def removeLabel(self):
|
|
|
|
for i in self.lstLabels.selectedIndexes():
|
|
|
|
self.mw.mdlLabels.removeRows(i.row(), 1)
|
|
|
|
|
|
|
|
def setLabelColor(self):
|
|
|
|
index = self.lstLabels.currentIndex()
|
|
|
|
color = iconColor(self.mw.mdlLabels.item(index.row()).icon())
|
|
|
|
self.colorDialog = QColorDialog(color, self)
|
|
|
|
color = self.colorDialog.getColor(color)
|
|
|
|
px = QPixmap(32, 32)
|
|
|
|
px.fill(color)
|
|
|
|
self.mw.mdlLabels.item(index.row()).setIcon(QIcon(px))
|
|
|
|
|