Skip to content
Snippets Groups Projects
Commit a24f9545 authored by Rohan Daruwala's avatar Rohan Daruwala
Browse files

Cleaned up unneeded files

parent 46d7a994
Branches develop
No related tags found
No related merge requests found
File deleted
%% Cell type:code id: tags:
``` python
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import json
import os
import math
from ipywidgets import *
from IPython.display import display
from tkinter import *
```
%% Cell type:code id: tags:
``` python
class GradientControl(QtGui.QWidget):
def __init__(self, parent=None, **kwargs):
super(GradientControl, self).__init__(parent)
l = QtGui.QGridLayout()
l.setSpacing(0)
self.setLayout(l)
self.gData = {}
try:
f = open('data.json', 'x+')
except FileExistsError:
if os.stat("data.json").st_size != 0:
self.gData = json.loads(open('data.json').read())
print(self.gData)
else:
print("Empty json file found.")
self.ColorBar = pg.GradientWidget(orientation='bottom')
self.ColorBar.hide()
self.SaveButton = QtGui.QPushButton("Save Gradient")
self.SaveButton.clicked.connect(self.on_save_click)
self.ImportButton = QtGui.QPushButton("Import Gradient")
self.ImportButton.clicked.connect(self.importButtonClick)
#Create Gradient List and Related Functions
self.List = QtGui.QListWidget()
self.List.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.List.itemSelectionChanged.connect(self.updateColorBar)
#Create SQRT Buttonand Related Functions
self.sqrt = QtGui.QCheckBox("SQRT")
self.sqrt.stateChanged.connect(self.sqrtAction)
self.CloseButton = QtGui.QPushButton("Close")
self.CloseButton.clicked.connect(self.closeButtonClick)
#Create Delete Buttonand Related Functions
self.DeleteButton = QtGui.QPushButton("Delete Gradient")
self.DeleteButton.clicked.connect(self.deleteButtonClick)
self.DeleteButton.hide()
#Create Export Buttonand Related Functions
self.ExportButton = QtGui.QPushButton("Export Gradient")
self.ExportButton.clicked.connect(self.exportButtonClick)
self.ExportButton.hide()
self.updateListWidget()
l.addWidget(self.ImportButton, 0, 0)
l.addWidget(self.sqrt, 1, 2)
l.addWidget(self.ColorBar, 2, 1)
l.addWidget(self.SaveButton, 1, 0)
l.addWidget(self.List, 1, 1)
l.addWidget(self.CloseButton, 6, 2)
l.addWidget(self.ExportButton, 2, 2)
l.addWidget(self.DeleteButton, 2, 0)
def on_save_click(self):
print(self.SaveButton.text())
self.p = QtGui.QWidget()
self.p.setWindowTitle('Save Gradient As:')
self.p.textbox = QtGui.QLineEdit(self.p)
self.p.textbox.move(20, 20)
self.p.textbox.resize(280,40)
self.p.resize(320, 150)
button = QtGui.QPushButton('Save', self.p)
button.move(20,80)
button.clicked.connect(self.on_save_click_2)
self.p.setWindowModality(QtCore.Qt.WindowModal)
self.p.show()
def getSelected(self):
toReturn = []
ListCount = self.List.count()
index = 0
while index < ListCount:
if(self.List.item(index).isSelected()):
toReturn.append(self.List.item(index))
index = index + 1
return toReturn
def on_save_click_2(self):
SaveName = self.p.textbox.text()
if SaveName in self.gData.keys():
overwrite_msg = "There is already a save with this name. Would you like to Overwrite?"
reply = QtGui.QMessageBox.question(self, 'Message',
overwrite_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.gData[SaveName] = self.ColorBar.saveState()
self.saveData()
self.p.close()
else:
self.gData[SaveName] = self.ColorBar.saveState()
self.saveData()
self.p.close()
self.updateListWidget()
def saveData(self):
with open('data.json', 'w') as fp:
json.dump(self.gData, fp)
def importButtonClick(self):
print(self.ImportButton.text())
def closeButtonClick(self):
sys.exit(main())
def updateListWidget(self):
self.List.clear()
self.ExportButton.hide()
self.DeleteButton.hide()
for key in self.gData.keys():
self.List.addItem(key)
def updateColorBar(self):
self.ExportButton.show()
self.ColorBar.show()
self.DeleteButton.show()
self.sqrt.setCheckState(0)
if self.List.item(self.List.currentRow()).text() in self.gData.keys():
NewBar = self.gData[self.List.item(self.List.currentRow()).text()]
self.ColorBar.restoreState(NewBar)
SelectedThings = self.getSelected()
print(len(SelectedThings))
if len(SelectedThings) > 1:
self.ColorBar.hide()
self.SaveButton.hide()
self.sqrt.hide()
else:
self.ColorBar.show()
self.SaveButton.show()
self.sqrt.show()
def sqrtAction(self):
if self.sqrt.isChecked() == True:
tickList = self.ColorBar.listTicks()
for tick in tickList:
self.ColorBar.setTickValue(tick[0], math.sqrt(self.ColorBar.tickValue(tick[0])))
else:
tickList = self.ColorBar.listTicks()
for tick in tickList:
self.ColorBar.setTickValue(tick[0], self.ColorBar.tickValue(tick[0]) * self.ColorBar.tickValue(tick[0]))
def deleteButtonClick(self):
delete_msg = "Please confirm you want to delete the Gradient: " + self.List.item(self.List.currentRow()).text() + ""
reply = QtGui.QMessageBox.question(self, 'Message',
delete_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
del self.gData[self.List.item(self.List.currentRow()).text()]
self.updateListWidget()
def exportButtonClick(self):
print("Export!")
def main():
app = QtGui.QApplication([])
w = GradientControl()
w.show()
app.exec_()
return 0
if __name__ == '__main__':
sys.exit(main())
```
%% Output
{'test': {'mode': 'rgb', 'ticks': [[0, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.0, [0, 0, 0, 255]], [0.2196078431372549, [186, 186, 186, 255]], [0.6472476631101879, [255, 85, 0, 255]], [0.996078431372549, [255, 255, 0, 255]], [1.0, [255, 255, 0, 255]]]}, 'test2': {'mode': 'rgb', 'ticks': [[0.012841091492776886, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.07062600321027288, [255, 0, 255, 255]], [0.19028105624272182, [24, 24, 24, 255]], [0.2340540710666289, [186, 186, 186, 255]], [0.27471123280772985, [196, 196, 196, 255]], [0.43449469675510655, [224, 224, 224, 255]], [0.36795392314229064, [251, 251, 251, 255]], [0.4746042237119567, [255, 166, 125, 255]], [0.949529474711233, [255, 255, 0, 255]], [0.8924558587479936, [255, 85, 127, 255]], [0.15008025682182985, [85, 85, 0, 255]], [0.6524879614767255, [85, 170, 255, 254]], [0.5674157303370787, [1, 1, 1, 254]], [0.7199036918138041, [3, 3, 0, 254]], [0.7953451043338684, [85, 85, 255, 254]]]}, 'temp': {'mode': 'rgb', 'ticks': [[0.012841091492776886, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.07062600321027288, [255, 0, 255, 255]], [0.19028105624272182, [24, 24, 24, 255]], [0.2340540710666289, [186, 186, 186, 255]], [0.27471123280772985, [196, 196, 196, 255]], [0.43449469675510655, [224, 224, 224, 255]], [0.36795392314229064, [251, 251, 251, 255]], [0.4746042237119567, [255, 166, 125, 255]], [0.949529474711233, [255, 255, 0, 255]], [0.8924558587479936, [255, 85, 127, 255]], [0.15008025682182985, [85, 85, 0, 255]], [0.6524879614767255, [85, 170, 255, 254]], [0.5674157303370787, [1, 1, 1, 254]], [0.7199036918138041, [3, 3, 0, 254]], [0.7953451043338684, [85, 85, 255, 254]]]}, 'sqrtTest': {'mode': 'rgb', 'ticks': [[0.11331853993401471, [0, 0, 0, 255]], [1.0, [255, 0, 0, 255]], [0.26575553279334163, [255, 0, 255, 255]], [0.4362121688384241, [24, 24, 24, 255]], [0.4837913507563244, [186, 186, 186, 255]], [0.5241290230541806, [196, 196, 196, 255]], [0.65916211720267, [224, 224, 224, 255]], [0.6065920566099515, [251, 251, 251, 255]], [0.688915251472891, [255, 166, 125, 255]], [0.974438030205735, [255, 255, 0, 255]], [0.9446988190677459, [255, 85, 127, 255]], [0.38740193187673944, [85, 85, 0, 255]], [0.8077672693769694, [85, 170, 255, 254]], [0.7532700248497073, [1, 1, 1, 254]], [0.8484713853830335, [3, 3, 0, 254]], [0.891821228909622, [85, 85, 255, 254]]]}}
1
1
2
3
1
2
1
2
3
4
1
2
3
1
2
3
4
0
{'test': {'mode': 'rgb', 'ticks': [[0, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.0, [0, 0, 0, 255]], [0.2196078431372549, [186, 186, 186, 255]], [0.6472476631101879, [255, 85, 0, 255]], [0.996078431372549, [255, 255, 0, 255]], [1.0, [255, 255, 0, 255]]]}, 'test2': {'mode': 'rgb', 'ticks': [[0.012841091492776886, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.07062600321027288, [255, 0, 255, 255]], [0.19028105624272182, [24, 24, 24, 255]], [0.2340540710666289, [186, 186, 186, 255]], [0.27471123280772985, [196, 196, 196, 255]], [0.43449469675510655, [224, 224, 224, 255]], [0.36795392314229064, [251, 251, 251, 255]], [0.4746042237119567, [255, 166, 125, 255]], [0.949529474711233, [255, 255, 0, 255]], [0.8924558587479936, [255, 85, 127, 255]], [0.15008025682182985, [85, 85, 0, 255]], [0.6524879614767255, [85, 170, 255, 254]], [0.5674157303370787, [1, 1, 1, 254]], [0.7199036918138041, [3, 3, 0, 254]], [0.7953451043338684, [85, 85, 255, 254]]]}, 'temp': {'mode': 'rgb', 'ticks': [[0.012841091492776886, [0, 0, 0, 255]], [1, [255, 0, 0, 255]], [0.07062600321027288, [255, 0, 255, 255]], [0.19028105624272182, [24, 24, 24, 255]], [0.2340540710666289, [186, 186, 186, 255]], [0.27471123280772985, [196, 196, 196, 255]], [0.43449469675510655, [224, 224, 224, 255]], [0.36795392314229064, [251, 251, 251, 255]], [0.4746042237119567, [255, 166, 125, 255]], [0.949529474711233, [255, 255, 0, 255]], [0.8924558587479936, [255, 85, 127, 255]], [0.15008025682182985, [85, 85, 0, 255]], [0.6524879614767255, [85, 170, 255, 254]], [0.5674157303370787, [1, 1, 1, 254]], [0.7199036918138041, [3, 3, 0, 254]], [0.7953451043338684, [85, 85, 255, 254]]]}, 'sqrtTest': {'mode': 'rgb', 'ticks': [[0.11331853993401471, [0, 0, 0, 255]], [1.0, [255, 0, 0, 255]], [0.26575553279334163, [255, 0, 255, 255]], [0.4362121688384241, [24, 24, 24, 255]], [0.4837913507563244, [186, 186, 186, 255]], [0.5241290230541806, [196, 196, 196, 255]], [0.65916211720267, [224, 224, 224, 255]], [0.6065920566099515, [251, 251, 251, 255]], [0.688915251472891, [255, 166, 125, 255]], [0.974438030205735, [255, 255, 0, 255]], [0.9446988190677459, [255, 85, 127, 255]], [0.38740193187673944, [85, 85, 0, 255]], [0.8077672693769694, [85, 170, 255, 254]], [0.7532700248497073, [1, 1, 1, 254]], [0.8484713853830335, [3, 3, 0, 254]], [0.891821228909622, [85, 85, 255, 254]]]}}
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 1
}
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 1
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment