-
Notifications
You must be signed in to change notification settings - Fork 0
/
gingawidgetFile.py
75 lines (61 loc) · 2.38 KB
/
gingawidgetFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
#
# gingawidgetFile.py --
# Plotting function for embedded matplotlib widget with Ginga.
#
# Thanks for Eric Jeschke (eric@naoj.org), https://github.com/ejeschke/ginga
# and
# https://gist.github.com/Maduranga/ for embedding matplotlibWidget into PyQt4
# Copyleft, Yücel Kılıç (yucelkilic@myrafproject.org) and
# Mohammad Niaei Shameoni (mshemuni@myrafproject.org).
# This is open-source software licensed under a GPLv3 license.
try:
from PyQt5 import QtWidgets
except Exception as e:
print("{}. PyQt5 is not installed?".format(e))
exit(0)
try:
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
except Exception as e:
print("{}. Mtplotlib is not installed?".format(e))
exit(0)
try:
from myraflib import myEnv
except Exception as e:
print("{}. Cannot find myraflib".format(e))
exit(0)
class MplCanvas(FigureCanvas):
def __init__(self, verb=True):
self.verb = verb
self.etc = myEnv.etc(verb=self.verb)
self.fop = myEnv.file_op(verb=self.verb)
if not self.fop.is_dir(self.etc.log_dir):
self.fop.mkdir(self.etc.log_dir)
# create a regular matplotlib figure
self.etc.log("gingawidgetFile is doing something(MplCanvas).")
try:
self.fig = plt.figure()
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding,
QtWidgets.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
except Exception as e:
self.etc.log(e)
class gingaWidget(QtWidgets.QWidget):
def __init__(self, parent=None, verb=True):
self.verb = verb
self.etc = myEnv.etc(verb=self.verb)
self.fop = myEnv.file_op(verb=self.verb)
if not self.fop.is_dir(self.etc.log_dir):
self.fop.mkdir(self.etc.log_dir)
self.etc.log("gingawidgetFile is doing something(gingaWidget).")
try:
QtWidgets.QWidget.__init__(self, parent)
self.canvas = MplCanvas()
self.vbl = QtWidgets.QVBoxLayout()
self.vbl.addWidget(self.canvas)
self.setLayout(self.vbl)
self.parent = parent
except Exception as e:
self.etc.log(e)