finished animation feature, rearranged buttons and cleaned up the code

This commit is contained in:
Stefan Kögl 2014-04-22 11:10:08 +02:00
parent 0086d0fd8f
commit 007ec565e1
6 changed files with 748 additions and 816 deletions

View File

@ -35,7 +35,8 @@ for path in QtGui.QIcon.themeSearchPaths():
print "%s/%s" % (path, QtGui.QIcon.themeName()) print "%s/%s" % (path, QtGui.QIcon.themeName())
# NOTE: if the QIcon.fromTheme method does not find any icons, you can set a theme # NOTE: if the QIcon.fromTheme method does not find any icons, you can use
# qtconfig and set a default theme or copy|symlink an existing theme dir to hicolor
# in your local icon directory: # in your local icon directory:
# ln -s /your/icon/theme/directory $HOME/.icons/hicolor # ln -s /your/icon/theme/directory $HOME/.icons/hicolor
@ -95,12 +96,14 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog):
return True return True
def slot_show_text(self, model_index): def slot_show_text(self, model_index):
try:
self.text_preview.setTextOrHtml(self.parent().parent().model.text_db[model_index.row()][1]) self.text_preview.setTextOrHtml(self.parent().parent().model.text_db[model_index.row()][1])
except IndexError:
pass
def slot_removeItem(self): def slot_removeItem(self):
index = self.text_list.currentIndex().row() index = self.text_list.currentIndex().row()
print "remote index", index
self.model.removeRows(index, 1) self.model.removeRows(index, 1)
index = self.model.index(0, 0) index = self.model.index(0, 0)
self.text_list.setCurrentIndex(index) self.text_list.setCurrentIndex(index)
@ -114,84 +117,83 @@ class TextAnimation(QtCore.QObject):
def __init__(self, parent=None): def __init__(self, parent=None):
super(TextAnimation, self).__init__(parent) super(TextAnimation, self).__init__(parent)
self.animated_document = None self.src_text_edit = None
self.cursor_position = 0 self.cursor_position = 0
self.src_cursor = None self.src_cursor = None
self.area = None self.dst_text_edit = None
self.dst_cursor = None self.dst_cursor = None
self.src_block = None
self.fragment_iter = None
self.text = None self.text = None
self.it = None self.it = None
self.timer = None self.timer = None
self.dst_current_block = None self.dst_current_block = None
self.fonts = dict()
self.count = 0
def start_animation(self, animated_document, area, cursor_position): def start_animation(self, src_text_edit, dst_text_edit, cursor_position):
print "start_animation", animated_document, area, cursor_position
if self.timer is not None: if self.timer is not None:
print "timer is not None"
return False return False
self.animated_document = animated_document self.parent().slot_clear_live()
self.area = area self.src_document = QtGui.QTextDocument(self)
self.src_document.setHtml(src_text_edit.document().toHtml())
self.src_text_edit = src_text_edit
self.dst_text_edit = dst_text_edit
self.cursor_position = cursor_position self.cursor_position = cursor_position
self.src_cursor = QtGui.QTextCursor(self.animated_document) self.dst_cursor = self.dst_text_edit.textCursor()
self.src_cursor.setPosition(0)
self.dst_cursor = self.area.textCursor()
self.dst_cursor.setPosition(self.cursor_position) self.dst_cursor.setPosition(self.cursor_position)
self.timer = QtCore.QTimer(self) self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.slot_animate) self.timer.timeout.connect(self.slot_animate)
parent = self.parent() self.parent().slot_clear_live()
parent.slot_clear_live() self.timer.start(55)
#self.dst_cursor.setPosition(self.cursor_position)
self.timer.start(70)
print "timer started"
return True return True
def slot_animate(self): def slot_animate(self):
print "slot_animate"
self.animation_started.emit() self.animation_started.emit()
parent = self.parent() parent = self.parent()
if self.it is None: if self.it is None:
self.it = self.animated_document.rootFrame().begin() src_root_frame = self.src_document.rootFrame()
#self.src_block = self.it.currentBlock() self.it = src_root_frame.begin()
#area_rootFrame = self.area.document().rootFrame() self.dst_text_edit.document().rootFrame().setFrameFormat(src_root_frame.frameFormat())
#area_rootFrame.setFrameFormat(rootFrame.frameFormat())
#print "it is none", repr(self.src_block.text())
if not self.it.atEnd(): if not self.it.atEnd():
if self.text is None: if self.src_block is None:
self.src_block = self.it.currentBlock() self.src_block = self.it.currentBlock()
text = unicode(self.src_block.text()) self.fragment_iter = self.src_block.begin()
print "text", repr(text)
self.text = iter(text)
src_block_format = self.src_block.blockFormat() src_block_format = self.src_block.blockFormat()
src_char_format = self.src_block.charFormat()
if self.dst_current_block is not None: if self.dst_current_block is not None:
print "insert new block"
self.dst_cursor.insertBlock(src_block_format) self.dst_cursor.insertBlock(src_block_format)
self.dst_current_block = self.dst_current_block.next() self.dst_current_block = self.dst_current_block.next()
else: else:
self.dst_current_block = self.dst_cursor.block() self.dst_current_block = self.dst_cursor.block()
dst_char_format = self.dst_current_block.charFormat() self.dst_cursor.setBlockFormat(src_block_format)
src_char_format = self.src_block.charFormat() self.dst_cursor.setBlockCharFormat(src_char_format)
src_font_point_size = src_char_format.fontPointSize() self.dst_cursor.setCharFormat(src_char_format)
dst_char_format.setFontPointSize(src_font_point_size)
print "src font size", src_font_point_size self.dst_cursor.mergeBlockCharFormat(src_char_format)
parent.default_size = src_font_point_size self.dst_cursor.mergeCharFormat(src_char_format)
parent.font.setPointSize(parent.default_size) self.dst_cursor.mergeBlockFormat(src_block_format)
parent.live_text.setFontSize(parent.default_size)
parent.live_text.setFont(parent.font) if not self.fragment_iter.atEnd():
parent.live_size_action.setFontSize(parent.default_size) if self.text is None:
#parent.live_text.document().setDefaultFont(parent.font) fragment = self.fragment_iter.fragment()
self.text = iter(unicode(fragment.text()))
self.fragment_char_format = fragment.charFormat()
self.dst_cursor.setCharFormat(self.fragment_char_format)
try: try:
char = self.text.next() char = self.text.next()
print "char", char
self.dst_cursor.insertText(char) self.dst_cursor.insertText(char)
except StopIteration: except StopIteration:
print "end of block" self.fragment_iter += 1
self.it += 1
self.text = None self.text = None
else:
self.it += 1
self.src_block = None
else: else:
self.timer.stop() self.timer.stop()
self.timer.timeout.disconnect(self.slot_animate) self.timer.timeout.disconnect(self.slot_animate)
@ -201,8 +203,8 @@ class TextAnimation(QtCore.QObject):
self.text = None self.text = None
self.animation_finished.emit() self.animation_finished.emit()
self.timer = None self.timer = None
print "animation end"
print self.count += 1
class MainWindow(KMainWindow, Ui_MainWindow): class MainWindow(KMainWindow, Ui_MainWindow):
@ -226,6 +228,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.model = TextModel(self) self.model = TextModel(self)
self.animation = TextAnimation(self) self.animation = TextAnimation(self)
self.db_dirty = False self.db_dirty = False
self.is_animate = False
self.is_auto_publish = False self.is_auto_publish = False
@ -234,15 +237,8 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.font = QtGui.QFont("monospace", self.default_size) self.font = QtGui.QFont("monospace", self.default_size)
self.font.setStyleHint(QtGui.QFont.TypeWriter) self.font.setStyleHint(QtGui.QFont.TypeWriter)
self.toolbar = KToolBar(self, True, True)
self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea)
self.toolbar.setMovable(False)
self.toolbar.setFloatable(False)
self.toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.toolbar)
self.createLiveActions() self.create_toolbar()
self.createPreviewActions()
#self.preview_text.document().setDefaultFont(self.font) #self.preview_text.document().setDefaultFont(self.font)
self.preview_text.setFont(self.font) self.preview_text.setFont(self.font)
@ -256,14 +252,12 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.live_editor_collection = KActionCollection(self) self.live_editor_collection = KActionCollection(self)
self.live_text.createActions(self.live_editor_collection) self.live_text.createActions(self.live_editor_collection)
self.filter_editor_actions() self.filter_editor_actions()
self.toolbar.insertSeparator(self.publish_action)
self.toolbar.addSeparator()
self.slot_load() self.slot_load()
self.show() self.show()
self.save_action.triggered.connect(self.slot_save) self.save_action.triggered.connect(self.slot_save)
#self.valign_action.triggered.connect(self.slot_valign)
self.publish_action.triggered.connect(self.slot_publish) self.publish_action.triggered.connect(self.slot_publish)
self.clear_live_action.triggered.connect(self.slot_clear_live) self.clear_live_action.triggered.connect(self.slot_clear_live)
self.clear_preview_action.triggered.connect(self.slot_clear_preview) self.clear_preview_action.triggered.connect(self.slot_clear_preview)
@ -276,6 +270,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.save_preview_action.triggered.connect(self.slot_save_preview_text) self.save_preview_action.triggered.connect(self.slot_save_preview_text)
self.streaming_action.triggered.connect(self.slot_toggle_streaming) self.streaming_action.triggered.connect(self.slot_toggle_streaming)
self.auto_publish_action.toggled.connect(self.slot_auto_publish) self.auto_publish_action.toggled.connect(self.slot_auto_publish)
self.typer_animation_action.toggled.connect(self.slot_toggle_animation)
self.preview_size_action.triggered[QtGui.QAction].connect(self.slot_preview_font_size) self.preview_size_action.triggered[QtGui.QAction].connect(self.slot_preview_font_size)
self.live_size_action.triggered[QtGui.QAction].connect(self.slot_live_font_size) self.live_size_action.triggered[QtGui.QAction].connect(self.slot_live_font_size)
@ -351,108 +346,116 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.slot_set_live_defaults() self.slot_set_live_defaults()
def createLiveActions(self): def create_toolbar(self):
self.toolbar.show()
self.live_text_collection = KActionCollection(self)
self.live_text_collection.addAssociatedWidget(self.toolbar)
self.clear_live_action = self.live_text_collection.addAction("clear_live_action") self.toolbar = KToolBar(self, True, True)
self.toolbar.setAllowedAreas(QtCore.Qt.BottomToolBarArea)
self.toolbar.setMovable(False)
self.toolbar.setFloatable(False)
self.toolbar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.toolbar)
self.toolbar.show()
self.action_collection = KActionCollection(self)
self.action_collection.addAssociatedWidget(self.toolbar)
self.clear_live_action = self.action_collection.addAction("clear_live_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("edit-clear")) icon = QtGui.QIcon.fromTheme(_fromUtf8("edit-clear"))
self.clear_live_action.setIcon(icon) self.clear_live_action.setIcon(icon)
self.clear_live_action.setIconText("clear live") self.clear_live_action.setIconText("clear live")
self.clear_live_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Q)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.clear_live_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Q)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.save_live_action = self.action_collection.addAction("save_live_action")
self.save_live_action = self.live_text_collection.addAction("save_live_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-new")) icon = QtGui.QIcon.fromTheme(_fromUtf8("document-new"))
self.save_live_action.setIcon(icon) self.save_live_action.setIcon(icon)
self.save_live_action.setIconText("save live") self.save_live_action.setIconText("save live")
self.save_live_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_W)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.save_live_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_W)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
def createPreviewActions(self): self.clear_preview_action = self.action_collection.addAction("clear_preview_action")
self.toolbar.show()
self.preview_text_collection = KActionCollection(self)
self.preview_text_collection.addAssociatedWidget(self.toolbar)
self.clear_preview_action = self.preview_text_collection.addAction("clear_preview_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("edit-clear")) icon = QtGui.QIcon.fromTheme(_fromUtf8("edit-clear"))
self.clear_preview_action.setIcon(icon) self.clear_preview_action.setIcon(icon)
self.clear_preview_action.setIconText("clear preview") self.clear_preview_action.setIconText("clear preview")
#self.clear_preview_action.setObjectName("clear_preview") #self.clear_preview_action.setObjectName("clear_preview")
self.clear_preview_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_A)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.clear_preview_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_A)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.save_preview_action = self.action_collection.addAction("save_preview_action")
self.save_preview_action = self.preview_text_collection.addAction("save_preview_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-new")) icon = QtGui.QIcon.fromTheme(_fromUtf8("document-new"))
self.save_preview_action.setIcon(icon) self.save_preview_action.setIcon(icon)
self.save_preview_action.setIconText("save preview") self.save_preview_action.setIconText("save preview")
self.save_preview_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_S)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.save_preview_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_S)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.publish_action = self.action_collection.addAction("publish_action")
self.publish_action = self.preview_text_collection.addAction("publish_action") icon = QtGui.QIcon.fromTheme(_fromUtf8("edit-copy"))
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-playback-start"))
self.publish_action.setIcon(icon) self.publish_action.setIcon(icon)
self.publish_action.setIconText("publish") self.publish_action.setIconText("publish")
self.publish_action.setShortcutConfigurable(True) self.publish_action.setShortcutConfigurable(True)
self.publish_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Return)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.publish_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Return)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.toolbar.insertSeparator(self.publish_action)
self.previous_action = self.preview_text_collection.addAction("previous_action") self.auto_publish_action = KToggleAction(self.action_collection)
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-skip-backward")) self.action_collection.addAction("auto publish", self.auto_publish_action)
self.previous_action.setIcon(icon)
self.previous_action.setIconText("previous")
self.previous_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Left)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.next_action = self.preview_text_collection.addAction("next_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-skip-forward"))
self.next_action.setIcon(icon)
self.next_action.setIconText("next")
self.next_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Right)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.text_editor_action = self.preview_text_collection.addAction("text_editor_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-open"))
self.text_editor_action.setIcon(icon)
self.text_editor_action.setIconText("edit")
self.text_editor_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_O)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.auto_publish_action = KToggleAction(self.preview_text_collection)
self.preview_text_collection.addAction("auto publish", self.auto_publish_action)
icon = QtGui.QIcon.fromTheme(_fromUtf8("view-refresh")) icon = QtGui.QIcon.fromTheme(_fromUtf8("view-refresh"))
self.auto_publish_action.setIcon(icon) self.auto_publish_action.setIcon(icon)
self.auto_publish_action.setObjectName("auto_publish_action") self.auto_publish_action.setObjectName("auto_publish_action")
self.auto_publish_action.setIconText("auto publish") self.auto_publish_action.setIconText("auto publish")
self.auto_publish_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_P)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.auto_publish_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_P)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.save_action = self.preview_text_collection.addAction("save_action") self.typer_animation_action = KToggleAction(self.action_collection)
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-playback-stop"))
self.typer_animation_action.setIcon(icon)
self.typer_animation_action.setIconText("animate")
self.typer_animation_action.setObjectName("typer_animation_action")
self.typer_animation_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_M)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.action_collection.addAction("typer_animation_action", self.typer_animation_action)
self.text_editor_action = self.action_collection.addAction("text_editor_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-open-data"))
self.text_editor_action.setIcon(icon)
self.text_editor_action.setIconText("edit")
self.text_editor_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_O)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.toolbar.insertSeparator(self.text_editor_action)
self.save_action = self.action_collection.addAction("save_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-save")) icon = QtGui.QIcon.fromTheme(_fromUtf8("document-save"))
self.save_action.setIcon(icon) self.save_action.setIcon(icon)
self.save_action.setIconText("save") self.save_action.setIconText("save")
self.save_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_S)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.save_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_S)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.streaming_action = KToggleAction(self.preview_text_collection) self.streaming_action = KToggleAction(self.action_collection)
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-record")) icon = QtGui.QIcon.fromTheme(_fromUtf8("media-record"))
self.streaming_action.setIcon(icon) self.streaming_action.setIcon(icon)
self.streaming_action.setIconText("stream") self.streaming_action.setIconText("stream")
self.streaming_action.setObjectName("stream") self.streaming_action.setObjectName("stream")
self.streaming_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_1)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) self.streaming_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_1)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.preview_text_collection.addAction("stream", self.streaming_action) self.action_collection.addAction("stream", self.streaming_action)
self.valign_action = self.preview_text_collection.addAction("valign_action") spacer = KToolBarSpacerAction(self.action_collection)
icon = QtGui.QIcon.fromTheme(_fromUtf8("media-stop")) self.action_collection.addAction("1_spacer", spacer)
self.valign_action.setIcon(icon)
self.valign_action.setIconText("valign")
self.valign_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Plus)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.spacer = KToolBarSpacerAction(self.preview_text_collection) self.previous_action = self.action_collection.addAction("previous_action")
self.preview_text_collection.addAction("spacer", self.spacer) icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page"))
self.previous_action.setIcon(icon)
self.previous_action.setIconText("previous")
self.previous_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Left)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.text_combo = KSelectAction(self.preview_text_collection) self.text_combo = KSelectAction(self.action_collection)
self.text_combo.setEditable(False) self.text_combo.setEditable(False)
icon = QtGui.QIcon.fromTheme(_fromUtf8("document-open-recent")) icon = QtGui.QIcon.fromTheme(_fromUtf8("document-open-recent"))
self.text_combo.setIcon(icon) self.text_combo.setIcon(icon)
self.text_combo.setIconText("saved texts") self.text_combo.setIconText("saved texts")
self.text_combo.setObjectName("text_combo") self.text_combo.setObjectName("text_combo")
self.preview_text_collection.addAction("saved texts", self.text_combo) self.action_collection.addAction("saved texts", self.text_combo)
self.next_action = self.action_collection.addAction("next_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("go-next-view-page"))
self.next_action.setIcon(icon)
self.next_action.setIconText("next")
self.next_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_Right)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.toolbar.addSeparator()
def closeEvent(self, event): def closeEvent(self, event):
self.stop_streaming() self.stop_streaming()
@ -478,7 +481,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
public_rect = self.live_text.geometry() public_rect = self.live_text.geometry()
global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()), self.mapToGlobal(public_rect.bottomRight())) global_rect = QtCore.QRect(self.mapToGlobal(public_rect.topLeft()), self.mapToGlobal(public_rect.bottomRight()))
self.ffserver = subprocess.Popen("ffserver -f /etc/ffserver.conf", shell=True, close_fds=True) self.ffserver = subprocess.Popen("ffserver -f /etc/ffserver.conf", shell=True, close_fds=True)
self.ffmpeg = subprocess.Popen("ffmpeg -f x11grab -s 768x576 -r 25 -i :0.0+%d,%d -vcodec mjpeg -pix_fmt yuvj422p -r 25 -aspect 4:3 http://localhost:8090/webcam.ffm" % (global_rect.x()+1, global_rect.y()+1), shell=True, close_fds=True) self.ffmpeg = subprocess.Popen("ffmpeg -f x11grab -s 768x576 -r 30 -i :0.0+%d,%d -vcodec mjpeg -pix_fmt yuvj444p -r 30 -aspect 4:3 http://localhost:8090/webcam.ffm" % (global_rect.x()+5, global_rect.y()+5), shell=True, close_fds=True)
self.is_streaming = True self.is_streaming = True
def focusChanged(self, old, new): def focusChanged(self, old, new):
@ -504,6 +507,8 @@ class MainWindow(KMainWindow, Ui_MainWindow):
def slot_auto_publish(self, state): def slot_auto_publish(self, state):
self.is_auto_publish = bool(state) self.is_auto_publish = bool(state)
def slot_toggle_animation(self, state):
self.is_animate = bool(state)
def slot_toggle_streaming(self): def slot_toggle_streaming(self):
if self.ffserver is None: if self.ffserver is None:
@ -513,15 +518,21 @@ class MainWindow(KMainWindow, Ui_MainWindow):
def slot_next_item(self): def slot_next_item(self):
try:
self.current = (self.text_combo.currentItem() + 1) % len(self.model.text_db) self.current = (self.text_combo.currentItem() + 1) % len(self.model.text_db)
self.text_combo.setCurrentItem(self.current) self.text_combo.setCurrentItem(self.current)
self.slot_load_preview_text(self.current) self.slot_load_preview_text(self.current)
except ZeroDivisionError:
pass
def slot_previous_item(self): def slot_previous_item(self):
try:
self.current = (self.text_combo.currentItem() - 1) % len(self.model.text_db) self.current = (self.text_combo.currentItem() - 1) % len(self.model.text_db)
self.text_combo.setCurrentItem(self.current) self.text_combo.setCurrentItem(self.current)
self.slot_load_preview_text(self.current) self.slot_load_preview_text(self.current)
except ZeroDivisionError:
pass
def slot_toggleToolbox(self, index): def slot_toggleToolbox(self, index):
@ -532,20 +543,19 @@ class MainWindow(KMainWindow, Ui_MainWindow):
def slot_publish(self): def slot_publish(self):
print "publish" if self.is_animate:
#self.live_text.setTextOrHtml(self.preview_text.textOrHtml()) self.animation.start_animation(self.preview_text, self.live_text, 0)
self.animation.start_animation(self.preview_text.document(), self.live_text, 0) else:
self.slot_clear_live() self.live_text.setTextOrHtml(self.preview_text.textOrHtml())
def slot_live_font_size(self, action): def slot_live_font_size(self, action):
print "font_size"
self.default_size = self.live_size_action.fontSize() self.default_size = self.live_size_action.fontSize()
self.slot_set_preview_defaults() self.slot_set_preview_defaults()
self.slot_set_live_defaults() self.slot_set_live_defaults()
def slot_preview_font_size(self, action): def slot_preview_font_size(self, action):
print "font_size"
self.default_size = self.preview_size_action.fontSize() self.default_size = self.preview_size_action.fontSize()
self.slot_set_live_defaults() self.slot_set_live_defaults()
self.slot_set_preview_defaults() self.slot_set_preview_defaults()
@ -566,17 +576,15 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.preview_text.setFontSize(self.default_size) self.preview_text.setFontSize(self.default_size)
self.preview_text.setFont(self.font) self.preview_text.setFont(self.font)
self.preview_size_action.setFontSize(self.default_size) self.preview_size_action.setFontSize(self.default_size)
#self.preview_text.document().setDefaultFont(self.font) self.preview_text.document().setDefaultFont(self.font)
def slot_set_live_defaults(self): def slot_set_live_defaults(self):
self.live_center_action.setChecked(True) self.live_center_action.setChecked(True)
self.live_text.alignCenter() self.live_text.alignCenter()
self.font.setPointSize(self.default_size)
self.live_text.setFontSize(self.default_size) self.live_text.setFontSize(self.default_size)
self.live_text.setFont(self.font)
self.live_size_action.setFontSize(self.default_size) self.live_size_action.setFontSize(self.default_size)
#self.live_text.document().setDefaultFont(self.font) self.live_text.document().setDefaultFont(self.font)
def slot_clear_live(self): def slot_clear_live(self):
@ -589,7 +597,6 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.slot_set_preview_defaults() self.slot_set_preview_defaults()
def fill_combo_box(self): def fill_combo_box(self):
print "fill_combo_box"
self.text_combo.clear() self.text_combo.clear()
for preview, text in self.model.text_db: for preview, text in self.model.text_db:
self.text_combo.addAction(preview) self.text_combo.addAction(preview)
@ -653,19 +660,12 @@ class MainWindow(KMainWindow, Ui_MainWindow):
return return
old_item = self.model.text_by_preview(preview) old_item = self.model.text_by_preview(preview)
if old_item is not None: if old_item is not None:
suffix = 1 ix, old_preview, old_text = old_item
while 1: self.model.text_db[ix][1] = text
tmp_preview = "%s_%d" % (preview, suffix)
tmp = self.model.text_by_preview(tmp_preview)
if tmp is None:
preview = tmp_preview
break
else: else:
suffix += 1
self.model.text_db.append([preview, text]) self.model.text_db.append([preview, text])
self.model.modelReset.emit()
action = self.text_combo.addAction(preview) action = self.text_combo.addAction(preview)
self.model.modelReset.emit()
self.text_combo.setCurrentAction(action) self.text_combo.setCurrentAction(action)
self.db_dirty = True self.db_dirty = True
@ -679,61 +679,8 @@ class MainWindow(KMainWindow, Ui_MainWindow):
return return
else: else:
cPickle.dump(self.model.text_db, f, cPickle.HIGHEST_PROTOCOL) cPickle.dump(self.model.text_db, f, cPickle.HIGHEST_PROTOCOL)
self.db_dirty = False
#def slot_valign(self):
#fm = QtGui.QFontMetrics(self.font)
##h = fn.height()
##max_lines = 576 / h
##text = unicode(self.preview_text.toPlainText())
##text = text.strip().strip("\n")
##lines = text.count("\n") + 1
##self.preview_text.setTextOrHtml("\n" * ((max_lines - lines) / 2) + text)
##self.statusBar().showMessage("text lines = %d, line height = %d, max lines = %d" % (lines, h, max_lines))
#text_layout = QtGui.QTextLayout(self.preview_text.textOrHtml(), self.font, self.preview_text)
##self.text_combo.setCurrentAction(action)
#margin = 10.
#radius = min(self.preview_text.width()/2.0, self.preview_text.height()/2.0) - margin
#print "radius", type(radius), radius
#lineHeight = float(fm.height())
#print "lineHeight", type(lineHeight), lineHeight
#y = 0.
#text_layout.beginLayout()
#while 1:
#line = text_layout.createLine()
#if not line.isValid():
#break
#x1 = max(0.0, pow(pow(radius,2)-pow(radius-y,2), 0.5))
#x2 = max(0.0, pow(pow(radius,2)-pow(radius-(y+lineHeight),2), 0.5))
#x = max(x1, x2) + margin
#lineWidth = (self.preview_text.width() - margin) - x
#line.setLineWidth(lineWidth)
#line.setPosition(QtCore.QPointF(x, margin+y))
#y += line.height()
#text_layout.endLayout()
#painter = QtGui.QPainter()
#painter.begin(self.preview_text)
#painter.setRenderHint(QtGui.QPainter.Antialiasing)
#painter.fillRect(self.rect(), QtCore.Qt.black)
#painter.setBrush(QtGui.QBrush(QtCore.Qt.white))
#painter.setPen(QtGui.QPen(QtCore.Qt.white))
#text_layout.draw(painter, QtCore.QPoint(0,0))
#painter.setBrush(QtGui.QBrush(QtGui.QColor("#a6ce39")))
#painter.setPen(QtGui.QPen(QtCore.Qt.black))
#painter.drawEllipse(QtCore.QRectF(-radius, margin, 2*radius, 2*radius))
#painter.end()
def slot_valign(self):
self.animation = TextAnimation(self.preview_text.document(), )
def slot_open_dialog(self): def slot_open_dialog(self):
self.dialog = KDialog(self) self.dialog = KDialog(self)
@ -745,7 +692,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
global_width = rect.width() global_width = rect.width()
global_height = rect.height() global_height = rect.height()
x = global_width - pos_x - 10 x = global_width - pos_x - 10
self.dialog.setFixedSize(x, global_height-40); #self.dialog.setFixedSize(x, global_height-40)
self.dialog.okClicked.connect(self.fill_combo_box) self.dialog.okClicked.connect(self.fill_combo_box)
self.dialog.exec_() self.dialog.exec_()
self.dialog.deleteLater() self.dialog.deleteLater()

