Re: in place list modification necessary? What's a better idiom?
On Apr 6, 10:43 pm, Carl Banks pavlovevide...@gmail.com wrote: MooMaster wrote: So I'm reading in values from a file, and for each column I need to dynamically discover the range of possible values it can take and quantize if necessary. This is the solution I've come up with: code def createInitialCluster(fileName): #get the data from the file points = [] with open(fileName, 'r') as f: for line in f: points.append(line.rstrip('\n')) #clean up the data fixedPoints = [] for point in points: dimensions = [quantize(i, points, point.split(,).index(i)) for i in point.split(,)] print dimensions fixedPoints.append(Point(dimensions)) #return an initial cluster of all the points return Cluster(fixedPoints) def quantize(stringToQuantize, pointList, columnIndex): #if it's numeric, no need to quantize if(isNumeric(stringToQuantize)): return float(stringToQuantize) #first we need to discover all the possible values of this column domain = [] for point in pointList: domain.append(point.split(,)[columnIndex]) #make it a set to remove duplicates domain = list(Set(domain)) #use the index into the domain as the number representing this value return float(domain.index(stringToQuantize)) #harvested fromhttp://www.rosettacode.org/wiki/IsNumeric#Python def isNumeric(string): try: i = float(string) except ValueError: return False return True Big problem with this. I'm guessing you never ran it on a really big file yet. Your quantize function does a lot of unnecessary work: it rebuilds the list of indices for every single line, every single non- numeric entry, in fact. (Tech-speak: that is N^2 behavior in both the number of lines and number of non-numeric columns. Not good.) This will work ok for a small file, but will take forever on a large file (perhaps literally). So, forgetting about column indexing for a moment, we can improve this vastly simply by generating the list of indices once. Do that in a separete function, have it return the list, and then pass that list to the quantize function. So replace the midportion of your createInitialCluster function with something like this: for i in xrange(len(points[0])): # number of columns column_indices.append(quantize_column(points,i)) fixedPoints = [] for point in points: dimensions = [quantize(s, column_indices[i], point.split (,).index(i)) for (i,s) in enumerate(point.split(,))] # need index as well as entry here print dimensions fixedPoints.append(Point(dimensions)) And the two functions would be something like this: def quantize_columns(point_list,column_index): # this assumes if the first column is numeric the whole column would be if(isNumeric(point_list[0][column_index])): return None # don't quantize this column #first we need to discover all the possible values of this column domain = [] for point in point_list: domain.append(point.split(,)[column_index]) #make it a set to remove duplicates return list(set(domain)) def quantize(i,domain,s): if domain is None: return float(s) return float(domain.index(s)) This (once debugged :) will run much, much faster on a large dataset. Now back to your question. It works, but it feels a little ugly, and not exactly Pythonic. Using two lists I need the original point list to read in the data, then the dimensions one to hold the processed point, and a fixedPoint list to make objects out of the processed data. If my dataset is in the order of millions, this'll nuke the memory. I tried something like: for point in points: point = Point([quantize(i, points, point.split(,).index(i)) for i in point.split(,)]) but when I print out the points afterward, it doesn't keep the changes. It's because the order of items in a set is undefined. The order of the items in list(set([a,b,c,d])) might be very different from the order in list(set([a,b,c,d,e])). You were passing quantize incomplete an incomplete list of points, so as the points grew, the items in the set changed, and it messed up the order. In fact, you should never rely on the order being the same, even if you created the set with the very same arguments. What you are trying to do should be done with dictionaries: create a dict that maps a value to a number. Now, based on your quantize function, it would seem that the number associated with the value is arbitrary (doesn't matter what it is, as long as it's distinct), so it isn't necessary to read the whole csv file in before assigning numbers; just build the dict as you go. I suggest collections.defaultdict for this task. It's like a regular dict, but it creates a new
Re: in place list modification necessary? What's a better idiom?
On Apr 7, 12:40 am, Peter Otten __pete...@web.de wrote: Peter Otten wrote: MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a simple quantization scheme of enumerating the set of values within the column domain and replacing the strings with numbers (i.e. Iris-setosa = 1, iris-versicolor=2). I'd calculate the distance as def string_dist(x, y, weight=1): return weight * (x == y) oops, this must of course be (x != y). You don't get a high resolution in that dimension, but you don't introduce an element of randomness, either. Peter The randomness doesn't matter too much, all K-means cares about is a distance between two points in a coordinate space and as long as that space is invariant it doesn't matter too much (i.e. we don't want (1,1) becoming (3,1) on the next iteration, or the value for a quantized column changing). With that in mind, I was hoping to be lazy and just go with an enumeration approach... Nevertheless, it does introduce a subtle ordering for nominal data, as if Iris-Setosa =1, Iris-Versicolor=2, and Iris-Virginica=3 then on that scale Iris-Versicolor is intuitively closer to virginica than setosa is, when in fact such distances don't mean anything on a nominal scale. I hadn't thought about a function like that, but it makes a lot of sense. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
in place list modification necessary? What's a better idiom?
A similar discussion has already occurred, over 4 years ago: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b806ada0732643d/5dff55826a199928?lnk=gstq=list+in+place#5dff55826a199928 Nevertheless, I have a use-case where such a discussion comes up. For my data mining class I'm writing an implementation of the bisecting KMeans clustering algorithm (if you're not familiar with clustering and are interested, this gives a decent example based overview: http://rakaposhi.eas.asu.edu/cse494/notes/f02-clustering.ppt). Given a CSV dataset of n records, we are to cluster them accordingly. The dataset is generalizable enough to have any kind of data-type (strings, floats, booleans, etc) for each of the record's columnar values, for example here's a couple of records from the famous iris dataset: 5.1,3.5,1.4,0.2,Iris-setosa 6.4,3.2,4.5,1.5,Iris-versicolor Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a simple quantization scheme of enumerating the set of values within the column domain and replacing the strings with numbers (i.e. Iris-setosa = 1, iris-versicolor=2). So I'm reading in values from a file, and for each column I need to dynamically discover the range of possible values it can take and quantize if necessary. This is the solution I've come up with: code def createInitialCluster(fileName): #get the data from the file points = [] with open(fileName, 'r') as f: for line in f: points.append(line.rstrip('\n')) #clean up the data fixedPoints = [] for point in points: dimensions = [quantize(i, points, point.split(,).index(i)) for i in point.split(,)] print dimensions fixedPoints.append(Point(dimensions)) #return an initial cluster of all the points return Cluster(fixedPoints) def quantize(stringToQuantize, pointList, columnIndex): #if it's numeric, no need to quantize if(isNumeric(stringToQuantize)): return float(stringToQuantize) #first we need to discover all the possible values of this column domain = [] for point in pointList: domain.append(point.split(,)[columnIndex]) #make it a set to remove duplicates domain = list(Set(domain)) #use the index into the domain as the number representing this value return float(domain.index(stringToQuantize)) #harvested from http://www.rosettacode.org/wiki/IsNumeric#Python def isNumeric(string): try: i = float(string) except ValueError: return False return True /code It works, but it feels a little ugly, and not exactly Pythonic. Using two lists I need the original point list to read in the data, then the dimensions one to hold the processed point, and a fixedPoint list to make objects out of the processed data. If my dataset is in the order of millions, this'll nuke the memory. I tried something like: for point in points: point = Point([quantize(i, points, point.split(,).index(i)) for i in point.split(,)]) but when I print out the points afterward, it doesn't keep the changes. What's a more efficient way of doing this? -- http://mail.python.org/mailman/listinfo/python-list
We have string.isdigit(), why not string.isNumber()?
N00b question alert! I did a search for isdigit() in the group discussion, and it didn't look like the question had been asked in the first 2 pages, so sorry if it was... The manual documentation says: isdigit( ) Return true if all characters in the string are digits and there is at least one character, false otherwise. For 8-bit strings, this method is locale-dependent. So it makes sense that something like 5.6 would return false. But what if we want to make sure that our string is a valid number, ie decimals included? I know how to write a regexp or method or whatever to do this, my main question is *why* something like an isNumber() method is not baked into the class. Does such functionality exist somewhere else in the standard library that I'm just missing? -- http://mail.python.org/mailman/listinfo/python-list
Inheritance issue...
I'm trying to use inheritance to create a simple binary tree, but it's not going so well... here's what I pull from the documentation for super() super( type[, object-or-type]) Return the superclass of type. If the second argument is omitted the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true. super() only works for new-style classes. A typical use for calling a cooperative superclass method is: class C(B): def meth(self, arg): super(C, self).meth(arg) So here's what I do: class Node: def __init__(self, val=0, prnt = None): self.value = val self.parent = prnt class Tree(Node): def __init__(self, val=0): self.root = super(Tree, self).__init__(val) self.leftChild = None self.rightChild = None def addChild(self, value): if self.root == None: self.__init__(value) else: n = self.root while(n is not None): if(n.leftChild == None and n.rightChild == None): n.leftChild = Node(value, n) elif(n.rightChild == None): n.rightChild = Node(value, n) else: if(n.leftChild.leftChild is not None and n.leftChild.rightChild is not None): n = n.rightChild else: n = n.leftChild def printTree(self): if self.root == None: print None else: n = self.root print n.value while(n is not None): if(n.leftChild is None): print str(n.value) + 's left child is None elif(n.rightChild is None): print str(n.value) + 's right child is None else: if(n.leftChild.leftChild is not None and n.leftChild.rightChild is not None): n = n.rightChild else: n = n.leftChild def main(): play = Tree(1) play.addChild(2) play.addChild(3) play.addChild(4) play.addChild(5) play.printTree() if __name__ == __main__: main() ...and here's what I get: Traceback (most recent call last): File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 53, in module main() File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 45, in main play = Tree(1) File C:/Users/The_N_Channel/Desktop/funWithTrees.py, line 8, in __init__ self.root = super(Tree, self).__init__(val) TypeError: super() argument 1 must be type, not classobj Looks to me like the super(Tree, self)__init__(val) follows the example in the documentation, but I may be a witch. Anyone know why this doesn't work? -- http://mail.python.org/mailman/listinfo/python-list
Re: Inheritance issue...
On Mar 3, 11:49 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: MooMaster schrieb: I'm trying to use inheritance to create a simple binary tree, but it's not going so well... here's what I pull from the documentation for super() super( type[, object-or-type]) Return the superclass of type. If the second argument is omitted the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true. super() only works for new-style classes. The last sentence contains the important bit. You need to use new-style-classes, which means they have to have the ancestor object somewhere in their inheritance-graph. Like this: class Foo(object): pass Certainly one of the somewhat uglier corners of Python... Diez Thanks guys, I hadn't even heard of the distinction between old and new style classes...is this in the tutorial somewhere? I didn't see it in Classes... -- http://mail.python.org/mailman/listinfo/python-list
Color Segmentation w/ PIL?
I'm trying to write a Digital Image Processing program using the PIL library, and upon consultation of the Handbook I see that it seems to have built in functions to run Edge Detection (in the ImageFilter module), but I don't see anything about Segmentation. Are there any built-in tools to do this operation? Has anyone done this operation with PIL in the past that can lead me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
decimal and context objects!
Hey guys, I'm trying to do some black magic voodoo and it's a little late, so forgive me if this question seems obvious or has been asked before. I tried doing a search on context objects and didn't find anything that popped out, and I'm too tired to keep digging. I'm making a little program that is trying to do weird and sexy things by fully leveraging the power of all the built-in beauty of Python. I was trying to play around with the new features added into Python 2.5, and ran into an unexpected issue...check this out: moo = lambda x, y : decimal.Context(3).sqrt(decimal.Context(3).power(x,2) + decimal.Context(3).power(y,2)) moo function lambda at 0x02CD0EB0 row = [1,2,3,4,5] weight_vector = .00556 moo(sum(row), weight_vector) Traceback (most recent call last): File pyshell#5, line 1, in module moo(sum(row), weight_vector) File pyshell#1, line 1, in lambda moo = lambda x, y : decimal.Context(3).sqrt(decimal.Context(3).power(x,2) + decimal.Context(3).power(y,2)) File C:\Python25\lib\decimal.py, line 2662, in power return a.__pow__(b, modulo, context=self) TypeError: wrapper __pow__ doesn't take keyword arguments I have no idea what keyword argument is getting passed to __pow__, anyone know what's going on? This should compute sqrt(5^2 + 3^2) -- http://mail.python.org/mailman/listinfo/python-list
Re: decimal and context objects!
On Mar 2, 3:08 am, MooMaster [EMAIL PROTECTED] wrote: Hey guys, I'm trying to do some black magic voodoo and it's a little late, so forgive me if this question seems obvious or has been asked before. I tried doing a search on context objects and didn't find anything that popped out, and I'm too tired to keep digging. I'm making a little program that is trying to do weird and sexy things by fully leveraging the power of all the built-in beauty of Python. I was trying to play around with the new features added into Python 2.5, and ran into an unexpected issue...check this out: moo = lambda x, y : decimal.Context(3).sqrt(decimal.Context(3).power(x,2) + decimal.Context(3).power(y,2)) moo function lambda at 0x02CD0EB0 row = [1,2,3,4,5] weight_vector = .00556 moo(sum(row), weight_vector) Traceback (most recent call last): File pyshell#5, line 1, in module moo(sum(row), weight_vector) File pyshell#1, line 1, in lambda moo = lambda x, y : decimal.Context(3).sqrt(decimal.Context(3).power(x,2) + decimal.Context(3).power(y,2)) File C:\Python25\lib\decimal.py, line 2662, in power return a.__pow__(b, modulo, context=self) TypeError: wrapper __pow__ doesn't take keyword arguments I have no idea what keyword argument is getting passed to __pow__, anyone know what's going on? This should compute sqrt(5^2 + 3^2) Oh sorry, ignore that last line, that was a copy/paste from another example I forgot to remove...OBVIOUSLY it's going to compute something else, that's not what I'm asking about...stupid late night hacking! XD -- http://mail.python.org/mailman/listinfo/python-list
Regex help...pretty please?
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: cond(c,a,b) but it gets a little more complicated because the conds themselves may have conds within, like the following: cond(0,cond(c,cond(e,cond(g,h,(af)),(ad)),(ab)),(a1)) What I want to do in this case is move the last parameter to the front and then work backwards all the way out (if you're thinking recursion too, I'm vindicated) so that it ends up looking like this: cond((a1), 0, cond((ab),c,cond((ad), e, cond((af), g, h futhermore, the conds may be multiplied by an expression, such as the following: cond(-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a)) Here, all I want to do is switch the parameters of the conds without touching the expression, like so: cond(f,-1,1)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a)) So that's the gist of my problem statement. I immediately thought that regular expressions would provide an elegant solution. I would go through the string by conds, stripping them the () off, until I got to the lowest level, then move the parameters and work backwards. That thought process became this: -CODE import re def swap(left, middle, right): left = left.replace((, ) right = right.replace(), ) temp = left left = right right = temp temp = middle middle = right right = temp whole = 'cond(' + left + ',' + middle + ',' + right + ')' return whole def condReplacer(string): #regex = re.compile(r'cond\(.*,.*,.+\)') regex = re.compile(r'cond\(.*,.*,.+?\)') if not regex.search(string): print whole string is: + string [left, middle, right] = string.split(',') right = right.replace('\'', ' ') string = swap(left.strip(), middle.strip(), right.strip()) print the new string is: + string return string else: more_conds = regex.search(string) temp_string = more_conds.group() firstParen = temp_string.find('(') temp_string = temp_string[firstParen:] print there are more conditionals! + temp_string condReplacer(temp_string) def lineReader(file): for line in file: regex = r'cond\(.*,.*,.+\)?' if re.search(regex,line,re.DOTALL): condReplacer(line) if __name__ == __main__: input_file = open(only_conds2.txt, 'r') lineReader(input_file) -CODE I think my problem lies in my regular expression... If I use the one commented out I do a greedy search and in my test case where I have a conditional * an expression, I grab the expression too, like so: INPUT: cond(-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float(a)) OUTPUT: whole string is: (-1,1,f)*((float(e)*(2**4))+(float(d)*8)+(float(c)*4)+(float(b)*2)+float (a)) the new string is:cond(f*((float(e*(2**4+(float(d*8+(float(c*4+(float(b*2+float (a,-1,1) when all I really want to do is grab the part associated with the cond. But if I do a non-greedy search I avoid that problem but stop too early when I have an expression like this: INPUT: cond(a,b,(abs(c) = d)) OUTPUT: whole string is: (a,b,(abs(c) the new string is:cond((abs(c,a,b) Can anyone help me with the regular expression? Is this even the best approach to take? Anyone have any thoughts? Thanks for your time! -- http://mail.python.org/mailman/listinfo/python-list
Re: Having problems with reading file in Python CGI
I haven't tried to use the CGI class for any CGI scripting, so I'm no expert...but I am familiar with file objects. You want to return the next line in the file object? Your loop will run until it hits the EOF, at which point it'll break...once you hit that, there is *no* next line. But it looks to me like you're trying to return the contents of the file in a list...is that the part that's not working? If so, you might wanna try this: def filereader(a_file): contents = [] for line in a_file: contents.append(line.strip()) print line print contents now if you create a file like so: myfile = file(Moo.txt, r) filereader(myfile) You should see the contents of the file. So in your case, you should be able to change that horrible infinite while 1 loop with a break (which is straight from the python docs too... my programming languages teacher would have a fit!) into something like: for stuff in fileStream.file: Hope this helps! Kiana Toufighi wrote: Hi, I have a simple CGI program that allows that user to upload a file. However, since accessing the the value of the uploaded file using the value attribute or the getvalue() method reads the entire file in memory as a string which is not what I want I'm making use of the file module. The problem is that all the my checks including assert fileStream.file in not None return true however readline() does not return the next line of the fileStream.file object! What am I doing wrong? Here's my code: Here's my code: caller: dataFile = form['data_file'] fileproc = redrev.FileStreamProcessor() dataLines = fileproc.readStream(dataFile) callee: def readStream(self, fileStream): '''readStream: reads a stream of input returns a list of lines''' # list to hold data lines fileLines = [] # make sure that the stream has been provided try: assert fileStream.file is not None except Exception, e: No input to process # use filestream object to get uploaded file's lines one by one if fileStream.file: while 1: line = fileStream.file.readline() if not line: break # process and store the line line.strip() fileLines.append(line) return fileLines Thanks, Kiana -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle string problems...
Lol, that was a copy paste error into the post on my part...but the problem has been fixed. Turns out that there was a string.replace call somewhere else in the code that replaced all single quotes with empty strings, which thus caused the singe quotes to disappear! Whoops! Thanks for the look, though -- http://mail.python.org/mailman/listinfo/python-list
Re: parse data
If you know the indices of where the data should be in your string, you can use substrings... ie: stringy = Happy Happy Cow, 50, 1234 Your Mom's House AllTheTime,USA stringy[0:16] ' Happy Happy Cow' If the data isn't set all the time (for example, and address doesn't have a mandatory length), then you're probably stuck using the index function...unless you have everything separated by a delimiter, such as a ,...then this would work: listy = stringy.split(,) print listy [' Happy Happy Cow', ' 50', 1234 Your Mom's House AllTheTime, 'USA '] Hope this helps! -- http://mail.python.org/mailman/listinfo/python-list
Re: parse data
If you know the indices of where the data should be in your string, you can use substrings... ie: stringy = Happy Happy Cow, 50, 1234 Your Mom's House AllTheTime,USA stringy[0:16] ' Happy Happy Cow' If the data isn't set all the time (for example, and address doesn't have a mandatory length), then you're probably stuck using the index function...unless you have everything separated by a delimiter, such as a ,...then this would work: listy = stringy.split(,) print listy [' Happy Happy Cow', ' 50', 1234 Your Mom's House AllTheTime, 'USA '] Hope this helps! -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie - chapter 19 in How to think like a CS in python
Well, being a lowly CS student myself this sounded like fun, so I went ahead and took the challenge. The first thing you have to consider is how to add the new element to the list. Obviously you have to iterate through the list, find the first element that the new one is greater than, and insert this one before it while keeping the list structure intact. You must also remember to update the head if necessary, and add at the end if the element to be added is less than what is already in the list...So this is what I came up with: First of all, however, add this to your Improved Queue Class- def printQueue(self): if(self.isEmpty()): print Empty else: pointer = self.head while(pointer != None): print str(pointer.cargo) pointer = pointer.next Then-- class PriorityQueueList(ImprovedQueue): def __init__(self): ImprovedQueue.__init__(self) def insert(self, cargo): newNode = Node(cargo) if self.length == 0: self.head = self.last = newNode else: #iterate through the list, keeping a reference to a node and the node before it tracker = self.head while(tracker !=None): copy2 = tracker.prev if(newNode.cargo tracker.cargo): #add the new node by updating links, then update head while keeping list intact tracker.prev = newNode newNode.next = tracker self.head = newNode newNode.prev = copy2 if(copy2 !=None): copy2.next = newNode break else: tracker = tracker.next #if a repeat element is added #we want to add to end to preserve the queue structure, thus if the element hasn't #been added at this point it should be added at the end if(newNode.prev ==None and newNode.next ==None): last = self.last last.next = newNode self.last = newNode self.length = self.length + 1 This produces the following output- l = PriorityQueueList() l.insert(1) l.insert(2) l.insert(1) l.printQueue() 2 1 1 l.insert(10) l.printQueue() 10 2 1 1 Hope this helps! -- http://mail.python.org/mailman/listinfo/python-list
Re: Need to interrupt to check for mouse movement
Have you tried binding EVT_MOTION(func) to your window? -- http://mail.python.org/mailman/listinfo/python-list
linking GUI apps using different Toolkits...possible?
This is more of a wxPython centric question, but not seeing reference to this on the wx group I thought I'd try here since many here also use wxPython toolkit. I started learning GUI development with Tkinter, and developed a few screens as part of an application I'm building with it. I've recently been trying to learn wxPython because of it's additional widgets (the wxTreeCtrl and Drag and Drop features in particular), and I've developed an application where there is a splitter window with a tree on the left side. My goal is to have a user double click on an option and call up the appropiate display on the right side. I've already developed the appropriate screens in Tkinter, and I'd like to use those instead of having to re-write them in wx. I'd basically like to pack the screen into the rightmost pane, but I have not been able to find an effective means for doing so. What I have so far is this: --- class MyApp(wxApp): driver class, creates a frame to store everything, puts 2 splitter windows inside, the first holding the tree display def OnInit(self): #create the frame frame = MyFrame(NULL, -1, Display) frame.Show(true) self.SetTopWindow(frame) #create the splitter windows splitter = MySplitter(frame, -1) sty = wxBORDER_SUNKEN self.p1 = wxWindow(splitter, style=sty) self.p2 = wxWindow(splitter, style=sty) self.p2.SetBackgroundColour(sky blue) splitter.SetMinimumPaneSize(100) splitter.SplitVertically(self.p1, self.p2, 320) #Create the tree and add the outermost parents self.p1.myTree = MyTreeCtrl(self.p1, -1, wxDefaultPosition, (400,400), wxTR_HAS_BUTTONS) self.p1.root = self.p1.myTree.AddRoot(Subsystem) self.p1.myTree.SetPyData(self.p1.root, None) self.p1.child1 = self.p1.myTree.AppendItem(self.p1.root, 4 Corners) self.p1.child2 = self.p1.myTree.AppendItem(self.p1.root, East of River) #Bind Drag and Drop methods to the tree to support drag and drop self.p1.myTree.Bind(EVT_TREE_BEGIN_DRAG, self.OnBeginDrag) self.p1.myTree.Bind(EVT_TREE_END_DRAG, self.OnEndDrag) self.p1.myTree.Bind(EVT_LEFT_DCLICK, self.OnLeftDClick) #Fill with children headerLabels = [TC43G, Arming, Outage, Lines, Graphs] for label in headerLabels: grandchild = self.p1.myTree.AppendItem(self.p1.child1, label) self.p1.myTree.SetPyData(grandchild, None) grandchild = self.p1.myTree.AppendItem(self.p1.child2, label) self.p1.myTree.SetPyData(grandchild, None) #Expand base root to get to meat of data self.p1.myTree.Expand(self.p1.root) return true #When a node is double clicked, it should display the corresponding display on the right hand side #currently, display pops up in separate window... def OnLeftDClick(self, event): pt = event.GetPosition(); item, flags = self.p1.myTree.HitTest(pt) clicked = self.p1.myTree.GetItemText(item) if(clicked == Arming): self.p2 = ACDisplay() elif(clicked == Graphs): self.p2 = Display() elif(clicked == Lines): self.p2 = OutTable() elif(clicked == Outage): self.p2 = tablesum() --- Where ACDisplay, Display, OutTable, and tablesum are the classes I've written already. It runs without errors, but what currently happens is that the main window with the tree comes up, and when I double-click an option the screen appears in a separate window. Is there a way to pack it into the second pane (self.p2)? -- http://mail.python.org/mailman/listinfo/python-list
multiple checkboxes highlighted when one clicked = not good
I've been reading Deitel's Introducing Python, and Fredrik Lundh's Introduction to Tkinter, trying to familiarize myself with Python and GUI design in Tk, and I've run into a puzzling problem. I'm trying to draw a column of 10 checkboxes, each with a separate variables and commands. The easy way to do this is to hardcode it, but I was trying to do something a little more elegant: self.InUse =[BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar(), BooleanVar()] for i in range(1,11): for t in range(7): if(t==0): Checkbutton(self.frame2, variable = self.InUse[t]).grid(row= i, column = t) I figure since I create a separate variable for each checkbutton, the should be independent of one another. Unfortunately, they are not, and when I click on one, all become selected/deselected. What am I missing? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple checkboxes highlighted when one clicked = not good
right, I'm basically drawing a table with 3 columns, and I want checkboxes when we are at column 0. In columns 1-3 I will want Entries and Labels, but I always want checkboxes @ column 0. -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple checkboxes highlighted when one clicked = not good
UhmI'm a dunce. Thanks James! -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple checkboxes highlighted when one clicked = not good
UhmI'm a dunce. Obviously having it only use t[0] is going to make it cleverly look like I'm using different variables, when in fact I'm not. Thanks James! -- http://mail.python.org/mailman/listinfo/python-list
Lost in a sea of documentation...can you point me in the right direction?
I'm a complete beginner in Python, but I've been fooling around with Java for a couple years, so I have decent programming experience... Anyway, I was sitting around playing with Python, when I thought to myself: I know! I'd like to write a program that I can pass a path to (say: My Pictures) and at a timer interval will pick a picture from it and set my wallpaper to that So I started reading about os, threads, and the path for the special folders in the archives and in the Python docs and I'm kind of lost because there aren't many concrete examples in the documentation. Can anyone point me in the right direction as to where I might find info that can help me write this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list