I found that if we open a new document, the document may have not a filename, so self.filename is null. But we'd have show its name like 'untitled'. So I think there should be two title on an document, one is its real filename, if it doesn't have one, the filename should be null. The other is its displaying filename, which can be used in tabbed page title or windows menu, and drpython window title, etc.
So the displaying filename could be a function, which can be evaluated by real filename. If read filename is null, then the value should be 'Untitled'. Otherwise the value is the same as real filename.
And I advice these property and function had better to be put in txtDocument objects. I also want to add a new property 'id' in drText class . It can be used to create new document untitled name. When DrPython starts, its value is 1. So the first new document' displaying filename is "Untitled1". When open a new document, the displaying filename is "Untitled2", the rest may be deduced by analogySome ideas?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That sounds interesting. I don't see too much of a reason for adding another variable to keep track of the title.
However I like the untitled with a number idea.
How to do it?
Here are some possibilities:
Have the number simply be the current document position (hence with two documents opened, a new document would become "Untitled 3").
Have DrPython keep track of each new file
Hence the second new document would be "Untitled 2".
Have DrPython calculate how many utitled documents exist, and make the new document "Untitled " + str(untitled documents).
What thoughts?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If put the id in DrText class as a class property, when creating a new DrText instance, I can increase the id value in __init__ function. this way can be very easy. And if I want to get the displaying filename, I can invoke DrText's member function, getFileName(), which may return 'Untitled 2' as the document hasn't a real filename. If I want the real filename, I can use the member variable filename. When saving a file, I can use txtDocument.filename to judge whether we should popup an saving file dialog.
Of cause the filename can be saved in filenameArray, but I think saving in object might be better. It's just some advice. The both are ok.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Probably easiest to just display "Untitled" when the filename is blank, that's certainly how I'd do it, and I've seen it used frequently.
To get the next "Untitled" title (e.g. "Untitled 2") just check the tabs for documents with blank filenames and add 1 to the last number shown, or just set to 2 if there is only a single one labelled "Untitled".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The displaying filename can be a function, which do what you said "check to see if the filename is "", and if it is, display untitled". Only one reason that if the ID saved in DrText( I thought id should be a class veriable, not a object veriable, so each DrText object will use the same id. Other ideas?), the id may not be the correctly one. Say
Of cause we can use ID as object variable, but how to increase id may be not so easy and clearly.
Oh, I find out a good idea!
class DrText:
id = 0
def __init__(self):
self.id += 1
self.fileid = self.id #assignment an object vairable will solve the problem
def GetDisplayFilename(self):
if self.filename == '':
return 'Untitled '+str(self.fileid)
else:
return self.filename
a=DrText() #a.fileid =1
b=DrText() #a.fileid = 1 b.fileid=2
The above will run perfectly.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Where to save the "last number", in drText class or somewhere? And how to increase the id's value?
If saving in drText, the thing saving and increasing will be easy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The next untitled project number could be stored in the "not too far away now" project manager data area. That way, you'd have the state saved between sessions and the code would be nice and simple.
When a new document is added, the next number (which would also serve as an ID) should be stored in the Document object for use as required.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So I see several points here.
1. the wxPython ID number should be distinct for different wx.stc controls. Agreed. We can fix this for the next version.
before I continue, we need a better way of posting python code to forums. Perhaps using one character that does not appear in your code as whitespace:
if (condition):
$$$$do this
Something like that. Then a simple replace operation makes the code all nic and jolly.
Anyway...
2. A display filename function. Do we need this to be a function? I would rather not, unless this operation occurs in several places. Calling a function just makes code less efficient, especially with python, and the places where you monitor this are very performance sensistive. If it seems necessary, I will do it though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
These places may use display filename:
1. DrPython window title
if filename is null , we have to use 'Untitled' or ('Unititled'+str(ID)). Otherwise just using filename.
2. tabbed page title
We only use the basename of the filename. As same as above, if filename is null, we have to use 'Untitled' or ('Unititled'+str(ID)). Otherwise just using the basename of the filname.
3. windonw menu
just like the first.
Are there also some other places using the display filename?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The display filename routine could be implemented "in-line" for the tab page titles and all other references taken from the current tab page. That way the code is only in one place and another function call is avoided.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The filename is stored in the txtDocument (After I get 2.4.6 out the door, I am waiting on the resolution of two bugs first), however we do this inline, rather than with a function call.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found that if we open a new document, the document may have not a filename, so self.filename is null. But we'd have show its name like 'untitled'. So I think there should be two title on an document, one is its real filename, if it doesn't have one, the filename should be null. The other is its displaying filename, which can be used in tabbed page title or windows menu, and drpython window title, etc.
So the displaying filename could be a function, which can be evaluated by real filename. If read filename is null, then the value should be 'Untitled'. Otherwise the value is the same as real filename.
And I advice these property and function had better to be put in txtDocument objects. I also want to add a new property 'id' in drText class . It can be used to create new document untitled name. When DrPython starts, its value is 1. So the first new document' displaying filename is "Untitled1". When open a new document, the displaying filename is "Untitled2", the rest may be deduced by analogySome ideas?
That sounds interesting. I don't see too much of a reason for adding another variable to keep track of the title.
However I like the untitled with a number idea.
How to do it?
Here are some possibilities:
Have the number simply be the current document position (hence with two documents opened, a new document would become "Untitled 3").
Have DrPython keep track of each new file
Hence the second new document would be "Untitled 2".
Have DrPython calculate how many utitled documents exist, and make the new document "Untitled " + str(untitled documents).
What thoughts?
If put the id in DrText class as a class property, when creating a new DrText instance, I can increase the id value in __init__ function. this way can be very easy. And if I want to get the displaying filename, I can invoke DrText's member function, getFileName(), which may return 'Untitled 2' as the document hasn't a real filename. If I want the real filename, I can use the member variable filename. When saving a file, I can use txtDocument.filename to judge whether we should popup an saving file dialog.
Of cause the filename can be saved in filenameArray, but I think saving in object might be better. It's just some advice. The both are ok.
You are right, I cannot think of a good reason to save the filename in the Frame instead of the Document. Leftover from the SDI days, I suppose.
In terms of the displaying filename, why is there a need for this? Why not just check to see if the filename is "", and if it is, display untitled?
Probably easiest to just display "Untitled" when the filename is blank, that's certainly how I'd do it, and I've seen it used frequently.
To get the next "Untitled" title (e.g. "Untitled 2") just check the tabs for documents with blank filenames and add 1 to the last number shown, or just set to 2 if there is only a single one labelled "Untitled".
That seems reasonable.
I like it.
The displaying filename can be a function, which do what you said "check to see if the filename is "", and if it is, display untitled". Only one reason that if the ID saved in DrText( I thought id should be a class veriable, not a object veriable, so each DrText object will use the same id. Other ideas?), the id may not be the correctly one. Say
class DrText:
id = 0
def __init__(self):
self.id += 1
def GetDisplayFilename(self):
if self.filename == '':
return 'Untitled '+str(self.id)
else:
return self.filename
a=DrText() #a.id = 1
b=DrText() #a.id = 2(incorrect) b.id=2
Of cause we can use ID as object variable, but how to increase id may be not so easy and clearly.
Oh, I find out a good idea!
class DrText:
id = 0
def __init__(self):
self.id += 1
self.fileid = self.id #assignment an object vairable will solve the problem
def GetDisplayFilename(self):
if self.filename == '':
return 'Untitled '+str(self.fileid)
else:
return self.filename
a=DrText() #a.fileid =1
b=DrText() #a.fileid = 1 b.fileid=2
The above will run perfectly.
Where to save the "last number", in drText class or somewhere? And how to increase the id's value?
If saving in drText, the thing saving and increasing will be easy.
The next untitled project number could be stored in the "not too far away now" project manager data area. That way, you'd have the state saved between sessions and the code would be nice and simple.
When a new document is added, the next number (which would also serve as an ID) should be stored in the Document object for use as required.
So I see several points here.
1. the wxPython ID number should be distinct for different wx.stc controls. Agreed. We can fix this for the next version.
before I continue, we need a better way of posting python code to forums. Perhaps using one character that does not appear in your code as whitespace:
if (condition):
$$$$do this
Something like that. Then a simple replace operation makes the code all nic and jolly.
Anyway...
2. A display filename function. Do we need this to be a function? I would rather not, unless this operation occurs in several places. Calling a function just makes code less efficient, especially with python, and the places where you monitor this are very performance sensistive. If it seems necessary, I will do it though.
These places may use display filename:
1. DrPython window title
if filename is null , we have to use 'Untitled' or ('Unititled'+str(ID)). Otherwise just using filename.
2. tabbed page title
We only use the basename of the filename. As same as above, if filename is null, we have to use 'Untitled' or ('Unititled'+str(ID)). Otherwise just using the basename of the filname.
3. windonw menu
just like the first.
Are there also some other places using the display filename?
The display filename routine could be implemented "in-line" for the tab page titles and all other references taken from the current tab page. That way the code is only in one place and another function call is avoided.
Use what? Page title? It seems not so good. I'd like to get it from txtDocument object, this seems more like object-oriented.
Certainly. All I meant, was that it be calculated on a per document basis, and all other references taken from there.
So are we in aggreement?
The filename is stored in the txtDocument (After I get 2.4.6 out the door, I am waiting on the resolution of two bugs first), however we do this inline, rather than with a function call.
oh, good