Implement text preview with tags

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2022-11-19 17:14:48 +01:00
parent 6e4e08d7f9
commit cc001aba9f
No known key found for this signature in database
GPG key ID: D850A5F772E880F9
2 changed files with 209 additions and 8 deletions

View file

@ -4,12 +4,14 @@
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from gi.repository import Gtk, Pango
from manuskript.data import Project, Outline, OutlineFolder, OutlineText, OutlineItem, OutlineState, Plots, PlotLine, Characters, Character, Importance, Goal
from manuskript.ui.util import rgbaFromColor, pixbufFromColor
from manuskript.util import validString, invalidString, validInt, invalidInt, CounterKind, countText
import inspect
class EditorView:
@ -30,6 +32,11 @@ class EditorView:
self.outlineStore = builder.get_object("outline_store")
self.refreshOutlineStore()
self.editorTextBuffer = builder.get_object("editor_text")
self.editorFlowbox = builder.get_object("editor_flowbox")
self.loadEditorData(None)
def refreshLabelStore(self):
self.labelStore.clear()
@ -53,6 +60,15 @@ class EditorView:
self.statusStore.set_value(tree_iter, 0, validString(status.name))
@classmethod
def __getIconByOutlineType(cls, outlineItem: OutlineItem):
if type(outlineItem) is OutlineFolder:
return "folder-symbolic"
elif type(outlineItem) is OutlineText:
return "emblem-documents-symbolic"
else:
return "folder-documents-symbolic"
def __appendOutlineItem(self, outlineItem: OutlineItem, parent_iter=None):
tree_iter = self.outlineStore.append(parent_iter)
@ -62,15 +78,11 @@ class EditorView:
if outlineItem.state != OutlineState.COMPLETE:
outlineItem.load(False)
if type(outlineItem) is OutlineFolder:
icon = "folder-symbolic"
icon = EditorView.__getIconByOutlineType(outlineItem)
if type(outlineItem) is OutlineFolder:
for item in outlineItem:
self.__appendOutlineItem(item, tree_iter)
elif type(outlineItem) is OutlineText:
icon = "emblem-documents-symbolic"
else:
icon = "folder-documents-symbolic"
wordCount = validInt(outlineItem.textCount())
goal = validInt(outlineItem.goalCount())
@ -97,5 +109,65 @@ class EditorView:
for item in self.project.outline.items:
self.__appendOutlineItem(item)
def __appendOutlineItemText(self, outlineItem: OutlineItem):
end_iter = self.editorTextBuffer.get_end_iter()
if type(outlineItem) is OutlineFolder:
if self.editorTextBuffer.get_line_count() > 1:
self.editorTextBuffer.insert_with_tags_by_name(end_iter, "\n", "none")
end_iter = self.editorTextBuffer.get_end_iter()
self.editorTextBuffer.insert_with_tags_by_name(end_iter, outlineItem.title + "\n", "h1")
for item in outlineItem:
self.__appendOutlineItemText(item)
return True
elif type(outlineItem) is OutlineText:
outlineText: OutlineText = outlineItem
if (outlineText.text is None) or (len(outlineText.text) <= 0):
return False
self.editorTextBuffer.insert(end_iter, outlineText.text)
return True
else:
return False
def loadEditorData(self, outlineItem: OutlineItem | None):
self.editorTextBuffer.set_text("")
for item in self.project.outline.items:
self.__appendOutlineItemText(item)
for item in self.project.outline.items:
child = Gtk.FlowBoxChild()
hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
icon = EditorView.__getIconByOutlineType(item)
iconImage = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
titleLabel = Gtk.Label(item.title)
summaryLabel = Gtk.Label(item.summaryFull)
titleLabel.set_ellipsize(Pango.EllipsizeMode.END)
summaryLabel.set_ellipsize(Pango.EllipsizeMode.END)
summaryLabel.set_line_wrap_mode(Pango.WrapMode.WORD_CHAR)
summaryLabel.set_line_wrap(True)
summaryLabel.set_max_width_chars(20)
hbox.pack_start(iconImage, False, True, 4)
hbox.pack_start(titleLabel, False, True, 4)
vbox.pack_start(hbox, False, True, 4)
vbox.pack_start(summaryLabel, False, True, 4)
child.add(vbox)
self.editorFlowbox.add(child)
def show(self):
self.widget.show_all()

View file

@ -30,6 +30,132 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<object class="GtkTextTagTable" id="editor_tag_table">
<child type="tag">
<object class="GtkTextTag" id="h1_tag">
<property name="name">h1</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="scale">2</property>
<property name="pixels-above-lines">4</property>
<property name="pixels-below-lines">4</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag">
<property name="font">Normal</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag">
<property name="font">Normal</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag">
<property name="font">Normal</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="h2_tag">
<property name="name">h2</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="scale">1.5</property>
<property name="pixels-above-lines">8</property>
<property name="pixels-below-lines">8</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="h3_tag">
<property name="name">h3</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="scale">1.1699999999999999</property>
<property name="pixels-above-lines">12</property>
<property name="pixels-below-lines">12</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="h4_tag">
<property name="name">h4</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="pixels-above-lines">16</property>
<property name="pixels-below-lines">16</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="h5_tag">
<property name="name">h5</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="scale">0.82999999999999996</property>
<property name="pixels-above-lines">20</property>
<property name="pixels-below-lines">20</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="h6_tag">
<property name="name">h6</property>
<property name="font">Normal</property>
<property name="variant">title-caps</property>
<property name="weight">700</property>
<property name="scale">0.67</property>
<property name="pixels-above-lines">24</property>
<property name="pixels-below-lines">24</property>
<property name="editable">False</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="b_tag">
<property name="name">b</property>
<property name="font">Normal</property>
<property name="weight">700</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="i_tag">
<property name="name">i</property>
<property name="font">Normal</property>
<property name="style">italic</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="s_tag">
<property name="name">s</property>
<property name="font">Normal</property>
<property name="strikethrough">True</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="u_tag">
<property name="name">u</property>
<property name="font">Normal</property>
<property name="underline">single</property>
</object>
</child>
<child type="tag">
<object class="GtkTextTag" id="none_tag">
<property name="name">none</property>
<property name="font">Normal</property>
<property name="editable">False</property>
</object>
</child>
</object>
<object class="GtkTextBuffer" id="editor_text">
<property name="tag-table">editor_tag_table</property>
</object>
<object class="GtkListStore" id="label_store">
<columns>
<!-- column-name name -->
@ -246,6 +372,8 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<object class="GtkTextView">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="wrap-mode">word-char</property>
<property name="buffer">editor_text</property>
</object>
</child>
</object>
@ -267,9 +395,10 @@ along with Manuskript. If not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkFlowBox">
<object class="GtkFlowBox" id="editor_flowbox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="homogeneous">True</property>
</object>
</child>
</object>