Commit 12c36577 authored by Kieran Hymas's avatar Kieran Hymas

Some work on brush tool

parent 1db599a5
......@@ -3,6 +3,7 @@ from videostream import *
import tkinter as tk
from tkinter import *
from tkinter import filedialog
from tkinter.colorchooser import *
from PIL import Image, ImageTk
import numpy as np
import cv2
......@@ -33,12 +34,16 @@ class Application:
'BlurKernelw' : IntVar(), \
'BlurDeviationX' : IntVar(), \
'BlurDeviationY' : IntVar(), \
'Skew' : False \
'Skew' : False, \
'BrushSize' : DoubleVar(), \
'Brush1Red' : 0, \
'Brush1Blue' : 0, \
'Brush1Green' : 0 \
}
#Toolbar options
self.toolbarExists = False
self.icons = [tk.PhotoImage(file="./assets/icons/snapshot.png"), \
self.toolbaricons = [tk.PhotoImage(file="./assets/icons/snapshot.png"), \
tk.PhotoImage(file="./assets/icons/record.png"), \
tk.PhotoImage(file="./assets/icons/rotate.png"), \
tk.PhotoImage(file="./assets/icons/skew.png"), \
......@@ -56,6 +61,10 @@ class Application:
#Colour options
self.colourOptionsExists = False
#Paintbrush options
self.paintbrushOptionsExists = False
self.paintarray = []
#INIT
self.initApp()
self.window.mainloop()
......@@ -107,39 +116,39 @@ class Application:
#load icons
pair1 = Frame(toolbar)
snapshotButton = Button(pair1, relief=FLAT, image=self.icons[0], command=self.onSnapshot)
snapshotButton = Button(pair1, relief=FLAT, image=self.toolbaricons[0], command=self.onSnapshot)
snapshotButton.pack(side=LEFT, padx=1, pady=1)
snapshotButton.image = self.icons[0]
recordButton = Button(pair1, relief=FLAT, image=self.icons[1], command=self.onRecord)
snapshotButton.image = self.toolbaricons[0]
recordButton = Button(pair1, relief=FLAT, image=self.toolbaricons[1], command=self.onRecord)
recordButton.pack(side=LEFT, padx=1, pady=1)
recordButton.image = self.icons[1]
recordButton.image = self.toolbaricons[1]
pair1.pack(side=TOP)
pair2 = Frame(toolbar)
rotateButton = Button(pair2, relief=FLAT, image=self.icons[2], command=self.onRotate)
rotateButton = Button(pair2, relief=FLAT, image=self.toolbaricons[2], command=self.onRotate)
rotateButton.pack(side=LEFT, padx=1, pady=1)
skewButton = Button(pair2, relief=FLAT, image=self.icons[3], command=self.onSkew)
skewButton = Button(pair2, relief=FLAT, image=self.toolbaricons[3], command=self.onSkew)
skewButton.pack(side=LEFT, padx=1, pady=1)
pair2.pack(side=TOP)
pair3 = Frame(toolbar)
vmirrorButton = Button(pair3, relief=FLAT, image=self.icons[4], command=self.onvMirror)
vmirrorButton = Button(pair3, relief=FLAT, image=self.toolbaricons[4], command=self.onvMirror)
vmirrorButton.pack(side=LEFT, padx=1, pady=1)
hmirrorButton = Button(pair3, relief=FLAT, image=self.icons[5], command=self.onhMirror)
hmirrorButton = Button(pair3, relief=FLAT, image=self.toolbaricons[5], command=self.onhMirror)
hmirrorButton.pack(side=LEFT, padx=1, pady=1)
pair3.pack(side=TOP)
pair4 = Frame(toolbar)
blurButton = Button(pair4, relief=FLAT, image=self.icons[6], command=self.onBlur)
blurButton = Button(pair4, relief=FLAT, image=self.toolbaricons[6], command=self.onBlur)
blurButton.pack(side=LEFT, padx=1, pady=1)
colourButton = Button(pair4, relief=FLAT, image=self.icons[7], command=self.onColour)
colourButton = Button(pair4, relief=FLAT, image=self.toolbaricons[7], command=self.onColour)
colourButton.pack(side=LEFT, padx=1, pady=1)
pair4.pack(side=TOP)
pair5 = Frame(toolbar)
brushButton = Button(pair5, relief=FLAT, image=self.icons[8])
brushButton = Button(pair5, relief=FLAT, image=self.toolbaricons[8], command=self.onBrush)
brushButton.pack(side=LEFT, padx=1, pady=1)
edgeButton = Button(pair5, relief=FLAT, image=self.icons[9])
edgeButton = Button(pair5, relief=FLAT, image=self.toolbaricons[9])
edgeButton.pack(side=LEFT, padx=1, pady=1)
pair5.pack(side=TOP)
......@@ -179,6 +188,7 @@ class Application:
self.blurOptionsExists = False
widget.destroy()
#Colour options functions
def initColourOptionsWindow(self):
if self.colourOptionsExists:
return
......@@ -206,6 +216,47 @@ class Application:
self.colourOptionsExists = False
widget.destroy()
#Paintbrush options functions
def initPaintbrushOptionsWindow(self):
if self.paintbrushOptionsExists:
return
self.paintbrushOptionsExists = True
paintbrushOptions = Toplevel(self.window, bd=1)
paintbrushOptions.title("Pycroscope: paintbrush options")
paintbrushToolsWidget = Frame(paintbrushOptions)
brushButton = Button(paintbrushToolsWidget, relief=SUNKEN).grid(row=0, column=0)
EraserButton = Button(paintbrushToolsWidget, relief=RAISED).grid(row=0, column=1)
UndoButton = Button(paintbrushToolsWidget, relief=RAISED).grid(row=0, column=2)
paintbrushToolsWidget.pack(side=TOP)
paintbrushSeparator = Frame(height=2, bd=1, relief=SUNKEN)
paintbrushSeparator.pack(padx=5, pady=5, side=TOP)
paintbrushOptionsWidget = Frame(paintbrushOptions)
sizelabel = Label(paintbrushOptionsWidget, text="Paintbrush size").grid(row=0)
colourlabel = Label(paintbrushOptionsWidget, text="Brush colour").grid(row=1)
sizescale = Scale(paintbrushOptionsWidget, from_=1, to=50, orient=HORIZONTAL, variable=self.options['BrushSize']).grid(row=0, column=1)
colourButton = Button(paintbrushOptionsWidget, text="Choose colour", command=self.setBrush1Colour).grid(row=1, column=1)
paintbrushOptionsWidget.pack(side=TOP)
paintbrushOptions.protocol("WM_DELETE_WINDOW", lambda arg=paintbrushOptions : self.onClosingPaintbrushOptions(arg))
def setBrush1Colour(self):
colour = askcolor(title='Pycroscope: brush colour', initialcolor=(self.options['Brush1Red'], self.options['Brush1Blue'], self.options['Brush1Green']))
if colour[0] == None:
return
self.options['Brush1Red'] = int(colour[0][0])
self.options['Brush1Blue'] = int(colour[0][1])
self.options['Brush1Green'] = int(colour[0][2])
def onClosingPaintbrushOptions(self, widget):
self.paintbrushOptionsExists = False
widget.destroy()
#Menubar options
#File
def onExit(self):
......@@ -264,7 +315,7 @@ class Application:
self.initColourOptionsWindow()
def onBrush(self):
print("Brush")
self.initPaintbrushOptionsWindow()
def onEdge(self):
print("Edge")
......@@ -305,6 +356,10 @@ class Application:
def updateVideo(self):
if self.videostreamplaying:
if self.vid.vidcap.isOpened():
if self.paintbrushOptionsExists:
self.canvas.config(cursor="cross black black")
else:
self.canvas.config(cursor="arrow")
ret, frame = self.vid.get_frame(self.options)
if ret:
self.photo = ImageTk.PhotoImage(image=Image.fromarray(frame))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment