Skip to content

Commit

Permalink
Merge pull request #377 from gaphor/fix-tree-cell-rendering
Browse files Browse the repository at this point in the history
Fix tree cell rendering
  • Loading branch information
danyeaw committed Jul 31, 2020
2 parents 5f21bb1 + a76a775 commit 1c353de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gaphor/diagram/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(
self,
*children,
style: Style = {},
draw: Optional[Callable[[Box, DrawContext, Rectangle], None]] = None
draw: Optional[Callable[[Box, DrawContext, Rectangle], None]] = None,
):
self.children = children
self.sizes: List[Tuple[int, int]] = []
Expand Down
5 changes: 3 additions & 2 deletions gaphor/diagram/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def __init__(
self.set_alignment(text_align)

def set(self, text=None, font=None, width=None, text_align=None):
if text:
# Since text expressions can return False, we should also accomodate for that
if text not in (None, False):
self.set_text(text)
if font:
self.set_font(font)
if width:
if width is not None:
self.set_width(width)
if text_align:
self.set_alignment(text_align)
Expand Down
23 changes: 13 additions & 10 deletions gaphor/ui/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging
from typing import TYPE_CHECKING, Optional

from gi.repository import Gdk, Gio, GLib, GObject, Gtk
from gi.repository import Gdk, Gio, GLib, GObject, Gtk, Pango

from gaphor import UML
from gaphor.core import action, event_handler, gettext, transactional
Expand Down Expand Up @@ -117,20 +117,23 @@ def _set_text(self, column, cell, model, iter, data):
Set font and of model elements in tree view.
"""
element = model.get_value(iter, 0)
text = element and (element.name or "").replace("\n", " ") or "<None>"

if isinstance(element, Diagram):
text = f"<b>{text}</b>"
elif (
isinstance(element, UML.Classifier) or isinstance(element, UML.Operation)
) and element.isAbstract:
text = f"<i>{text}</i>"
elif isinstance(element, UML.Property):
text = format_attribute(element) or "&lt;None&gt;"
cell.set_property("weight", Pango.Weight.BOLD)
elif isinstance(element, (UML.Classifier, UML.Operation)):
cell.set_property(
"style",
Pango.Style.ITALIC if element.isAbstract else Pango.Style.NORMAL,
)

if isinstance(element, UML.Property):
text = format_attribute(element) or "<None>"
elif isinstance(element, UML.Operation):
text = format_operation(element)
else:
text = element and (element.name or "").replace("\n", " ") or "<None>"

cell.set_property("markup", text)
cell.set_property("text", text)

@transactional
def _text_edited(self, cell, path_str, new_text):
Expand Down

0 comments on commit 1c353de

Please sign in to comment.