summaryrefslogtreecommitdiff
path: root/OSCAD/subcktEditor/template.py
diff options
context:
space:
mode:
authorJayaram Pai2014-05-19 11:02:57 +0530
committerJayaram Pai2014-05-19 11:02:57 +0530
commit8377256e7d90aa7ba1cb51f6164e99f81e2eb53c (patch)
tree5afcc8e82d7f7d4f6fbff900520bd8f05eb343ca /OSCAD/subcktEditor/template.py
downloadFreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.tar.gz
FreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.tar.bz2
FreeEDA-8377256e7d90aa7ba1cb51f6164e99f81e2eb53c.zip
initial commit
Diffstat (limited to 'OSCAD/subcktEditor/template.py')
-rw-r--r--OSCAD/subcktEditor/template.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/OSCAD/subcktEditor/template.py b/OSCAD/subcktEditor/template.py
new file mode 100644
index 0000000..3353328
--- /dev/null
+++ b/OSCAD/subcktEditor/template.py
@@ -0,0 +1,110 @@
+#!/usr/bin/python
+from Tkinter import *
+import os
+
+class MyTemplate(Toplevel):
+ """Template to construct new window"""
+# Define constructor
+ def __init__(self, parent, title=None):
+ # Set new window properties same as parent
+ Toplevel.__init__(self, parent)
+ # Create a new window on top of the parent such that don't appear in taskbar
+ self.transient(parent)
+
+ # Set the title
+ if title:
+ self.title(title)
+ # Set Parent of active window
+ self.parent =parent
+
+ # Create a new frame
+ body =Frame (self)
+ # Call body method
+ self.initial_focus = self.body(body)
+ # Display body
+ body.pack(padx=5, pady=5)
+ # Create buttons
+ self.buttonbox()
+ # Create status bar
+ self.statusBar()
+ # Take control of all the events
+ self.grab_set()
+
+ # Take control of all the keyboard events
+ if not self.initial_focus:
+ self.initial_focus=self
+
+ # Protocol when window is deleted.
+ self.protocol("WM_DELETE_WINDOW",self.cancel)
+
+ # Position the geometry respect to main window
+ self.geometry("+%d+%d" % (parent.winfo_rootx()+50,parent.winfo_rooty()+50))
+ self.initial_focus.focus_set()
+
+ # Wait for widget to be destroyed
+ self.wait_window(self)
+
+# Construction of body of the window
+ def body(self, master):
+ # Create dialog body. This method should be overridden
+ pass
+
+# Add standard button box (OK, Cancel). Override if you don't want the standard buttons
+ def buttonbox(self):
+ # Construct a new frame
+ box = Frame(self)
+ # Create buttons
+ w = Button(box, text="OK", width=10, command=self.ok, default=ACTIVE)
+ w.pack(side=LEFT, padx=5, pady=5)
+ w = Button(box, text="Cancel", width=10, command=self.cancel)
+ w.pack(side=LEFT, padx=5, pady=5)
+
+ # Bind Return and escape keys
+ self.bind("<Return>", self.ok)
+ self.bind("<Escape>", self.cancel)
+ # Create the frame "box"
+ box.pack()
+
+# Add standard status bar. Override if you don't want the status bar
+ def statusBar(self):
+ self.statusbar = Label(self, text="", bd=1, relief=SUNKEN, anchor=W)
+ self.statusbar.pack(side=BOTTOM, fill=X)
+
+# Template for action taken when OK is pressed
+ def ok(self, event=None):
+ # If data is not valid then put the focus back
+ if not self.validate():
+ self.initial_focus.focus_set()
+ return
+ # Remove the window from the screen (without destroying it)
+ self.withdraw()
+ # Call all pending idle tasks, without processing any other events.
+ self.update_idletasks()
+ # Perform required task (collection of result, inputs etc.)
+ self.apply()
+ # Take action when all task has finished
+ self.cancel(status=1)
+
+# Template for action taken when cancel pressed
+ def cancel(self, event=None, status=0):
+ # Catch the status
+ self.status=status
+ # Put focus back to the parent window
+ self.parent.focus_set()
+ # Destroy child window
+ self.destroy()
+
+# Template for validation of data
+ def validate(self):
+ return 1
+
+# Template for required action (Saving Data, results)
+ def apply(self):
+ pass
+
+# Test case
+if __name__=='__main__':
+ root=Tk()
+ d =MyTemplate(root)
+ mainloop()
+