Skip to content

Commit

Permalink
Merge dev's tabs into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrnt committed Nov 12, 2013
2 parents 9f8dfb1 + 23614f9 commit 3444c8e
Show file tree
Hide file tree
Showing 6 changed files with 415 additions and 55 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
NoteVelocity
===================
A speedy note-taking program
A speedy note-taking and revision program
---------------------

This is an EPQ (Extended Project Qualification) project for designing and making a note-taking program for university and A-level students. The main goals will be speed of operation and effectiveness of using NoteVelocity for revision.
This is an EPQ (Extended Project Qualification) project for designing and making a note-taking program for A-level students to easily revise from. The main goals will be speed of operation and effectiveness of using NoteVelocity for revision.
Made using *Python* and *Tkinter*.

**Dependencies:**
* *Python* >= *3.3*, as of commit 47
* *Python* >= *3.3*
* *Tkinter*
* *Source Sans Pro*
23 changes: 20 additions & 3 deletions notevelocity/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,21 @@
rename = "<Control-r>"
openFile = "<Control-o>"

quit = "<Control-w>"
nextTab = "<Control-d>"
prevTab = "<Control-D>"
newTab = "<Control-n>"
newTabTwo = "<Control-t>"
closeTab = "<Control-w>"

quit = "<Control-W>"

decreaseIndent = "<Control-Shift-space>"
increaseIndent = "<Control-space>" # Or the tab key when at the start of a line

margins = 2
makeHeading = "<Control-h>"
makeSubheading = "<Control-H>"

# Main
# Binding (Do not edit)
def init(self, root):
print("bindings initialised")

Expand All @@ -40,5 +47,15 @@ def init(self, root):
# Opening
root.bind(openFile, lambda event: self.openFile())

# Tab control
root.bind(nextTab, lambda event: self.tabBar.switch(0, 1))
root.bind(prevTab, lambda event: self.tabBar.switch(0, -1))
root.bind(newTab, lambda event: self.tabBar.add(self, "New Note"))
root.bind(newTabTwo, lambda event: self.tabBar.add(self, "New Note"))
root.bind(closeTab, lambda event: self.tabBar.closeCurrent())

root.bind(makeHeading, lambda event: print("Making heading"))
root.bind(makeSubheading, lambda event: print("Making subheading"))

# Quit
root.bind(quit, lambda event: self.quit())
53 changes: 38 additions & 15 deletions notevelocity/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tkinter import *
from tkinter.ttk import *
import bindings
import styles

## Main
# Title bar
Expand All @@ -26,19 +27,19 @@ def __init__(self, master, root):

self.testMessage = "titleBar is initialised"

self.Frame = Frame()
self.Frame = Frame(style = "TB.TFrame")
self.Frame.pack(fill = X, side = TOP, expand = 0, ipadx = 2, ipady = 2)

self.icon = Frame(self.Frame)
self.icon.pack(expand = 0, side = LEFT)

self.buttonA = Button(self.Frame, text = "Save")
self.buttonA = Button(self.Frame, text = "Save", style = "TB.TButton")
self.buttonA.pack(expand = 0, side = LEFT)

self.buttonB = Button(self.Frame, text = "Open")
self.buttonB = Button(self.Frame, text = "Open", style = "TB.TButton")
self.buttonB.pack(expand = 0, side = LEFT)

self.title = Label(self.Frame, text = " New note", anchor = "w")
self.title = Label(self.Frame, text = " New note", anchor = "w", style = "T.TLabel")
self.title.pack(expand = 1, fill = BOTH, side = LEFT)

self.Bindings()
Expand Down Expand Up @@ -72,17 +73,28 @@ def __init__(self, master):

self.testMessage = "formatBar is initialised"

self.Frame = Frame()
self.Frame = Frame(style = "TB.TFrame")
self.Frame.pack(fill = Y, side = LEFT, expand = 0, ipadx = 2, ipady = 2)

self.bold = Button(self.Frame, text = "B")
self.bold.pack(expand = 0, side = TOP)
self.spacer1 = Frame(self.Frame, height = 2)
self.spacer1.pack(expand = 0, side = TOP)

self.title = Button(self.Frame, text = "T", style = "F.TButton")
self.title.pack(expand = 0, side = TOP)

self.subTitle = Button(self.Frame, text = "S", style = "F.TButton")
self.subTitle.pack(expand = 0, side = TOP)

self.italic = Button(self.Frame, text = "I")
self.italic.pack(expand = 0, side = TOP)
self.notes = Button(self.Frame, text = "N", style = "F.TButton")

