Skip to content

Commit

Permalink
start implementing settings change from emacs
Browse files Browse the repository at this point in the history
  • Loading branch information
swhalemwo committed Oct 31, 2020
1 parent c8ffb82 commit 05d1296
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
14 changes: 12 additions & 2 deletions obvz.el
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@
(obvz-send-to-python (json-encode `(("layout_type" . ,obvz-layout-type))))
)


(defun obvz-change-setting ()
"change settings in python"
(interactive)
(let ((setting-dict `(("font_size" . ,(read-number "new font size: ")))))
(obvz-send-to-python (json-encode setting-dict))))




;; connection functions

(defun obvz-send-to-python (dict-str-to-send)
Expand All @@ -433,12 +443,12 @@
method args))


;; (add-hook 'org-brain-after-visualize-hook 'obvz-update-graph) ;; automatic redrawing with org-brain
(add-hook 'org-brain-after-visualize-hook 'obvz-update-graph) ;; automatic redrawing with org-brain

(setq obvz-connection-type "dbus")

(setq obvz-include-node-texts nil)
(setq obvz-only-use-annotated-edges t)
(setq obvz-only-use-annotated-edges nil)
(setq obvz-most-recent-config ())
(setq obvz-draw-arrow t)
(setq obvz-highlight-current-node t)
Expand Down
21 changes: 17 additions & 4 deletions obvz.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def reset(self):


def signal_received(self, new_graph_str):
"""deal received signal"""
logging.info(' receiving')
# main parsing/updates has to happen here
new_graph_dict = json.loads(new_graph_str)
Expand All @@ -281,13 +282,23 @@ def signal_received(self, new_graph_str):
self.draw_arrow_toggle = new_graph_dict['draw_arrow_toggle']

# change layout type



if list(new_graph_dict.keys())[0] == "layout_type":
if self.layout_type != new_graph_dict['layout_type']:
self.layout_type = new_graph_dict['layout_type']
update_me = 1


if list(new_graph_dict.keys())[0] == "font_size":
self.font_size = new_graph_dict['font_size']
font_title = QFont("Arial", self.font_size)
fm = QFontMetrics(font_title)
self.title_vflush = fm.boundingRect("node title").height()
self.set_node_wd_ht(list(self.g.nodes()))
update_me = 1
# update_texts = 1


# only command is to redraw
if list(new_graph_dict.keys())[0] == 'redraw':
Expand Down Expand Up @@ -380,7 +391,7 @@ def proc_node_texts(self, node_texts):


def get_node_text_dimensions(self, fm_nt, node_text):

"""calculate stuff related to when text is included"""
# n = 'bobbie'
# node_text = new_graph_dict['node_texts'][n]
# font = QFont("Arial", 10)
Expand Down Expand Up @@ -423,7 +434,6 @@ def set_node_wd_ht(self, nodes_to_recalc_dims):
fm_nt = QFontMetrics(font) # font metric node text



for n in nodes_to_recalc_dims:
if self.g.nodes[n]['nd_tp'] == 'nd':
node_rect = fm.boundingRect(self.g.nodes[n]['title'])
Expand All @@ -440,6 +450,7 @@ def set_node_wd_ht(self, nodes_to_recalc_dims):

self.g.nodes[n]['width'] = max(nt_dims[0]) + self.wd_pad*2
self.g.nodes[n]['height'] = sum(nt_dims[1])
logging.info(['node dims: ', self.g.nodes[n]['width'], self.g.nodes[n]['height']])

# if node is an edge label node there's no need to check for node text
if self.g.nodes[n]['nd_tp'] == 'lbl':
Expand Down Expand Up @@ -945,12 +956,15 @@ def draw_texts(self, qp, scl):

# draw node titles and text

logging.info(['vflush: ', self.title_vflush])

for t in zip(self.qt_coords, self.dim_ar, self.node_names):

if self.g.nodes[t[2]]['nd_tp'] == 'nd':
qp.setFont(QFont('Arial', self.font_size * scl))
ypos = (t[0][1]-t[1][1]/2) + self.title_vflush/1.3333


if self.g.nodes[t[2]]['nd_tp'] == 'lbl':
qp.setFont(QFont('Arial', self.node_text_size * scl))

Expand All @@ -959,7 +973,6 @@ def draw_texts(self, qp, scl):

xpos = t[0][0]-t[1][0]/2+ self.wd_pad


# qp.drawText(xpos, ypos, t[2])
qp.drawText(xpos, ypos, self.g.nodes[t[2]]['title'])

Expand Down

0 comments on commit 05d1296

Please sign in to comment.