View File

@ -61,21 +61,16 @@ class TextModel(QtCore.QAbstractTableModel):
return True return True
def removeRows(self, row, count, parent=QtCore.QModelIndex()): def removeRows(self, row, count, parent=QtCore.QModelIndex()):
print "removeRows", row, count
print map(itemgetter(0), self.text_db)
self.beginRemoveRows(QtCore.QModelIndex(), row, row+count+1) self.beginRemoveRows(QtCore.QModelIndex(), row, row+count+1)
for i in range(row, row+count): for i in range(row, row+count):
print "del", i, self.text_db[row]
self.text_db.pop(row) self.text_db.pop(row)
print "after"
print map(itemgetter(0), self.text_db)
self.endRemoveRows() self.endRemoveRows()
return True return True
def text_by_preview(self, preview): def text_by_preview(self, preview):
for title, text in self.text_db: for ix, (title, text) in enumerate(self.text_db):
if title == preview: if title == preview:
return title, text return ix, title, text
return None return None

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# coding=UTF-8 # coding=UTF-8
# #
# Generated by pykdeuic4 from texter4.ui on Sat Apr 19 19:39:29 2014 # Generated by pykdeuic4 from texter4.ui on Mon Apr 21 01:34:50 2014
# #
# WARNING! All changes to this file will be lost. # WARNING! All changes to this file will be lost.
from PyKDE4 import kdecore from PyKDE4 import kdecore
@ -25,18 +25,19 @@ except AttributeError:
class Ui_TextSorterDialog(object): class Ui_TextSorterDialog(object):
def setupUi(self, TextSorterDialog): def setupUi(self, TextSorterDialog):
TextSorterDialog.setObjectName(_fromUtf8("TextSorterDialog")) TextSorterDialog.setObjectName(_fromUtf8("TextSorterDialog"))
TextSorterDialog.resize(1073, 938) TextSorterDialog.resize(1084, 633)
self.verticalLayout = QtGui.QVBoxLayout(TextSorterDialog) self.verticalLayout = QtGui.QVBoxLayout(TextSorterDialog)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout_2 = QtGui.QHBoxLayout() self.splitter = QtGui.QSplitter(TextSorterDialog)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.text_list = QtGui.QListView(TextSorterDialog) self.splitter.setObjectName(_fromUtf8("splitter"))
self.text_list = QtGui.QListView(self.splitter)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(2) sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.text_list.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.text_list.sizePolicy().hasHeightForWidth())
self.text_list.setSizePolicy(sizePolicy) self.text_list.setSizePolicy(sizePolicy)
self.text_list.setMinimumSize(QtCore.QSize(0, 576)) self.text_list.setMinimumSize(QtCore.QSize(200, 576))
self.text_list.setMaximumSize(QtCore.QSize(16777215, 576)) self.text_list.setMaximumSize(QtCore.QSize(16777215, 576))
palette = QtGui.QPalette() palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
@ -77,14 +78,13 @@ class Ui_TextSorterDialog(object):
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
self.text_list.setPalette(palette) self.text_list.setPalette(palette)
self.text_list.setObjectName(_fromUtf8("text_list")) self.text_list.setObjectName(_fromUtf8("text_list"))
self.horizontalLayout_2.addWidget(self.text_list) self.text_preview = KRichTextWidget(self.splitter)
self.text_preview = KRichTextWidget(TextSorterDialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(8) sizePolicy.setHorizontalStretch(100)
sizePolicy.setVerticalStretch(0) sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.text_preview.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.text_preview.sizePolicy().hasHeightForWidth())
self.text_preview.setSizePolicy(sizePolicy) self.text_preview.setSizePolicy(sizePolicy)
self.text_preview.setMinimumSize(QtCore.QSize(200, 576)) self.text_preview.setMinimumSize(QtCore.QSize(0, 576))
self.text_preview.setMaximumSize(QtCore.QSize(768, 576)) self.text_preview.setMaximumSize(QtCore.QSize(768, 576))
palette = QtGui.QPalette() palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
@ -225,8 +225,7 @@ class Ui_TextSorterDialog(object):
self.text_preview.setPalette(palette) self.text_preview.setPalette(palette)
self.text_preview.setReadOnly(True) self.text_preview.setReadOnly(True)
self.text_preview.setObjectName(_fromUtf8("text_preview")) self.text_preview.setObjectName(_fromUtf8("text_preview"))
self.horizontalLayout_2.addWidget(self.text_preview) self.verticalLayout.addWidget(self.splitter)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.kbuttongroup = KButtonGroup(TextSorterDialog) self.kbuttongroup = KButtonGroup(TextSorterDialog)
self.kbuttongroup.setObjectName(_fromUtf8("kbuttongroup")) self.kbuttongroup.setObjectName(_fromUtf8("kbuttongroup"))
self.horizontalLayout = QtGui.QHBoxLayout(self.kbuttongroup) self.horizontalLayout = QtGui.QHBoxLayout(self.kbuttongroup)

View File

@ -217,11 +217,8 @@
</disabled> </disabled>
</palette> </palette>
</property> </property>
<property name="cursor" stdset="0">
<cursorShape>ArrowCursor</cursorShape>
</property>
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="verticalScrollBarPolicy"> <property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum> <enum>Qt::ScrollBarAlwaysOff</enum>
@ -324,14 +321,11 @@
</disabled> </disabled>
</palette> </palette>
</property> </property>
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<property name="toolTip"> <property name="toolTip">
<string>preview text</string> <string>preview text</string>
</property> </property>
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::StyledPanel</enum> <enum>QFrame::StyledPanel</enum>

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1073</width> <width>1084</width>
<height>938</height> <height>633</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,18 +15,20 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QSplitter" name="splitter">
<item> <property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QListView" name="text_list"> <widget class="QListView" name="text_list">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>2</horstretch> <horstretch>1</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>200</width>
<height>576</height> <height>576</height>
</size> </size>
</property> </property>
@ -155,18 +157,16 @@
</palette> </palette>
</property> </property>
</widget> </widget>
</item>
<item>
<widget class="KRichTextWidget" name="text_preview"> <widget class="KRichTextWidget" name="text_preview">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>8</horstretch> <horstretch>100</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>200</width> <width>0</width>
<height>576</height> <height>576</height>
</size> </size>
</property> </property>
@ -595,8 +595,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </widget>
</layout>
</item> </item>
<item> <item>
<widget class="KButtonGroup" name="kbuttongroup"> <widget class="KButtonGroup" name="kbuttongroup">

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'texter3.ui' # Form implementation generated from reading ui file 'texter3.ui'
# #
# Created: Sat Apr 19 21:56:41 2014 # Created: Mon Apr 21 22:38:51 2014
# by: PyQt4 UI code generator 4.10.3 # by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -97,8 +97,7 @@ class Ui_MainWindow(object):
brush.setStyle(QtCore.Qt.SolidPattern) brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Link, brush) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Link, brush)
self.live_text.setPalette(palette) self.live_text.setPalette(palette)
self.live_text.viewport().setProperty("cursor", QtGui.QCursor(QtCore.Qt.ArrowCursor)) self.live_text.setAutoFillBackground(False)
self.live_text.setAutoFillBackground(True)
self.live_text.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.live_text.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.live_text.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.live_text.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.live_text.setAcceptRichText(True) self.live_text.setAcceptRichText(True)
@ -134,8 +133,7 @@ class Ui_MainWindow(object):
brush.setStyle(QtCore.Qt.SolidPattern) brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
self.preview_text.setPalette(palette) self.preview_text.setPalette(palette)
self.preview_text.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.preview_text.setAutoFillBackground(False)
self.preview_text.setAutoFillBackground(True)
self.preview_text.setFrameShape(QtGui.QFrame.StyledPanel) self.preview_text.setFrameShape(QtGui.QFrame.StyledPanel)
self.preview_text.setAcceptRichText(True) self.preview_text.setAcceptRichText(True)
self.preview_text.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextEditable|QtCore.Qt.TextEditorInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse) self.preview_text.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByKeyboard|QtCore.Qt.LinksAccessibleByMouse|QtCore.Qt.TextBrowserInteraction|QtCore.Qt.TextEditable|QtCore.Qt.TextEditorInteraction|QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse)