Created
December 5, 2015 23:19
-
-
Save LeftRadio/4652b9d330b7c5015b8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(100, 100, 100, 100) | |
self.setStyleSheet('color: rgb(64, 64, 64);') | |
self.update() | |
def paintEvent(self, event): | |
""" Paint ngl widget event """ | |
_width = self.geometry().width() | |
_height = self.geometry().height() | |
color = QStyleParser.getColor(self.styleSheet(), 'color: rgb') | |
p = QPainter() | |
p.begin(self) | |
p.setPen(color); | |
for x in range(_width): | |
if x % self._cell_width == 0: | |
p.drawLine(x, 0, x, _height) | |
for y in range(_height): | |
if y % self._cell_height == 0: | |
p.drawLine(0, y, _width, y) | |
if self._central_lines: | |
p.setPen(self._central_lines_color); | |
p.drawLine(_width/2, 0, _width/2, _height) | |
p.drawLine(0, _height/2, _width, _height/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