Graph Element, Alternative Font support
This commit is contained in:
parent
b45a2572f0
commit
b72b98e87b
|
@ -10,7 +10,8 @@ from PySide2.QtWidgets import QApplication, QLabel, QWidget, QLineEdit, QComboBo
|
||||||
from PySide2.QtWidgets import QSlider, QCheckBox, QRadioButton, QSpinBox, QPushButton, QTextEdit, QMainWindow, QDialog, QAbstractItemView
|
from PySide2.QtWidgets import QSlider, QCheckBox, QRadioButton, QSpinBox, QPushButton, QTextEdit, QMainWindow, QDialog, QAbstractItemView
|
||||||
from PySide2.QtWidgets import QSpacerItem, QFrame, QGroupBox, QTextBrowser, QPlainTextEdit, QButtonGroup, QFileDialog, QTableWidget
|
from PySide2.QtWidgets import QSpacerItem, QFrame, QGroupBox, QTextBrowser, QPlainTextEdit, QButtonGroup, QFileDialog, QTableWidget
|
||||||
# from PySide2.QtWidgets import
|
# from PySide2.QtWidgets import
|
||||||
from PySide2.QtWidgets import QTableWidgetItem
|
from PySide2.QtWidgets import QTableWidgetItem, QGraphicsView, QGraphicsScene, QGraphicsItemGroup
|
||||||
|
from PySide2.QtGui import QPainter, QPixmap, QPen, QColor, QBrush, QPainterPath, QFont
|
||||||
from PySide2.QtCore import Qt,QProcess, QEvent
|
from PySide2.QtCore import Qt,QProcess, QEvent
|
||||||
import PySide2.QtGui as QtGui
|
import PySide2.QtGui as QtGui
|
||||||
import PySide2.QtCore as QtCore
|
import PySide2.QtCore as QtCore
|
||||||
|
@ -287,7 +288,12 @@ class Element():
|
||||||
self.Type = type
|
self.Type = type
|
||||||
self.AutoSizeText = auto_size_text
|
self.AutoSizeText = auto_size_text
|
||||||
self.Pad = DEFAULT_ELEMENT_PADDING if pad is None else pad
|
self.Pad = DEFAULT_ELEMENT_PADDING if pad is None else pad
|
||||||
self.Font = font
|
if font is not None and len(font) == 2:
|
||||||
|
self.Font = font
|
||||||
|
elif font is not None:
|
||||||
|
self.Font = font.split(' ')
|
||||||
|
else:
|
||||||
|
self.Font = font
|
||||||
|
|
||||||
self.TKStringVar = None
|
self.TKStringVar = None
|
||||||
self.TKIntVar = None
|
self.TKIntVar = None
|
||||||
|
@ -1501,13 +1507,15 @@ class Graph(Element):
|
||||||
self.CanvasSize = canvas_size
|
self.CanvasSize = canvas_size
|
||||||
self.BottomLeft = graph_bottom_left
|
self.BottomLeft = graph_bottom_left
|
||||||
self.TopRight = graph_top_right
|
self.TopRight = graph_top_right
|
||||||
self._TKCanvas = None
|
self.x = self.y = 0
|
||||||
self._TKCanvas2 = None
|
|
||||||
|
|
||||||
super().__init__(ELEM_TYPE_GRAPH, background_color=background_color, size=canvas_size, pad=pad, key=key,
|
super().__init__(ELEM_TYPE_GRAPH, background_color=background_color, size=canvas_size, pad=pad, key=key,
|
||||||
tooltip=tooltip)
|
tooltip=tooltip)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _convert_xy_to_canvas_xy(self, x_in, y_in):
|
def _convert_xy_to_canvas_xy(self, x_in, y_in):
|
||||||
scale_x = (self.CanvasSize[0] - 0) / (self.TopRight[0] - self.BottomLeft[0])
|
scale_x = (self.CanvasSize[0] - 0) / (self.TopRight[0] - self.BottomLeft[0])
|
||||||
scale_y = (0 - self.CanvasSize[1]) / (self.TopRight[1] - self.BottomLeft[1])
|
scale_y = (0 - self.CanvasSize[1]) / (self.TopRight[1] - self.BottomLeft[1])
|
||||||
|
@ -1518,13 +1526,14 @@ class Graph(Element):
|
||||||
def DrawLine(self, point_from, point_to, color='black', width=1):
|
def DrawLine(self, point_from, point_to, color='black', width=1):
|
||||||
converted_point_from = self._convert_xy_to_canvas_xy(point_from[0], point_from[1])
|
converted_point_from = self._convert_xy_to_canvas_xy(point_from[0], point_from[1])
|
||||||
converted_point_to = self._convert_xy_to_canvas_xy(point_to[0], point_to[1])
|
converted_point_to = self._convert_xy_to_canvas_xy(point_to[0], point_to[1])
|
||||||
if self._TKCanvas2 is None:
|
|
||||||
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
qcolor = QColor(color)
|
||||||
print('Call Window.Finalize() prior to this operation')
|
pen = QPen(qcolor, width)
|
||||||
return None
|
line = self.QT_QGraphicsScene.addLine(self.x+converted_point_from[0],self.y+ converted_point_from[1], self.x+converted_point_to[0],self.y+ converted_point_to[1], pen=pen)
|
||||||
return self._TKCanvas2.create_line(converted_point_from, converted_point_to, width=width, fill=color)
|
# self.QT_QGraphicsItemGroup.addToGroup(line)
|
||||||
|
|
||||||
def DrawPoint(self, point, size=2, color='black'):
|
def DrawPoint(self, point, size=2, color='black'):
|
||||||
|
self.QT_Q
|
||||||
converted_point = self._convert_xy_to_canvas_xy(point[0], point[1])
|
converted_point = self._convert_xy_to_canvas_xy(point[0], point[1])
|
||||||
if self._TKCanvas2 is None:
|
if self._TKCanvas2 is None:
|
||||||
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
||||||
|
@ -1536,13 +1545,13 @@ class Graph(Element):
|
||||||
|
|
||||||
def DrawCircle(self, center_location, radius, fill_color=None, line_color='black'):
|
def DrawCircle(self, center_location, radius, fill_color=None, line_color='black'):
|
||||||
converted_point = self._convert_xy_to_canvas_xy(center_location[0], center_location[1])
|
converted_point = self._convert_xy_to_canvas_xy(center_location[0], center_location[1])
|
||||||
if self._TKCanvas2 is None:
|
qcolor = QColor(fill_color)
|
||||||
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
pen = QPen(qcolor)
|
||||||
print('Call Window.Finalize() prior to this operation')
|
qcolor = QColor(line_color)
|
||||||
return None
|
brush = QBrush(qcolor)
|
||||||
return self._TKCanvas2.create_oval(converted_point[0] - radius, converted_point[1] - radius,
|
line = self.QT_QGraphicsScene.addEllipse(self.x+converted_point[0], self.y+converted_point[1],
|
||||||
converted_point[0] + radius, converted_point[1] + radius, fill=fill_color,
|
radius, radius, pen=pen, brush=brush)
|
||||||
outline=line_color)
|
|
||||||
|
|
||||||
def DrawOval(self, top_left, bottom_right, fill_color=None, line_color=None):
|
def DrawOval(self, top_left, bottom_right, fill_color=None, line_color=None):
|
||||||
converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1])
|
converted_top_left = self._convert_xy_to_canvas_xy(top_left[0], top_left[1])
|
||||||
|
@ -1577,13 +1586,16 @@ class Graph(Element):
|
||||||
|
|
||||||
def DrawText(self, text, location, color='black', font=None, angle=0):
|
def DrawText(self, text, location, color='black', font=None, angle=0):
|
||||||
converted_point = self._convert_xy_to_canvas_xy(location[0], location[1])
|
converted_point = self._convert_xy_to_canvas_xy(location[0], location[1])
|
||||||
if self._TKCanvas2 is None:
|
|
||||||
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
qcolor = QColor(color)
|
||||||
print('Call Window.Finalize() prior to this operation')
|
qpath = QPainterPath()
|
||||||
return None
|
_font = font or ('courier', 12)
|
||||||
text_id = self._TKCanvas2.create_text(converted_point[0], converted_point[1], text=text, font=font, fill=color,
|
qfont = QFont(_font[0], _font[1])
|
||||||
angle=angle)
|
# qfont.setWeight(.5)
|
||||||
return text_id
|
|
||||||
|
qpath.addText(self.x+converted_point[0], self.y+converted_point[1], qfont, str(text))
|
||||||
|
self.QT_QGraphicsScene.addPath(qpath, qcolor)
|
||||||
|
|
||||||
|
|
||||||
def Erase(self):
|
def Erase(self):
|
||||||
if self._TKCanvas2 is None:
|
if self._TKCanvas2 is None:
|
||||||
|
@ -1600,14 +1612,17 @@ class Graph(Element):
|
||||||
self._TKCanvas2.configure(background=background_color)
|
self._TKCanvas2.configure(background=background_color)
|
||||||
|
|
||||||
def Move(self, x_direction, y_direction):
|
def Move(self, x_direction, y_direction):
|
||||||
|
x_direction = -x_direction
|
||||||
|
y_direction = -y_direction
|
||||||
zero_converted = self._convert_xy_to_canvas_xy(0, 0)
|
zero_converted = self._convert_xy_to_canvas_xy(0, 0)
|
||||||
shift_converted = self._convert_xy_to_canvas_xy(x_direction, y_direction)
|
shift_converted = self._convert_xy_to_canvas_xy(x_direction, y_direction)
|
||||||
shift_amount = (shift_converted[0] - zero_converted[0], shift_converted[1] - zero_converted[1])
|
shift_amount = (shift_converted[0] - zero_converted[0], shift_converted[1] - zero_converted[1])
|
||||||
if self._TKCanvas2 is None:
|
rect = self.QT_QGraphicsScene.sceneRect()
|
||||||
print('*** WARNING - The Graph element has not been finalized and cannot be drawn upon ***')
|
rect.translate(shift_amount[0], shift_amount[1])
|
||||||
print('Call Window.Finalize() prior to this operation')
|
self.x += shift_amount[0]
|
||||||
return None
|
self.y += shift_amount[1]
|
||||||
self._TKCanvas2.move('all', shift_amount[0], shift_amount[1])
|
self.QT_QGraphicsScene.setSceneRect(rect)
|
||||||
|
|
||||||
|
|
||||||
def MoveFigure(self, figure, x_direction, y_direction):
|
def MoveFigure(self, figure, x_direction, y_direction):
|
||||||
zero_converted = self._convert_xy_to_canvas_xy(0, 0)
|
zero_converted = self._convert_xy_to_canvas_xy(0, 0)
|
||||||
|
@ -2761,12 +2776,7 @@ class Window:
|
||||||
# return None, None
|
# return None, None
|
||||||
return self
|
return self
|
||||||
def Refresh(self):
|
def Refresh(self):
|
||||||
if self.TKrootDestroyed:
|
self.QTApplication.processEvents() # refresh the window
|
||||||
return self
|
|
||||||
try:
|
|
||||||
rc = self.TKroot.update()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def Fill(self, values_dict):
|
def Fill(self, values_dict):
|
||||||
|
@ -2930,7 +2940,8 @@ class Window:
|
||||||
:return:
|
:return:
|
||||||
'''
|
'''
|
||||||
self._AlphaChannel = alpha
|
self._AlphaChannel = alpha
|
||||||
self.TKroot.attributes('-alpha', alpha)
|
if self._AlphaChannel:
|
||||||
|
self.QTWindow.setWindowOpacity(self._AlphaChannel)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def AlphaChannel(self):
|
def AlphaChannel(self):
|
||||||
|
@ -4064,6 +4075,14 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
|
||||||
# ------------------------- Graph element ------------------------- #
|
# ------------------------- Graph element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_GRAPH:
|
elif element_type == ELEM_TYPE_GRAPH:
|
||||||
width, height = element_size
|
width, height = element_size
|
||||||
|
element.QT_QGraphicsView = QGraphicsView()
|
||||||
|
# element.QT_QGraphicsView.setGeometry(0,0,element.CanvasSize[0],element.CanvasSize[1])
|
||||||
|
element.QT_QGraphicsScene = QGraphicsScene()
|
||||||
|
element.QT_QGraphicsScene.setSceneRect(0,0,element.CanvasSize[0],element.CanvasSize[1])
|
||||||
|
element.QT_QGraphicsView.setScene(element.QT_QGraphicsScene)
|
||||||
|
element.QT_QGraphicsItemGroup = QGraphicsItemGroup()
|
||||||
|
qt_row_layout.addWidget(element.QT_QGraphicsView)
|
||||||
|
|
||||||
# ------------------------- MENUBAR element ------------------------- #
|
# ------------------------- MENUBAR element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_MENUBAR:
|
elif element_type == ELEM_TYPE_MENUBAR:
|
||||||
menu_def = element.MenuDefinition
|
menu_def = element.MenuDefinition
|
||||||
|
|
|
@ -129,14 +129,13 @@ These Elements are "complete" (a relative term... more are more complete than ot
|
||||||
* change_submits events
|
* change_submits events
|
||||||
* Updates
|
* Updates
|
||||||
* Image as a background (new feature)
|
* Image as a background (new feature)
|
||||||
|
* Graph - Draw line, draw circle, draw text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Missing Features
|
## Missing Features
|
||||||
|
|
||||||
Notable MISSING features at the moment include:
|
Notable MISSING features at the moment include:
|
||||||
* Graphs Element
|
* Graphs Element - erasing, draw arc, etc
|
||||||
* Image Element
|
* Image Element
|
||||||
* Tree Element - the more complex Elements have not yet been ported. Stay tuned, new ones being added daily!
|
* Tree Element - the more complex Elements have not yet been ported. Stay tuned, new ones being added daily!
|
||||||
* Tab & tab group Elements
|
* Tab & tab group Elements
|
||||||
|
|
Loading…
Reference in New Issue