Skip to content

Commit

Permalink
Added features:
Browse files Browse the repository at this point in the history
- label tracking independent of lines
- completely hiding graph
  • Loading branch information
ArtificialQualia committed Aug 8, 2017
1 parent a963597 commit 6e5f6e6
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 47 deletions.
42 changes: 33 additions & 9 deletions PyEveLiveDPS/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class DPSGraph(tk.Frame):
"capDamageOut": { "zorder": 40 },
"capDamageIn": { "zorder": 30 }
}
def __init__(self, characterDetector, settings, labelHandler, **kwargs):
tk.Frame.__init__(self, **kwargs)
def __init__(self, parent, characterDetector, settings, labelHandler, **kwargs):
tk.Frame.__init__(self, parent, **kwargs)

self.labelHandler = labelHandler
self.settings = settings
Expand Down Expand Up @@ -102,6 +102,11 @@ def changeSettings(self):
self.categories["capDamageOut"]["settings"] = self.settings.getCapDamageOutSettings()
self.categories["capDamageIn"]["settings"] = self.settings.getCapDamageInSettings()

if self.settings.getGraphDisabled():
self.grid_remove()
else:
self.grid()

self.labelHandler.redoLabels()

for category, items in self.categories.items():
Expand All @@ -110,8 +115,14 @@ def changeSettings(self):
items["historical"] = [0] * int((self.seconds*1000)/self.interval)
items["yValues"] = np.array([0] * int((self.seconds*1000)/self.interval))
ySmooth = self.smoothListGaussian(items["yValues"], self.degree)
plotLine, = self.subplot.plot(ySmooth, zorder=items["zorder"])
items["lines"] = [plotLine]
try:
items["labelOnly"] = items["settings"][0]["labelOnly"]
except KeyError:
items["settings"][0]["labelOnly"] = False
items["labelOnly"] = items["settings"][0]["labelOnly"]
if not items["labelOnly"]:
plotLine, = self.subplot.plot(ySmooth, zorder=items["zorder"])
items["lines"] = [plotLine]
else:
self.labelHandler.enableLabel(category, False)

Expand Down Expand Up @@ -181,17 +192,30 @@ def animate(self, i):
items["yValues"] = items["yValues"][1:]
average = (np.sum(items["historical"])*(1000/self.interval))/len(items["historical"])
items["yValues"] = np.append(items["yValues"], average)
ySmooth = self.smoothListGaussian(items["yValues"], self.degree)
self.animateLine(ySmooth, items["settings"], items["lines"], zorder=items["zorder"])
self.labelHandler.updateLabel(category, average, matplotlib.colors.to_hex(items["lines"][-1].get_color()))
if not items["labelOnly"]:
ySmooth = self.smoothListGaussian(items["yValues"], self.degree)
self.animateLine(ySmooth, items["settings"], items["lines"], zorder=items["zorder"])
self.labelHandler.updateLabel(category, average, matplotlib.colors.to_hex(items["lines"][-1].get_color()))
else:
for index, item in enumerate(items["settings"]):
if index == (len(items["settings"])-1):
if average >= item["transitionValue"]:
self.labelHandler.updateLabel(category, average, item["color"])
elif average >= item["transitionValue"] and average < items["settings"][index+1]["transitionValue"]:
self.labelHandler.updateLabel(category, average, item["color"])
break

#Find highest average for the y-axis scaling
self.highestAverage = 0
self.highestLabelAverage = 0
for i in range(int((self.seconds*1000)/self.interval)):
for category, items in self.categories.items():
if items["settings"]:
if items["settings"] and not items["labelOnly"]:
if (items["yValues"][i] > self.highestAverage):
self.highestAverage = items["yValues"][i]
elif items["settings"]:
if (items["yValues"][i] > self.highestAverage):
self.highestLabelAverage = items["yValues"][i]

if (self.highestAverage < 100):
self.graphFigure.axes[0].set_ylim(bottom=0, top=100)
Expand All @@ -200,7 +224,7 @@ def animate(self, i):
self.graphFigure.axes[0].get_yaxis().grid(True, linestyle="-", color="grey", alpha=0.2)
self.readjust(self.windowWidth)