self.settings = Button(self.Frame, text = "S")
self.settings.pack(expand = 0, side = BOTTOM)
self.spacer2 = Frame(self.Frame, height = 5)
self.spacer2.pack(expand = 0, side = TOP)

self.equation = Button(self.Frame, text = "E", style = "F.TButton")
self.equation.pack(expand = 0, side = TOP)

self.settings = Button(self.Frame, text = "Set", style = "F.TButton")
self.settings.pack(expand = 0, side = BOTTOM, padx = 2, pady = 4)

# Text Frame
class text(Frame):
Expand All @@ -93,15 +105,16 @@ def __init__(self, master, root):

self.testMessage = "textFrame is initialised"

self.Frame = Frame()
self.Frame.pack(fill = BOTH, expand = 1, side = LEFT)
self.Frame = Frame(style = "TB.TFrame")
self.Frame.pack(fill = BOTH, expand = 1, side = TOP)

self.scrollbar = Scrollbar(self.Frame)
self.scrollbar.pack(expand = 0, fill = Y, side = RIGHT)

self.textBox = Text(self.Frame)
self.textBox.pack(expand = 1, fill = BOTH, side = LEFT)
self.textBox.config(tabs = ("0.5c", "0.75c", "0.825c"))
self.textBox.config(tabs = ("0.5c", "0.75c", "0.825c"), borderwidth = 0)
self.textBox.config(bg = master.master.textBoxBackground, fg = master.master.textBoxTextColour)

# Link self.textBox and self.scrollbar
self.textBox.config(yscrollcommand = self.scrollbar.set)
Expand Down Expand Up @@ -237,4 +250,14 @@ def updateTags(self):
self.root.after(1000, self.updateTags)

else:
print("Tag updating disabled")
print("Tag updating disabled")

class arrangementFrame(Frame):
def __init__(self, master):
self.master = master

self.testMessage = "arrangementFrame is initialised"

self.Frame = Frame()
self.Frame.pack(side = LEFT)

102 changes: 68 additions & 34 deletions notevelocity/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
from tkinter import messagebox
from os import getcwd
from os import remove
import platform
import frames
import tabs
import bindings
import logging
import styles

## Main loop
class AppFrame(Frame):
Expand All @@ -28,6 +31,7 @@ def __init__(self, master):

self.log = logging.Log(self)

self.osStuff()
self.initVars()
self.initUI()

Expand All @@ -39,38 +43,60 @@ def initVars(self):
def initUI(self):
self.log.write("Initialising UI")

styles.init(self)

## Top level frames
try:
self.titleBar = frames.titleBar(self, root)
self.log.write(self.titleBar.testMessage)
except:
except Exception as ex:
print("titleBar was not initialised properly")
self.log.writeError("titleBar was not initialised properly")
self.log.writeError("titleBar was not initialised properly. Error:\n" + str(ex))
self.quit()

try:
self.formatBar = frames.formatBar(self)
self.log.write(self.formatBar.testMessage)
except:
except Exception as ex:
print("formatBar was not initialised properly")
self.log.writeError("formatBar was not initialised properly")
self.log.writeError("formatBar was not initialised properly. Error:\n" + str(ex))
self.quit()

try:
self.textFrame = frames.text(self, root)
self.arrangementFrame = frames.arrangementFrame(self)
self.log.write(self.arrangementFrame.testMessage)
except Exception as ex:
print("arrangementFrame was not initialised properly")
self.log.writeError("arrangementFrame was not initialised properly. Error:\n" + str(ex))
self.quit()

try:
self.textFrame = frames.text(self.arrangementFrame, root)
self.log.write(self.textFrame.testMessage)
except:
except Exception as ex:
print("textFrame was not initialised properly")
self.log.writeError("textFrame was not initialised properly")
self.log.writeError("textFrame was not initialised properly. Error:\n" + str(ex))
self.quit()

"""try:
self.tabBar = tabs.tabBar(self.arrangementFrame)
self.log.write(self.tabBar.testMessage)
except Exception as ex:
print("tabBar was not initialised properly")
self.log.writeError("tabBar was not initialsed properly. Error:\n" + str(ex))
self.quit()"""

self.tabBar = tabs.tabBar(self.arrangementFrame)

try:
bindings.init(self, root)
except:
except Exception as ex:
print("bindings were not initialised properly")
self.log.writeError("bindings were not initialised properly")
self.log.writeError("bindings were not initialised properly. Error:\n" + str(ex))
self.quit()

self.textFrame.textBox.focus_set()

self.log.write("All initialised\n")

def saveFile(self, mode):
Expand All @@ -96,13 +122,15 @@ def saveFile(self, mode):
fileToSave.close()

self.textFrame.changed = False
self.tabBar.resetChanged()

elif mode == 2:
# Save file as
fileContents = self.textFrame.textBox.get("1.0", "end")

saveLocation = filedialog.asksaveasfilename(initialdir = self.notesDir, title = "Save note as", filetypes = [("Note files", "*.note")])
self.textFrame.fileName = saveLocation
self.tabBar.updateFilename()

if saveLocation is None or saveLocation is False or saveLocation is "" or saveLocation is "\n" or saveLocation == ():
print("No save location selected. Cancelling")
Expand All @@ -118,11 +146,14 @@ def saveFile(self, mode):
self.log.write("Saved file at " + saveLocation)

self.textFrame.fileName = saveLocation
self.titleBar.title.config(text = " " + saveLocation.split("/")[-1].split(".")[-2])
shortName = saveLocation.split(self.slashChar)[-1].split(".")[-2]
self.titleBar.title.config(text = " " + shortName)
self.tabBar.renameCurrent(shortName)

fileToSave.close()

self.textFrame.changed = False
self.tabBar.resetChanged()

elif mode == 3:
# Rename
Expand All @@ -141,39 +172,37 @@ def saveFile(self, mode):
print("Renamed file to " + saveLocation)
self.log.write("Renamed file to " + saveLocation)

remove(self.textFrame.fileName)
print(self.textFrame.fileName)
if self.textFrame.fileName != "":
remove(self.textFrame.fileName)

self.textFrame.fileName = saveLocation
print(self.textFrame.fileName)
self.titleBar.title.config(text = " " + saveLocation.split("/")[-1].split(".")[-2])
shortName = saveLocation.split(self.slashChar)[-1].split(".")[-2]
self.titleBar.title.config(text = " " + shortName)
self.tabBar.renameCurrent(shortName)

fileToSave.close()

self.textFrame.changed = False
self.tabBar.resetChanged()

else:
print("saveFile index out of range")
self.log.write("saveFile index out of range")

def openFile(self):
# Check whether textbox contents have changed. If yes, ask to save.
if self.textFrame.changed == True:
yesno = messagebox.askyesno("Save current file?", "The currently open file has not been saved. Save it?")

if yesno:
self.saveFile(1)
else:
self.textFrame.changed = False

openLocation = filedialog.askopenfilename(initialdir = self.notesDir, title = "Select note to open", filetypes = [("Note files", "*.note")])

if openLocation is None or openLocation is "" or openLocation is "\n" or openLocation is False or openLocation == ():
print("No open location selected")
self.log.write("No open location selected")
elif self.textFrame.changed == False:
else:
openFile = open(openLocation, "r")

self.textFrame.fileName = openLocation
shortName = self.textFrame.fileName.split(self.slashChar)[-1].split(".")[-2]
self.tabBar.add(self.tabBar, shortName)
self.titleBar.title.config(text = " " + shortName)

self.textFrame.textBox.delete("1.0", "end")

lineNum = 1
Expand All @@ -184,16 +213,10 @@ def openFile(self):

lineNum += 1

self.textFrame.fileName = openLocation
self.titleBar.title.config(text = " " + self.textFrame.fileName.split("/")[-1].split(".")[-2])

print("Opening file from " + openLocation)
self.log.write("Opening file from " + openLocation)
print("Opened file from " + openLocation)
self.log.write("Opened file from " + openLocation)

self.textFrame.changed = False
else:
print("Error opening file. The \'changed\' variable may not have been correctly set.")
self.log.writeError("Error opening file. The \'changed\' variable may not have been correctly set.")

def max(self):
pass
Expand All @@ -216,8 +239,19 @@ def log(self, mode):
elif mode == 1:
pass

def initStyles(self):
s = Style()
def osStuff(self):
self.os = platform.system()

if self.os == "Windows":
self.slashChar = "\\"
elif self.os == "Linux":
self.slashChar = "/"
elif self.os == "Darwin":
self.slashChar = "/"
else:
self.log.wrteError("System not detected as Windows, Mac or Linux. Some features may not work.")
print("System not detected as Windows, Mac or Linux. Some features may not work.")
self.slashChar = "/"

# Set root window properties
root = Tk()
Expand Down
Loading

0 comments on commit 3444c8e

Please sign in to comment.