Skip to content

Commit

Permalink
Improve UX: bad init window pos
Browse files Browse the repository at this point in the history
  • Loading branch information
krrr committed Dec 20, 2015
1 parent b1c69a3 commit 8db3b9e
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions hazama/ui/listview.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Main List and TagList, and their delegates.
"""
from PySide.QtGui import *
from PySide.QtCore import *
import logging
import random
from collections import OrderedDict
from PySide.QtGui import *
from PySide.QtCore import *
from hazama.ui import font, datetimeTrans, getDpiScaleRatio, makeQIcon
from hazama.ui.editor import Editor
from hazama.ui.customobjects import NTextDocument, MultiSortFilterProxyModel
Expand Down Expand Up @@ -483,7 +484,7 @@ def __init__(self, parent=None):
shortcut=QKeySequence(Qt.Key_F7), triggered=self.selectRandomly)
for i in [self.editAct, self.delAct, self.randAct]: self.addAction(i)
# setup editors
self.editors = {}
self.editors = OrderedDict() # diaryId => Editor, id of new diary is -1
self.doubleClicked.connect(self.startEditor)
self.activated.connect(self.startEditor)

Expand All @@ -505,30 +506,32 @@ def selectRandomly(self):

def startEditor(self):
dic = self._getNikkiDict(self.currentIndex())
_id = dic['id']
if _id in self.editors:
self.editors[_id].activateWindow()
id_ = dic['id']
if id_ in self.editors:
self.editors[id_].activateWindow()
else:
editor = Editor(nikkiDict=dic)
self.editors[_id] = editor
editor.closed.connect(self.closeEditor)
editor.preSc.activated.connect(lambda: self._editorMove(-1))
editor.nextSc.activated.connect(lambda: self._editorMove(1))
editor.show()
return _id
e = Editor(nikkiDict=dic)
self._setEditorStaggerPos(e)
self.editors[id_] = e
e.closed.connect(self.closeEditor)
e.preSc.activated.connect(lambda: self._editorMove(-1))
e.nextSc.activated.connect(lambda: self._editorMove(1))
e.show()
return id_

def startEditorNew(self):
if -1 in self.editors:
self.editors[-1].activateWindow()
else:
editor = Editor(nikkiDict={'id': -1})
self.editors[-1] = editor
editor.closed.connect(self.closeEditor)
editor.show()
e = Editor(nikkiDict={'id': -1})
self._setEditorStaggerPos(e)
self.editors[-1] = e
e.closed.connect(self.closeEditor)
e.show()

def closeEditor(self, id, needSave):
def closeEditor(self, id_, needSave):
"""Write editor's data to model and database, and destroy editor"""
editor = self.editors[id]
editor = self.editors[id_]
if needSave:
qApp.setOverrideCursor(QCursor(Qt.WaitCursor))
dic = editor.toNikkiDict()
Expand All @@ -542,11 +545,18 @@ def closeEditor(self, id, needSave):
self.setCurrentIndex(self.modelProxy.mapFromSource(
self.originModel.index(row, 0)))

if id == -1: self.countChanged.emit() # new diary
if id_ == -1: self.countChanged.emit() # new diary
if editor.tagModified: self.tagsChanged.emit()
qApp.restoreOverrideCursor()
editor.deleteLater()
del self.editors[id]
del self.editors[id_]

def _setEditorStaggerPos(self, editor):
if self.editors:
lastOpenEditor = list(self.editors.values())[-1]
pos = lastOpenEditor.pos() + QPoint(16, 16) * getDpiScaleRatio()
# can't check available screen space because of bug in pyside
editor.move(pos)

def load(self):
self.startLoading.emit()
Expand Down

0 comments on commit 8db3b9e

Please sign in to comment.