if (self.highestAverage == 0):
if (self.highestAverage == 0 and self.highestLabelAverage == 0):
if not self.slowDown:
self.slowDown = True
self.ani.event_source._set_interval(500)
Expand Down
4 changes: 2 additions & 2 deletions PyEveLiveDPS/labelHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, parent, settings, makeAllChildrenDraggable, **kwargs):
tk.Frame.__init__(self, parent, **kwargs)
self.settings = settings
self.makeAllChildrenDraggable = makeAllChildrenDraggable
self.grid_columnconfigure(9, weight="1")
self.columnconfigure(9, weight="1")

tk.Frame(self, width="1", height="1", background="black").grid(row="0", column="9", rowspan="10")

Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(self, parent, text, settings, **kwargs):
tk.Frame(self, width="1", height="1", background="black").grid(row="0", column="3")

tk.Label(self, text=text, fg="white", background="black").grid(row="0", column="1")
self.numberLabel = tk.Label(self, text="text", fg="white", background="black")
self.numberLabel = tk.Label(self, text="0.0", fg="white", background="black")
self.numberLabel.grid(row="0", column="2")

def updateLabel(self, number, color):
Expand Down
50 changes: 32 additions & 18 deletions PyEveLiveDPS/mainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):
self.columnconfigure(10, weight=1)
self.rowconfigure(10, weight=1)
self.configure(background="black")
self.minsize(175,100)
self.minsize(175,50)

#Grab settings from our settings handler
self.settings = settings.Settings()
Expand Down Expand Up @@ -94,26 +94,38 @@ def __init__(self):

self.addQuitButton()

self.addCollapseButton()
self.addCollapseButton(self, row="5", column="17")

self.addMenus()

#Container for our "dps labels"
self.labelHandler = labelHandler.LabelHandler(self, self.settings, lambda c:self.makeAllChildrenDraggable(c),
#Container for our "dps labels" and graph
self.middleFrame = tk.Frame(self, background="black")
self.middleFrame.columnconfigure(0, weight=1)
self.middleFrame.rowconfigure(1, weight=1)
self.middleFrame.grid(row="10", column="1", columnspan="19", sticky="news")
self.makeDraggable(self.middleFrame)

self.labelHandler = labelHandler.LabelHandler(self.middleFrame, self.settings, lambda c:self.makeAllChildrenDraggable(c),
height="10", borderwidth="0", background="black")
self.labelHandler.grid(row="6", column="1", columnspan="19", sticky="ew")
self.labelHandler.grid(row="0", column="0", sticky="news")
self.makeDraggable(self.labelHandler)

self.geometry("%sx%s+%s+%s" % (self.settings.getWindowWidth(), self.settings.getWindowHeight(),
self.settings.getWindowX(), self.settings.getWindowY()))
self.update_idletasks()

#The hero of our app
self.graphFrame = graph.DPSGraph(self.characterDetector, self.settings, self.labelHandler, background="black", borderwidth="0")
self.graphFrame.grid(row="7", column="1", rowspan="13", columnspan="19", sticky="nesw")
self.graphFrame = graph.DPSGraph(self.middleFrame, self.characterDetector, self.settings, self.labelHandler, background="black", borderwidth="0")
self.graphFrame.grid(row="1", column="0", columnspan="3", sticky="nesw")
self.makeDraggable(self.graphFrame.canvas.get_tk_widget())

self.graphFrame.readjust(self.winfo_width())
if self.settings.getGraphDisabled():
self.graphFrame.grid_remove()
else:
self.graphFrame.grid()

self.labelHandler.lift(self.graphFrame)

def addMenus(self):
#Set up menu options
Expand Down Expand Up @@ -216,23 +228,23 @@ def addQuitButton(self):
self.quitButton.bind("<Enter>", self.buttonGray25)
self.quitButton.bind("<Leave>", self.buttonBlack)

def addCollapseButton(self):
tk.Frame(self, height=1, width=5, background="black").grid(row="5", column="18")

self.rightSpacerFrame = tk.Frame(width=5, height=5, background="black")
self.rightSpacerFrame.grid(row="0", column="100", rowspan="50")
self.rightSpacerFrame.grid_remove()

def addCollapseButton(self, parent, row, column):
self.collapsed = False
self.collapseButton = tk.Canvas(width=15, height=15, background="black",
self.collapseButton = tk.Canvas(parent, width=15, height=15, background="black",
highlightbackground="white", highlightthickness="1")
#Boxception
self.collapseButton.create_line(5,5,12,5,fill="white")
self.collapseButton.create_line(5,5,5,12,fill="white")
self.collapseButton.create_line(11,11,11,5,fill="white")
self.collapseButton.create_line(11,11,5,11,fill="white")

self.rightSpacerFrame = tk.Frame(width=5, height=5, background="black")
self.rightSpacerFrame.grid(row="0", column="100", rowspan="50")
self.rightSpacerFrame.grid_remove()

self.collapseButton.grid(row="5", column="17", sticky="n")
self.collapseButton.grid(row=row, column=column, sticky="n")
self.collapseButton.bind("<ButtonPress-1>", self.buttonDimGray)
self.collapseButton.bind("<ButtonRelease-1>", self.collapseEvent)
self.collapseButton.bind("<Enter>", self.buttonGray25)
Expand All @@ -251,14 +263,15 @@ def collapseEvent(self, event):
self.bottomLeftResizeFrame.grid()
self.bottomRightResizeFrame.grid()
self.makeDraggable(self.mainFrame)
self.makeDraggable(self.middleFrame)
self.makeDraggable(self.labelHandler)
self.makeAllChildrenDraggable(self.labelHandler)
self.makeDraggable(self.graphFrame.canvas.get_tk_widget())
self.mainMenu.grid()
self.characterMenu.grid()
self.quitButton.grid()
self.labelHandler.grid(row="6", column="1", columnspan="19", sticky="ew")
self.collapseButton.grid(row="5", column="17", sticky="n")
self.collapseButton.destroy()
self.addCollapseButton(self, row="5", column="17")
self.collapsed = False
else:
self.wm_attributes("-alpha", self.settings.getCompactTransparency()/100)
Expand All @@ -272,14 +285,15 @@ def collapseEvent(self, event):
self.bottomRightResizeFrame.grid_remove()
self.rightSpacerFrame.grid()
self.unmakeDraggable(self.mainFrame)
self.unmakeDraggable(self.middleFrame)
self.unmakeDraggable(self.labelHandler)
self.unmakeAllChildrenDraggable(self.labelHandler)
self.unmakeDraggable(self.graphFrame.canvas.get_tk_widget())
self.mainMenu.grid_remove()
self.characterMenu.grid_remove()
self.quitButton.grid_remove()
self.labelHandler.grid(row="6", column="1", columnspan="18", sticky="ew")
self.collapseButton.grid(row="6", column="19", sticky="ne")
self.collapseButton.destroy()
self.addCollapseButton(self.middleFrame, row="0", column="1")
self.collapsed = True

def getGraph(self):
Expand Down
19 changes: 17 additions & 2 deletions PyEveLiveDPS/settings/generalSettingsFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@ def __init__(self, parent, mainWindow, **kwargs):
tk.Frame(self, height="0", width="1").grid(row="0", column="4")
self.counter = 0

checkboxValue = tk.BooleanVar()
checkboxValue.set(self.mainWindow.settings.getGraphDisabled())
self.graphDisabled = tk.Checkbutton(self, text="Disable graph entirely", variable=checkboxValue)
self.graphDisabled.var = checkboxValue
self.graphDisabled.grid(row=self.counter, column="1", columnspan="2")
descriptor = tk.Label(self, text="Labels will still be shown")
font = tkFont.Font(font=descriptor['font'])
font.config(slant='italic')
descriptor['font'] = font
descriptor.grid(row=self.counter+1, column="1", columnspan="2")
tk.Frame(self, height="20", width="10").grid(row=self.counter+2, column="1", columnspan="5")
self.counter += 3

self.secondsVar = tk.StringVar()
self.secondsVar.set(self.mainWindow.settings.getSeconds())
self.addSetting(self.secondsVar, "Number of seconds to average values:",
"Recommended to set this value higher than your weapon cycle time")

self.intervalVar = tk.StringVar()
self.intervalVar.set(self.mainWindow.settings.getInterval())
self.addSetting(self.intervalVar, "How often to update the graph in milliseconds:",
self.addSetting(self.intervalVar, "How often to update graph/labels in milliseconds:",
"The lower you set this value, the higher your CPU usage will be")

self.transparencyVar = tk.StringVar()
self.transparencyVar.set(self.mainWindow.settings.getCompactTransparency())
self.addSetting(self.transparencyVar, "Window transparency percentage in compact mode:",
"100 is fully visible, 0 is invisible")


def addSetting(self, var, labelText, descriptorText):
centerFrame = tk.Frame(self)
centerFrame.grid(row=self.counter, column="1", columnspan="2")
Expand Down Expand Up @@ -89,4 +103,5 @@ def doSettings(self):
tk.messagebox.showerror("Error", "Please enter a value between 1-100 for compact transparency percentage")
return

return {"seconds": secondsSetting, "interval": intervalSetting, "compactTransparency": compactTransparencySetting}
return {"seconds": secondsSetting, "interval": intervalSetting,
"compactTransparency": compactTransparencySetting, "graphDisabled": self.graphDisabled.var.get()}
36 changes: 25 additions & 11 deletions PyEveLiveDPS/settings/lineSettingsFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,34 @@ def onLineFrameConfigure(self, event):
self.scrollableCanvas.configure(scrollregion=self.scrollableCanvas.bbox("all"))

def addLineSection(self, frame, text, settingsList):
frame.columnconfigure(0, weight=1)
#frame.columnconfigure(0, weight=1)
frame.columnconfigure(1, weight=1)
sectionLabel = tk.Label(frame, text=text + " tracking")
sectionLabel.grid(row="0", column="0", sticky="e")
font = tkFont.Font(font=sectionLabel['font'])
font.config(weight='bold')
sectionLabel['font'] = font
innerFrame = tk.Frame(frame, borderwidth=1, relief="sunken", padx="5")
innerFrame.columnconfigure(0, weight=1)
innerFrame.grid(row="1", column="0", columnspan="2", sticky="we")
lineCheckboxValue = tk.BooleanVar()
lineCheckbox = tk.Checkbutton(frame, variable=lineCheckboxValue, text="Only show label", state="disabled")
lineCheckbox.grid(row="0", column="1", sticky="e")
lineCheckbox.var = lineCheckboxValue
checkboxValue = tk.BooleanVar()
if len(settingsList) == 0:
checkboxValue.set(False)
else:
checkboxValue.set(True)
self.addLineCustomizationSection(innerFrame, text, checkboxValue, settingsList)
sectionCheckbox = tk.Checkbutton(frame, variable=checkboxValue,
command=lambda:self.addLineCustomizationSection(innerFrame, text, checkboxValue, settingsList))
sectionCheckbox.grid(row="0", column="1", sticky="w")
try:
lineCheckboxValue.set(settingsList[0]["labelOnly"])
except KeyError:
pass
self.addLineCustomizationSection(innerFrame, text, checkboxValue, lineCheckbox, settingsList)
sectionCheckbox = tk.Checkbutton(frame, variable=checkboxValue, text=text + " tracking",
command=lambda:self.addLineCustomizationSection(innerFrame, text, checkboxValue, lineCheckbox, settingsList))
font = tkFont.Font(font=sectionCheckbox['font'])
font.config(weight='bold')
sectionCheckbox['font'] = font
sectionCheckbox.grid(row="0", column="0")
tk.Frame(frame, height="20", width="10").grid(row="1000", column="1", columnspan="5")

def addLineCustomizationSection(self, frame, text, checkboxValue, settingsList):
def addLineCustomizationSection(self, frame, text, checkboxValue, lineCheckbox, settingsList):
if checkboxValue.get():
frame.grid()
innerLabel = tk.Label(frame, text="Color and threshold (when to change colors) for this line:")
Expand All @@ -125,11 +131,15 @@ def addLineCustomizationSection(self, frame, text, checkboxValue, settingsList):
innerFrame = tk.Frame(frame)
innerFrame.grid(row="1", column="0", columnspan="5")
self.expandCustomizationSettings(innerFrame, settingsList)
lineCheckbox.configure(state="normal")
settingsList[0].update({ "labelOnly": lineCheckbox.var })
else:
for child in frame.winfo_children():
child.destroy()
frame.grid_remove()
settingsList.clear()
lineCheckbox.var.set(0)
lineCheckbox.configure(state="disabled")

def expandCustomizationSettings(self, frame, settingsList):
index = 0
Expand Down Expand Up @@ -200,6 +210,10 @@ def doSettings(self):
"capDamageOut": copy.copy(self.capDamageOutSettings),
"capDamageIn": copy.copy(self.capDamageInSettings)}

for name, settings in self.settingsCopy.items():
if len(settings) > 0:
settings[0]["labelOnly"] = settings[0]["labelOnly"].get()

for name, settings in self.settingsCopy.items():
for setting in settings:
try:
Expand Down
Loading

0 comments on commit 6e5f6e6

Please sign in to comment.