Skip to content
Snippets Groups Projects
Commit 6e33abad authored by Allen, Bruce (CIV)'s avatar Allen, Bruce (CIV)
Browse files

update syntax based on pylint

parent be69d8b6
No related branches found
No related tags found
No related merge requests found
Showing
with 176 additions and 224 deletions
......@@ -11,3 +11,5 @@ mp_py_um.toc
# Python
__pycache__
# Doxygen
doc/doxygen/html
......@@ -18,7 +18,7 @@
# Changed dist to also depend on all
#
VERSION = Pre-Alpha-v0.3.9
VERSION = Pre-Alpha-v0.3.10
WIN = MP_Gryphon_GUI-$(VERSION)-windowsinstaller.exe
ZIP_DIR = MP_Gryphon_GUI-$(VERSION)
ZIP = $(ZIP_DIR).zip
......
......@@ -20,7 +20,6 @@ class AboutMPDialogWrapper(QDialog):
# put in text from file
with open("html/about.html") as f:
text = f.read()
# self.ui.about_te.appendHtml(text)
self.ui.about_tb.setHtml(text)
self.ui.about_tb.setOpenExternalLinks(True)
......
#from PyQt5.QtCore import QObject # for signal/slot support
#from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QColorDialog
from PyQt5.QtGui import QColor
from settings_manager import settings
......
......@@ -23,7 +23,7 @@ class _RunnerThread(threading.Thread):
# run the command
try:
self.cmd_p = subprocess.Popen(self._cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stderr=subprocess.PIPE)
# start readers
stdout_reader = _ReaderThread("stdout", self.cmd_p.stdout, self._queue)
......@@ -39,7 +39,7 @@ class _RunnerThread(threading.Thread):
# python 3 uses FileNotFoundError, python 2.7 uses superclass IOError
except IOError:
self._queue.put(("Error", "%s not found. Please check that it "
"is installed.\n" % self._cmd[0]))
"is installed.\n" % self._cmd[0]))
return 1
# private reader helper
......@@ -53,8 +53,8 @@ class _ReaderThread(threading.Thread):
def run(self):
# read pipe until pipe closes
for line in self._pipe:
line_string = line.decode(
encoding=sys.stderr.encoding, errors='replace')
line_string = line.decode(encoding=sys.stderr.encoding,
errors='replace')
# write stderr line to queue
self._queue.put((self._name, line_string))
......
# Adapted from https://raw.githubusercontent.com/baoboa/pyqt5/master/examples/graphicsview/elasticnodes.py
from math import sin, cos, tan, atan2, pi
from PyQt5.QtCore import (QLineF, QPointF, QRectF, QSizeF)
from PyQt5.QtCore import QLineF, QPointF
from PyQt5.QtCore import Qt
from PyQt5.QtGui import (QBrush, QColor, QLinearGradient, QPainter,
QPainterPath, QPen, QPolygonF, QRadialGradient)
from PyQt5.QtGui import QTransform
from PyQt5.QtGui import QPolygonF
from PyQt5.QtGui import QFontMetrics
from PyQt5.QtGui import QFont
from PyQt5.QtGui import QPainterPath
from PyQt5.QtGui import QColor, QPainterPath, QPen, QPolygonF
from PyQt5.QtGui import QPainterPathStroker
from PyQt5.QtWidgets import (QGraphicsItem, QGraphicsView, QStyle)
from PyQt5.QtWidgets import QGraphicsSimpleTextItem
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QAction
from PyQt5.QtWidgets import QGraphicsSceneContextMenuEvent
from PyQt5.QtWidgets import QGraphicsItem
from settings_manager import settings
# Qt line style from MP line style name
def _line_style_lookup(name):
if name == "solid_line":
return Qt.SolidLine
elif name == "dash_line":
if name == "dash_line":
return Qt.DashLine
else:
print("Invalid line style name '%s'" % name)
return Qt.SolidLine
print("Invalid line style name '%s'" % name)
return Qt.SolidLine
# source point is at edge of source node
def _source_point(source_node, line):
......@@ -113,7 +102,7 @@ class Edge(QGraphicsItem):
Type = QGraphicsItem.UserType + 2
def __init__(self, source_id, relation, target_id, label, node_lookup,
cbp1 = None, cbp2 = None):
cbp1=None, cbp2=None):
super(Edge, self).__init__()
# MP attributes
......@@ -243,7 +232,7 @@ class Edge(QGraphicsItem):
dest_path = self.mapFromItem(self.dest_node, self.dest_node.mouse_path)
t = 0.5
m = 0.25
for i in range(10): # binary search edge with resolution of 12
for _i in range(10): # binary search edge with resolution of 12
arrow_tip = edge_path.pointAtPercent(t)
if dest_path.contains(arrow_tip):
# inside dest so move back
......@@ -309,20 +298,21 @@ class Edge(QGraphicsItem):
def boundingRect(self):
extra = 1
return self.edge_path.boundingRect().adjusted(-extra, -extra,
extra, extra)
extra, extra)
def shape(self):
# note: path without stroker includes concave shape, not just edge path
return self.mouse_path
def paint(self, painter, option, widget):
def paint(self, painter, _option, _widget):
# paint edge shape of path without brush fill
painter.strokePath(self.edge_path, QPen(self.color, self.line_width,
self.style, Qt.RoundCap, Qt.RoundJoin))
# draw the arrow
painter.setPen(QPen(self.color, self.line_width, self.style, Qt.RoundCap, Qt.RoundJoin))
painter.setPen(QPen(self.color, self.line_width, self.style,
Qt.RoundCap, Qt.RoundJoin))
painter.setBrush(self.color)
painter.drawPolygon(self.arrow)
......@@ -334,14 +324,7 @@ class Edge(QGraphicsItem):
offset = QPointF(label_width/2, label_descent+1)
painter.drawText(self.label_point - offset, self.label)
# paint using p0, p1, p2, p3, color, line_width, style
def draw_cubic_bezier(self):
painter.setPen(QPen(self.color, self.line_width, self.style,
Qt.RoundCap, Qt.RoundJoin))
painter.moveTo(self.p0)
painter.cubicTo(self.p1, self.p2, self.p3)
def mousePressEvent(self, event):
def mousePressEvent(self, _event):
# deselect any nodes
for node in self.source_node.graph_item.nodes:
node.setSelected(False)
......
from PyQt5.QtCore import QPointF, QRectF
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import Qt
from PyQt5.QtGui import (QBrush, QColor, QLinearGradient, QPainter,
QPainterPath, QPen, QPolygonF, QRadialGradient)
from PyQt5.QtGui import QTransform
from PyQt5.QtGui import QPolygonF
from PyQt5.QtGui import QFontMetrics
from PyQt5.QtGui import QFont
from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import (QGraphicsItem, QGraphicsView, QStyle)
from PyQt5.QtGui import QBrush, QColor, QPainterPath, QPen, QRadialGradient
from PyQt5.QtWidgets import QGraphicsItem
from settings_manager import settings
# EdgeGrip
......@@ -61,7 +54,7 @@ class EdgeGrip(QGraphicsItem):
def clear_grip(self):
self.setVisible(False)
def type(self):
return EdgeGrip.Type
......@@ -73,25 +66,25 @@ class EdgeGrip(QGraphicsItem):
def shape(self):
return self.grip_shape
def paint(self, painter, option, widget):
def paint(self, painter, _option, _widget):
# draw circle shadow
painter.setPen(Qt.NoPen)
painter.setBrush(QColor(Qt.darkGray))
painter.drawPath(self.grip_shadow)
# draw circle shadow
painter.setPen(Qt.NoPen)
painter.setBrush(QColor(Qt.darkGray))
painter.drawPath(self.grip_shadow)
# circle gradient color
if self.isSelected():
self.gradient.setColorAt(0, self.color.lighter(170))
self.gradient.setColorAt(1, self.color.darker(110))
else:
self.gradient.setColorAt(0, self.color.lighter(140))
self.gradient.setColorAt(1, self.color.darker(140))
# circle gradient color
if self.isSelected():
self.gradient.setColorAt(0, self.color.lighter(170))
self.gradient.setColorAt(1, self.color.darker(110))
else:
self.gradient.setColorAt(0, self.color.lighter(140))
self.gradient.setColorAt(1, self.color.darker(140))
# draw circle
painter.setBrush(QBrush(self.gradient))
painter.setPen(QPen(QColor(Qt.red), 0))
painter.drawPath(self.grip_shape)
# draw circle
painter.setBrush(QBrush(self.gradient))
painter.setPen(QPen(QColor(Qt.red), 0))
painter.drawPath(self.grip_shape)
def itemChange(self, change, value):
if change == QGraphicsItem.ItemPositionHasChanged:
......
......@@ -11,7 +11,7 @@ def _place_points(edge, count):
# edge to same node so identify a length higher than the node
h = 200 + 2*scale * count
l = QLineF(QPointF(0,0), QPointF(h,0))
l = QLineF(QPointF(0, 0), QPointF(h, 0))
# 0 degrees is at 3 o'clock, increasing clockwise
l.setAngle(90+60)
edge.cbp1 = p + l.p2()
......@@ -30,7 +30,7 @@ def _place_points(edge, count):
# skew overlapping edges
if count > 0:
angle = QLineF(source_p, dest_p).angle()
l = QLineF(QPointF(0,0), QPointF(scale * count,0))
l = QLineF(QPointF(0, 0), QPointF(scale * count, 0))
l.setAngle(angle+90)
# bow depending on orientation of nodes
......@@ -42,8 +42,8 @@ def _place_points(edge, count):
edge.cbp1 -= l.p2()
edge.cbp2 -= l.p2()
"""Set Cubic Bezier points cbp1 and cbp2 for the edge if not already set."""
class EdgePointPlacer():
"""Set Cubic Bezier points cbp1 and cbp2 for the edge if not already set."""
def __init__(self):
......
......@@ -2,13 +2,11 @@ from PyQt5.QtCore import QObject # for signal/slot support
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QMenu
from PyQt5.QtWidgets import QAction
from PyQt5.QtGui import QIcon
from graph_collapse_helpers import collapse_below, uncollapse_below
from graph_item import GraphItem
"""Provides event_menu."""
class EventMenu(QObject):
"""Provides event_menu."""
def __init__(self, graphs_manager, graph_list_widget, settings_manager):
super(EventMenu, self).__init__()
......
import os
from subprocess import Popen, PIPE
#import shutil
import json
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QFont
from PyQt5.QtGui import QFontMetrics
......@@ -9,20 +5,17 @@ from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QPainter
from PyQt5.QtGui import QColor, QLinearGradient, QBrush, QRadialGradient, QPen
from PyQt5.QtWidgets import QStyleOptionViewItem
from graph_item import GraphItem
from settings_manager import settings
"""export_trace_manager manages export of trace image files.
"""
# export trace as image file. Return (status)
def export_trace(trace_filename, graph_item):
"""export_trace_manager manages export of trace image files."""
# painting is much like GraphListItemDelegate.paint().
# also ref GraphMainView.drawBackground().
if graph_item == None:
return("Error: graph not available")
return "Error: graph not available"
# font height and banner height
font_height = QFontMetrics(QFont()).height()
......@@ -46,7 +39,7 @@ def export_trace(trace_filename, graph_item):
gradient.setColorAt(0.5, c)
gradient.setColorAt(1, c.darker(settings["graph_gradient"]))
# zz NOTE: painter must go beyond. Why? Use this workaround.
fill_rect = bounding_rect.adjusted(0, 0, 100,100)
fill_rect = bounding_rect.adjusted(0, 0, 100, 100)
painter.fillRect(fill_rect, QBrush(gradient))
# paint the graph index
......@@ -115,5 +108,5 @@ def export_trace(trace_filename, graph_item):
except Exception as e:
status = "Error exporting trace image file '%s': %s" % (
trace_filename, str(e))
return (status)
return status
......@@ -95,7 +95,7 @@ def collapsed_edges(graph_item):
print("collapsed_edges.a")
# make sure there are edges to work with
if not len(graph_item.edges):
if not graph_item.edges:
return (list(), list())
# identify the existing collapsed source_node, dest_node edge pairs
......@@ -105,22 +105,25 @@ def collapsed_edges(graph_item):
if edge.relation == "COLLAPSED_FOLLOWS":
existing_edge_pairs.add((edge.source_node, edge.dest_node))
existing_edges[(edge.source_node, edge.dest_node)] = edge
print("identified existing edge %s to %s" % (edge.source_node.label, edge.dest_node.label))
print("identified existing edge %s to %s" % (
edge.source_node.label, edge.dest_node.label))
# calculate the set of source_node, dest_node edge pairs
edge_pairs = set()
for edge in graph_item.edges:
if edge.relation == "FOLLOWS" and (edge.source_node.collapse
or edge.dest_node.collapse):
print("will add COLLAPSED_FOLLOWS to bridge: %s to %s" % (edge.source_node.label, edge.dest_node.label))
print("will add COLLAPSED_FOLLOWS to bridge: %s to %s" % (
edge.source_node.label, edge.dest_node.label))
# source and dest nodes
source_node_set = at_and_above_in_uncollapsed(edge.source_node)
dest_node_set = at_and_above_in_uncollapsed(edge.dest_node)
for source_node in source_node_set:
for dest_node in dest_node_set:
if source_node != dest_node:
print("adding %s to %s" % (source_node.label, dest_node.label))
edge_pairs.add((source_node, dest_node))
for dest_node in dest_node_set:
if source_node != dest_node:
print("adding %s to %s" % (
source_node.label, dest_node.label))
edge_pairs.add((source_node, dest_node))
# identify edges that need removed
removable_edges = list()
......
from PyQt5.QtCore import QRectF
# global constants and defaults
graphics_rect = QRectF(-50, -50, 25000, 25000)
GRAPHICS_RECT = QRectF(-50, -50, 25000, 25000)
from PyQt5.QtCore import QRect
from graph_constants import graphics_rect
from graph_constants import GRAPHICS_RECT
from graph_collapse_helpers import collapsed_edges
from edge import Edge
from edge_point_placer import EdgePointPlacer
"""Defines one graph item.
Data structures:
* index (int)
* mark (str)
* nodes (list<Node>)
* edges (list<Edge>)
NOTE: Optimization: call initialize_items and appearance just-in-time.
Set appearance when graph should be painted differently.
"""
class GraphItem():
"""Defines one graph item.
Data structures:
* index (int)
* mark (str)
* nodes (list<Node>)
* edges (list<Edge>)
NOTE: Optimization: call initialize_items and appearance just-in-time.
Set appearance when graph should be painted differently.
"""
def __init__(self, index, mark, probability, nodes, edges):
super(GraphItem, self).__init__()
......@@ -54,7 +53,7 @@ class GraphItem():
for node in self.nodes:
x = (node.x() - old_indent) / old_spacing * new_spacing + new_indent
node.setPos(x, node.y())
def change_v_spacing(self, old_spacing, old_indent,
new_spacing, new_indent):
for node in self.nodes:
......@@ -67,19 +66,19 @@ class GraphItem():
self.set_appearance()
# find the corners of this graph
min_x = graphics_rect.x() + graphics_rect.width()
max_x = graphics_rect.x()
min_y = graphics_rect.y() + graphics_rect.height()
max_y = graphics_rect.y()
min_x = GRAPHICS_RECT.x() + GRAPHICS_RECT.width()
max_x = GRAPHICS_RECT.x()
min_y = GRAPHICS_RECT.y() + GRAPHICS_RECT.height()
max_y = GRAPHICS_RECT.y()
for node in self.nodes:
if node.x() - node.w/2 < min_x:
min_x = node.x() - node.w/2
if node.x() + node.w/2 > max_x:
max_x = node.x() + node.w/2
if node.y() - node.h/2 < min_y:
min_y = node.y() - node.h/2
if node.y() + node.h/2 > max_y:
max_y = node.y() + node.h/2
if node.x() - node.w/2 < min_x:
min_x = node.x() - node.w/2
if node.x() + node.w/2 > max_x:
max_x = node.x() + node.w/2
if node.y() - node.h/2 < min_y:
min_y = node.y() - node.h/2
if node.y() + node.h/2 > max_y:
max_y = node.y() + node.h/2
return QRect(min_x, min_y, max_x-min_x, max_y-min_y)
......@@ -94,7 +93,7 @@ class GraphItem():
# diagnostics
def _print_totals(self):
if not len(self.edges):
if not self.edges:
print("Totals: None, empty graph.")
return
......@@ -110,7 +109,10 @@ class GraphItem():
for node in self.nodes:
edge_list_total += len(node.edge_list)
print("Totals: scene: %d, graph: %d, graph nodes: %d, graph edges: %d, edge list total: %d" % (scene_item_total, graph_item_total, len(self.nodes), len(self.edges), edge_list_total))
print("Totals: scene: %d, graph: %d, graph nodes: %d, "
"graph edges: %d, edge list total: %d" % (
scene_item_total, graph_item_total,
len(self.nodes), len(self.edges), edge_list_total))
# redo the list of collapsed edges in edges[] based on what is collapsed
def set_collapsed_edges(self):
......
......@@ -4,8 +4,7 @@ from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QSplitter
class GraphListColumn(QWidget):
"""Container for trace navigation and graph list
"""
"""Container for trace navigation and graph list"""
def __init__(self, gui_manager):
super(GraphListColumn, self).__init__()
......
from PyQt5.QtCore import QObject # for signal/slot support
from PyQt5.QtGui import QColor
from PyQt5.QtGui import QRadialGradient
from PyQt5.QtGui import QBrush
from PyQt5.QtGui import QPen
from PyQt5.QtGui import QTransform
from PyQt5.QtGui import QFontMetrics
from PyQt5.QtGui import QFont
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QRectF, QRect
from PyQt5.QtCore import QAbstractListModel
from PyQt5.QtCore import QSortFilterProxyModel
#from PyQt5.QtCore import QSortFilterProxyModel
from PyQt5.QtCore import QVariant
#from PyQt5.QtCore import QModelIndex
from PyQt5.QtCore import QSize
from PyQt5.QtWidgets import QListView
from PyQt5.QtWidgets import QStyledItemDelegate
from PyQt5.QtWidgets import QListWidgetItem
from PyQt5.QtWidgets import QStyle
from graph_item import GraphItem
from graph_constants import graphics_rect
"""GraphListWidget provides the graph list. It wraps details of parts,
ref. http://doc.qt.io/qt-5/model-view-programming.html.
Parts:
* GraphListModel Provides graphs from graph_manager
zz FUTURE * GraphProxyModel Sits between model and view to provide sort and
filter functions
* GraphListView Manages view
* GraphListItemDelegate Provides the paint function for each graph list item
Signals:
* signal_graph_selection_changed(GraphItem)
"""
# GraphListModel
"""Links the QAbstractListModel to the graph_manager's list subscript.
Listens to graphs_manager graph changed event to replace the data."""
# ref. https://stackoverflow.com/questions/17231184/insert-and-remove-items-from-a-qabstractlistmodel
class GraphListModel(QAbstractListModel):
"""Links the QAbstractListModel to the graph_manager's list subscript.
Listens to graphs_manager graph changed event to replace the data."""
# ref. https://stackoverflow.com/questions/17231184/insert-and-remove-items-from-a-qabstractlistmodel
def __init__(self, graphs_manager):
super(GraphListModel, self).__init__()
......@@ -84,12 +64,12 @@ class GraphListView(QListView):
self.changed_width)
# user selection changed
def currentChanged(self, current, previous):
def currentChanged(self, current, _previous):
self.graph_list_widget.selection_changed(current.row())
# width changed
@pyqtSlot(int)
def changed_width(self, width):
def changed_width(self, _width):
# no: self.update()
# hack from https://stackoverflow.com/questions/16444558/how-to-force-qabstractitemview-recalculate-items-sizehints
hack_size = self.viewport().size()
......@@ -152,7 +132,7 @@ class GraphListItemDelegate(QStyledItemDelegate):
else:
background_color = QColor(Qt.blue).lighter(192)
painter.fillRect(option.rect.adjusted(0,0,0,-1), background_color)
painter.fillRect(option.rect.adjusted(0, 0, 0, -1), background_color)
# translate axis to cell
painter.translate(option.rect.x(), option.rect.y())
......@@ -223,7 +203,7 @@ class GraphListItemDelegate(QStyledItemDelegate):
painter.restore()
# sizeHint
def sizeHint(self, option, model_index):
def sizeHint(self, _option, _model_index):
# Make width hint narrow to prevent horizontal scrollbar.
# Use a small width hint. It needs to be smaller than list width
# minus scrollbar width minus widget padding, which might be four.
......@@ -254,7 +234,7 @@ class GraphListItemDelegate(QStyledItemDelegate):
# self.sort(0) # list so sort column 0
#
# def lessThan(self, left, right): # QModelIndex
# print("lessThan %s %d %d" % (self.sort_mode,
# print("lessThan %s %d %d" % (self.sort_mode,
# self.graphs_manager.graphs[left.row()].index,
# self.graphs_manager.graphs[right.row()].index))
#
......@@ -274,6 +254,19 @@ class GraphListItemDelegate(QStyledItemDelegate):
# self.graphs_manager.graphs[right.row()].index
class GraphListWidget(QObject):
"""GraphListWidget provides the graph list. It wraps details of parts,
ref. http://doc.qt.io/qt-5/model-view-programming.html.
Parts:
* GraphListModel Provides graphs from graph_manager
zz FUTURE * GraphProxyModel Sits between model and view to provide sort and
filter functions
* GraphListView Manages view
* GraphListItemDelegate Provides the paint function for each graph list item
Signals:
* signal_graph_selection_changed(GraphItem)
"""
# signals
signal_graph_selection_changed = pyqtSignal(GraphItem,
......@@ -296,7 +289,7 @@ class GraphListWidget(QObject):
# view calls this when the user selection changed
def selection_changed(self, graph_subscript):
if (graph_subscript == -1):
if graph_subscript == -1:
# nothing selected
return
......@@ -310,17 +303,16 @@ class GraphListWidget(QObject):
self.graphs_manager.graphs.index(graph))
self.view.setCurrentIndex(list_model_index)
return True
else:
return False
return False
# get the graph that is selected in the model else None
def selected_graph(self):
graph_subscript = self.view.currentIndex().row()
if graph_subscript == -1:
return None
else:
# graph_index associated with the selected data model index
return self.graphs_manager.graphs[graph_subscript]
# use graph_index associated with the selected data model index
return self.graphs_manager.graphs[graph_subscript]
# signal this to signal when the graph item needs repainted in the list
@pyqtSlot(GraphItem)
......
from PyQt5.QtCore import QObject # for signal/slot support
from PyQt5.QtCore import pyqtSignal # for signal/slot support
from PyQt5.QtCore import pyqtSlot # for signal/slot support
"""Track graph list width and signal change
Data:
* width - width of the graph list available in the list splitpane
class GraphListWidthManager(QObject):
"""Track graph list width and signal change
Signals:
* signal_graph_list_width_changed(int) - width of graph list changed
"""
Data:
* width - width of the graph list available in the list splitpane
class GraphListWidthManager(QObject):
Signals:
* signal_graph_list_width_changed(int) - width of graph list changed
"""
# signals
signal_graph_list_width_changed = pyqtSignal(int,
......
......@@ -9,35 +9,33 @@
# Adapted from https://raw.githubusercontent.com/baoboa/pyqt5/master/examples/graphicsview/elasticnodes.py
import math
from PyQt5.QtCore import (QLineF, QPointF, qrand, QRect, QRectF, QSizeF, Qt)
from PyQt5.QtCore import QPoint
from PyQt5.QtCore import QRectF, Qt
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import QObject
from PyQt5.QtGui import (QBrush, QColor, QLinearGradient, QPainter,
QPainterPath, QPen, QPolygonF, QRadialGradient)
from PyQt5.QtGui import QBrush, QColor, QLinearGradient, QPainter, QPen
from PyQt5.QtGui import QTransform
from PyQt5.QtWidgets import (QGraphicsItem, QGraphicsView, QStyle)
from PyQt5.QtWidgets import QGraphicsView
from PyQt5.QtWidgets import QGraphicsScene
from graph_constants import graphics_rect
from graph_constants import GRAPHICS_RECT
from graph_item import GraphItem
from settings_manager import settings
from graph_collapse_helpers import collapse_below, uncollapse_below
#from node import Node # for Node detection
from edge_grip import EdgeGrip
"""GraphMainWidget provides the main QGraphicsView. It manages signals
and wraps these:
* GraphMainView
* GraphMainScene
GraphMainWidget also issues signal:
* signal_graph_item_view_changed = pyqtSignal(GraphItem,
name='graphItemViewChanged')
"""
# GraphicsView
class GraphMainView(QGraphicsView):
"""GraphMainWidget provides the main QGraphicsView. It manages signals
and wraps these:
* GraphMainView
* GraphMainScene
GraphMainWidget also issues signal:
* signal_graph_item_view_changed = pyqtSignal(GraphItem,
name='graphItemViewChanged')
"""
def __init__(self):
super(GraphMainView, self).__init__()
......@@ -49,7 +47,7 @@ class GraphMainView(QGraphicsView):
# enable user rectangular selection
self.setDragMode(QGraphicsView.RubberBandDrag)
self.viewport().setCursor(self.viewport_cursor)
self.setSceneRect(graphics_rect)
self.setSceneRect(GRAPHICS_RECT)
self.setMinimumSize(300, 300)
# Manage restorable scaling using scale_value, _rescale,
......@@ -82,7 +80,7 @@ class GraphMainView(QGraphicsView):
# poll specific view orientation
# return scale, x_slider, y_slider
def get_view_orientation(self):
return (self._scale_value,
return (self._scale_value,
self.horizontalScrollBar().value(),
self.verticalScrollBar().value())
......@@ -280,7 +278,7 @@ class GraphMainScene(QGraphicsScene):
# if down click happens and not over grip then turn off grips
g1 = self.source_edge_grip
g2 = self.dest_edge_grip
if not ((g1.isUnderMouse() and g1.isVisible()) or
if not ((g1.isUnderMouse() and g1.isVisible()) or
(g2.isUnderMouse() and g2.isVisible())):
self.clear_grips()
super(GraphMainScene, self).mousePressEvent(event)
......@@ -328,7 +326,7 @@ class GraphMainWidget(QObject):
# call this to emit indication that the main view geometry changed somehow
@pyqtSlot('QList<QRectF>')
def changed_main_view(self, region):
def changed_main_view(self, _region):
if self.scene.graph_item:
self.signal_graph_item_view_changed.emit(self.scene.graph_item)
......
......@@ -9,8 +9,8 @@ from PyQt5.QtCore import QObject # for signal/slot support
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QLabel
"""Provides status text for graph traces in a QLabel."""
class GraphStatusLabel(QObject):
"""Provides status text for graph traces in a QLabel."""
def __init__(self, graphs_manager):
super(GraphStatusLabel, self).__init__()
......
from PyQt5.QtCore import QObject # for signal/slot support
from PyQt5.QtCore import pyqtSignal # for signal/slot support
from PyQt5.QtCore import pyqtSlot # for signal/slot support
from PyQt5.QtCore import QPointF # for node location float
"""Provides graphs (list<GraphItem>) and signals when the graph list
is loaded or cleared.
Register with signal_graphs_loaded to provide current graph list.
class GraphsManager(QObject):
"""Provides graphs (list<GraphItem>) and signals when the graph list
is loaded or cleared.
Data structures:
* schema_name (str)
* scope (int)
* graphs (list<GraphItem>)
Register with signal_graphs_loaded to provide current graph list.
Signals:
* signal_graphs_loaded() - graphs were loaded or cleared
* signal_appearance_changed() - graph appearance changed
"""
Data structures:
* schema_name (str)
* scope (int)
* graphs (list<GraphItem>)
class GraphsManager(QObject):
Signals:
* signal_graphs_loaded() - graphs were loaded or cleared
* signal_appearance_changed() - graph appearance changed
"""
# signals
signal_graphs_loaded = pyqtSignal(name='graphsLoaded')
......@@ -29,7 +28,7 @@ class GraphsManager(QObject):
# set initial state
self.clear_graphs()
# accept graph changes and signal appearance changed
# accept graph changes and signal appearance changed
settings_manager.signal_settings_changed.connect(
self.appearance_changed)
......
......@@ -5,20 +5,17 @@
# Added graph_list_column and trace_navigation classes
#
from PyQt5.QtWidgets import QMainWindow, QAction
import os
import webbrowser
from PyQt5.QtWidgets import QAction
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QSizePolicy
from PyQt5.QtWidgets import QStyle # for PM_ScrollBarExtent
from PyQt5.QtWidgets import QActionGroup
from PyQt5.QtWidgets import qApp
from PyQt5.QtWidgets import QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QObject
from PyQt5.QtCore import pyqtSlot
import os
import webbrowser
from version_file import VERSION
from main_splitter import MainSplitter
from mp_code_column import MPCodeColumn
......@@ -33,27 +30,26 @@ from graphs_manager import GraphsManager
from mp_code_editor import MPCodeEditor
from logger import Logger
import mp_code_io_manager
from mp_code_syntax_checker import parse_error_line_number
from mp_code_syntax_checker import parse_error_line_number, MPCodeSyntaxChecker
from trace_generator_manager import TraceGeneratorManager
import export_trace_manager
from settings_manager import SettingsManager, settings_themes
from settings_manager import SettingsManager, SETTINGS_THEMES
from settings_dialog_wrapper import SettingsDialogWrapper
from keyboard_dialog_wrapper import KeyboardDialogWrapper
from about_mp_dialog_wrapper import AboutMPDialogWrapper
from event_menu import EventMenu
from mp_code_syntax_checker import MPCodeSyntaxChecker
from path_constants import MP_CODE_EXAMPLES
"""MP main window containing menu, toolbar, statusbar, and central widget.
Central widget contains split pane areas, ref. http://firebird.nps.edu/:
code_area
console_area
graph_area
graph_list_area
"""
class GUIManager(QObject):
"""MP main window containing menu, toolbar, statusbar, and central widget.
Central widget contains split pane areas, ref. http://firebird.nps.edu/:
code_area
console_area
graph_area
graph_list_area
"""
def __init__(self, main_window):
super(GUIManager, self).__init__()
......@@ -80,7 +76,7 @@ class GUIManager(QObject):
self.w = main_window
# main window decoration
self.w.setGeometry(0,0,850,800)
self.w.setGeometry(0, 0, 850, 800)
self.w.setWindowTitle("Monterey Phoenix v4 - Gryphon GUI %s"%VERSION)
self.w.setWindowIcon(QIcon('icons/MP-logo-small-blue.png'))
......@@ -146,13 +142,13 @@ class GUIManager(QObject):
# the central widget containing the main split pane
self.mp_code_column = MPCodeColumn(self)
self.mp_code_column.set_sizes([600,200])
self.mp_code_column.set_sizes([600, 200])
self.graph_list_column = GraphListColumn(self)
self.graph_list_column.set_sizes([50,600])
self.graph_list_column.set_sizes([50, 600])
main_splitter.addWidget(self.mp_code_column)
main_splitter.addWidget(self.graph_main_widget.view)
main_splitter.addWidget(self.graph_list_column)
main_splitter.setSizes([250,500,100])
main_splitter.setSizes([250, 500, 100])
self.w.setCentralWidget(main_splitter)
# clean shutdown
......@@ -295,7 +291,7 @@ class GUIManager(QObject):
os.path.join(MP_CODE_EXAMPLES, filename):
self.open_mp_code(filename))
self.open_examples_menu.addAction(action)
# menu | file | save MP Code
file_menu.addAction(self.action_save_mp_code_file)
......@@ -345,7 +341,7 @@ class GUIManager(QObject):
settings_menu = preferences_menu.addMenu("Settings")
# menu | preferences | settings options
for theme_name, theme in settings_themes:
for theme_name, theme in SETTINGS_THEMES:
# add action with dedicated lambda function containing filename
action = QAction(theme_name, self)
......@@ -415,7 +411,7 @@ class GUIManager(QObject):
if filename:
# remember the preferred path
head, tail = os.path.split(filename)
head, _tail = os.path.split(filename)
self.preferred_mp_code_dir = head
# open the file
......@@ -532,8 +528,7 @@ class GUIManager(QObject):
@pyqtSlot()
def select_and_export_all_traces(self):
graph = self.graph_list_widget.selected_graph()
if not len(self.graphs_manager.graphs):
if not self.graphs_manager.graphs:
self.logger.log("Error exporting trace: There are no traces")
return
......@@ -659,7 +654,7 @@ class GUIManager(QObject):
# select graph at first row
# ref. https://stackoverflow.com/questions/6925951/how-to-select-a-row-in-a-qlistview
if len(graphs) > 0:
if graphs:
self.graph_list_widget.select_graph(graphs[0])
# set visual state
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment