Some advice needed on an Tkinter app that I try to write

S

Svenn Bjerkem

Hi,

Armed with Programming Python 3rd Edition and Learning Python 2nd
edition I try to write an application which I at first thought was
simple, at least until I was finished with the GUI and then wanted to
start putting some data into it.

As you will see, the program is not yet finished but I post what I have
so far.

It will read a spice file and extract the interfaces to the
subcircuits. The purpose of the program is to assign the interface pins
to sides of a rectangular box symbol which will represent the
subcircuit in a graphical design tool dedicated for electronics design
(Cadence to be precise) The output of the tool will be a lisp like text
format which can be read into that tool and there the actual generation
of the graphical symbol will take place.

The name of the subcircuits will be shown in the ScrolledList Widget.
When the user click on one of the entries of that widget, the pins of
the interface will be shown in the AssignList widget. (I have not
managed this, yet) If the user select any of the ScrolledList entries
(Single selection) the current setting is shown in the other widgets.
This implies that the user can move from one subcircuit to the next
before all pins have been placed. (I need some kind of an in-memory
database to take care of the data)

In the AssignList widget, either the user can select one or more
entries (extended selection) and press one of the four buttons
left,top,bottom,right and the pins will be moved to the respective
PinList widget. This process goes on until all the pins have been
assigned a side. When a pin is moved from the AssignList to one of the
PinList widgets, the pin is deleted from the AssignList.

If the user by accident move a pin to the wrong side, he can select the
wrongly placed pin and press the "Move here" button under the proper
PinList widget. Pins will always be placed at the bottom of a PinList.
This will make a rudimentary rearrange possible: If the Move Here
button of the same PinList widget is pressed, the selected pins
(extended selection) are moved to the bottom. (in an extended selection
the highest index will be moved first)

When I have come this far, I will add a menu line with options to save
the whole database to the text format which I can read into Cadence.

My biggest problem is probably that I have to implement a model view
controller but none of the books cover how to do this in Python. I have
tried to search on the web with google and find a lot of descriptions,
but so far nothing that make me more clever.

The problem which I have been chewing on the whole weekend is how to
tell the AssignList to load the pins belonging to the subcircuit
selected in ScrolledList.

Any ideas?
--
Svenn

#!/bin/env python

from Tkinter import *

class ScrolledList(Frame):
def __init__(self, data, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(data)

def handleList(self, event):
index = self.listbox.curselection()
label = self.listbox.get(index)
self.listbox.insert(END, label)
self.runCommand(label)

def makeWidgets(self, options):
sbar = Scrollbar(self)
list = Listbox(self, relief=SUNKEN)
sbar.config(command=list.yview)
list.config(yscrollcommand=sbar.set)
sbar.pack(side=RIGHT, fill=Y)
list.pack(side=LEFT, expand=YES, fill=BOTH)
pos=0
for label in options:
list.insert(pos,label)
pos += 1
list.bind('<<ListboxSelect>>', self.handleList)
list.bind('<Double-1>', self.handleList)
list.configure(selectmode=EXTENDED)
self.listbox = list

def runCommand(self, selection):
print 'You selected in: ', self
g_from=self

#----------------------------------------------------------
# A Widget to set some pins
#----------------------------------------------------------
class PinList(Frame):
def __init__(self, text="", parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets(text)
def makeWidgets(self, text):
frame = LabelFrame(self, text=text)
list = Listbox(frame, relief=SUNKEN)
sbar = Scrollbar(frame)
button = Button(frame, text='Move here',
command=self.handleList)
sbar.config(command=list.yview)
list.config(yscrollcommand=sbar.set)
frame.pack(side=LEFT, expand=YES, fill=BOTH)
button.grid(column=0, row=1, sticky=E+W)
list.grid(column=0, row=0, sticky=N+S+E+W)
sbar.grid(column=1, row=0, sticky=N+S)
frame.columnconfigure(0, weight=1)
frame.rowconfigure(0, weight=1)
list.bind('<<ListboxSelect>>', self.handleList)
self.listbox = list
def handleList(self, event):
index = self.listbox.curselection()
label = self.listbox.get(index)
def runCommand(self, selection):
print 'You selected: ', selection

class AssignList(Frame):
def __init__(self, data, parent=None):
Frame.__init__(self, parent)
self.pack(expand=YES, fill=BOTH)
self.makeWidgets()
def makeWidgets(self):
b1 = Button(self,
text="L\ne\nf\nt").grid(column=0, row=1, sticky=N+S)
b2 = Button(self,
text="Top").grid(column=1, row=0, sticky=E+W)
b3 = Button(self,
text="Bottom").grid(column=1, row=2, sticky=E+W)
b4 = Button(self,
text="R\ni\ng\nh\nt").grid(column=2, row=1, sticky=N+S)
l1 = Listbox(self).grid(column=1, row=1, sticky=N+S+E+W)
self.columnconfigure(1, weight=1)
self.rowconfigure(1, weight=1)
self.listbox = l1

# Test variables ------------------------------------------

data = {'buffer' : ['output', 'input', 'avdd', 'avss'],
'inverter': ['outputx', 'input', 'avdd', 'agnd'],
'adc' : ['d3', 'd2', 'd1', 'd0', 'anin', 'aref', 'clk']}

# ---------------------------------------------------------

#root = Tk()
class AppGui(Frame):
def __init__(self,parent=None):
Frame.__init__(self,parent=None)
self.pack(expand=YES, fill=BOTH)
self.make_widgets()
def make_widgets(self):
raw = LabelFrame(self, text="The Raw SUBCKT Data")
raw.pack(fill="both", expand="yes")

raw_pane = PanedWindow(raw)
raw_pane.pack(fill="both", expand="yes")

subckt_frame = LabelFrame(raw_pane, text="The SUBCKT Entities")
subckt_frame.pack(side="left", fill="both", expand="yes")
subckt_list = ScrolledList(data, subckt_frame)
subckt_list.pack(side="left", fill="both", expand="yes")

assign_frame = LabelFrame(raw_pane, text="Assign pins to sides")
assign_frame.pack(side="left", fill="both", expand="yes")
assign_list = AssignList(data, assign_frame)
assign_list.pack(side="left", fill="both", expand="yes")

raw_pane.add(subckt_frame)
raw_pane.add(assign_frame)

pins = LabelFrame(self, text="The assigned pins")
pins.pack(fill="both", expand="yes")
left_frame = PinList(parent=pins, text="Left side")
left_frame.pack(side="left", fill="both", expand="yes")
top_frame = PinList(parent=pins, text="Top side")
top_frame.pack(side="left", fill="both", expand="yes")
bottom_frame = PinList(parent=pins, text="Bottom side")
bottom_frame.pack(side="left", fill="both", expand="yes")
right_frame = PinList(parent=pins, text="Right side")
right_frame.pack(side="left", fill="both", expand="yes")

AppGui().mainloop()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top