Skip to content

Instantly share code, notes, and snippets.

@LeftRadio
Created December 6, 2015 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeftRadio/3e7ff93396ae88b93f1c to your computer and use it in GitHub Desktop.
Save LeftRadio/3e7ff93396ae88b93f1c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from ngl_utils.nplugins.widgets.ngl_base import NGL_Base
from ngl_utils.nplugins.widgets.qstyle_parser import QStyleParser
from PyQt5.QtCore import pyqtSlot, pyqtProperty, QRect, Qt
from PyQt5.QtGui import QPainter, QPen, QColor
class NGL_Greed(NGL_Base):
"""NGL_Greed(NGL_Base)
Provides a embedded NGL library greed widget.
"""
def __init__(self, parent=None):
""" Constructor for ngl widget """
super(NGL_Greed, self).__init__(parent)
self._static = False
self._central_lines = True
self._central_lines_color = QColor(Qt.red)
self._cell_width = 15
self._cell_height = 15
self.setGeometry(150, 150, 150, 150)
self.setStyleSheet('color: rgb(64, 64, 64);')
self.update()
def paintEvent(self, event):
""" Paint ngl widget event """
_width = self.geometry().width()
_x_2 = _width // 2
_height = self.geometry().height()
_y_2 = _height // 2
color = QStyleParser.getColor(self.styleSheet(), 'color: rgb')
p = QPainter()
p.begin(self)
p.setPen(color);
# horisontal steps
for x in range(_x_2, _width, self._cell_width):
p.drawLine(x, 0, x, _height-1)
for x in range(_x_2, 0, -self._cell_width):
p.drawLine(x, 0, x, _height-1)
# vertical steps
for y in range(_y_2, _width, self._cell_height):
p.drawLine(0, y, _width-1, y)
for y in range(_y_2, 0, -self._cell_height):
p.drawLine(0, y, _width-1, y)
if self._central_lines:
p.setPen(self._central_lines_color);
p.drawLine(_x_2, 0, _x_2, _height-1)
p.drawLine(0, _y_2, _width-1, _y_2)
p.end()
def sizeHint(self):
""" Return Qt sizeHint """
return self.size()
#
# Provide getter and setter methods for the property.
#
@pyqtProperty(bool)
def central_lines(self):
return self._central_lines
@central_lines.setter
def central_lines(self, state):
self._central_lines = state
self.update()
#
# Provide getter and setter methods for the property.
#
@pyqtProperty(QColor)
def central_lines_color(self):
return self._central_lines_color
@central_lines_color.setter
def central_lines_color(self, color):
self._central_lines_color = color
self.update()
#
# Provide getter and setter methods for the property.
#
@pyqtProperty(int)
def cell_width(self):
return self._cell_width
@cell_width.setter
def cell_width(self, width):
self._cell_width = width
self.update()
#
# Provide getter and setter methods for the property.
#
@pyqtProperty(bool)
def cell_height(self):
return self._cell_height
@cell_height.setter
def cell_height(self, height):
self._cell_height = height
self.update()
# if run as main program
if __name__ == "__main__":
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
widget = NGL_Greed()
widget.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment