This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
From: wxpython-users@googlegroups.com [mailto:wxpython-
users@googlegroups.com] On Behalf Of C M
Sent: Thursday, October 21, 2010 8:35 PM
To: wxPython-users@googlegroups.com
Subject: [wxPython-users] custom rgb colors for wxfancytext?
This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
Thanks, but unfortunately, this doesn't work in wxFancyText. I wanted
to use FancyText instead of HTML window because it seemed that I
cannot draw a gradient background on an HTML window and have the text
show at the same time. If that's possible, maybe I can just use an
HTML window, but so far I haven't been able to get it to work.
Che
···
On Fri, Oct 22, 2010 at 2:14 AM, Al Mansur <almansur@rusnam.org> wrote:
Hi
-----Original Message-----
From: wxpython-users@googlegroups.com [mailto:wxpython-
users@googlegroups.com] On Behalf Of C M
Sent: Thursday, October 21, 2010 8:35 PM
To: wxPython-users@googlegroups.com
Subject: [wxPython-users] custom rgb colors for wxfancytext?
This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
The fancytext module dates waaaaayyyy back to the early days of wxPython, before some of the conveniences we currently have were available. Looking at the code I see this:
def getCurrentColor(self):
font = self.fonts[-1]
return wx.TheColourDatabase.FindColour(font.get("color", self.defaultColor))
So it is only going to look in the color name database (actually just a list of names/colors) and wont try converting from other string formats that wxPython supports today. You can try rewriting that method to use wx.NamedColour instead, and monkey-patch your new method into the class.
···
On 10/21/10 8:35 PM, C M wrote:
This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
Ah-ha. I see. Ok, then aside from monkey patching fancytext, what
might you in terms of currently available conveniences, for getting
this effect:
I'd like to make a pleasant welcome screen (that comes after a splash
screen, for first time users) that is a (probably) a dialog that
displays (custom) colored text over a gradient background, possibly
some images or widgets, too. Draw it all on directly with DC myself?
Or is there a more convenient way?
Thanks,
Che
···
On Fri, Oct 22, 2010 at 1:27 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/21/10 8:35 PM, C M wrote:
This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
The fancytext module dates waaaaayyyy back to the early days of wxPython,
before some of the conveniences we currently have were available.
(I should add that I went to FancyText and/or HTML Window because I
thought I might want the descriptive text to have formatting of
individual words, like italics or bold within a paragraph of text, and
it would be inconvenient and not-at-all easily maintainable to try to
line up the text sections individually using dc.DrawText() )
···
On Fri, Oct 22, 2010 at 1:40 PM, C M <cmpython@gmail.com> wrote:
On Fri, Oct 22, 2010 at 1:27 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/21/10 8:35 PM, C M wrote:
This is really simplistic, but how can one--if one can--use custom
colors with wxfancytext? For example, the demo has this line:
test_str2 = '<font family="swiss" color="dark green" size="40">big
green text</font>'
That is used to show big green text. But what if I wanted the color
to be equal to rgb(23,231,55)? I can't figure out how to write this.
I thought it should accept color=rgb(23,231,55) or at least a hex,
like color="##0000ff" (Note: all these values are just made up to
make the point). But when I try that, the text is just black
(default).
The fancytext module dates waaaaayyyy back to the early days of wxPython,
before some of the conveniences we currently have were available.
Ah-ha. I see. Ok, then aside from monkey patching fancytext, what
might you in terms of currently available conveniences, for getting
this effect:
I'd like to make a pleasant welcome screen (that comes after a splash
screen, for first time users) that is a (probably) a dialog that
displays (custom) colored text over a gradient background, possibly
some images or widgets, too. Draw it all on directly with DC myself?
Or is there a more convenient way?
I probably depends on the nature and complexity of what it is you want to show. If it's static then you could just create an image in a paint program that you then show like a splash screen or draw in the window's paint handler. Or perhaps a combination approach would work, create the background image with the static elements and then draw the image and text in the paint handler. Positioning live widgets over a drawn background is no big deal, although you'll probably want to use absolute positioning rather than sizers.
On the other hand, it's very easy to do stuff like this with wx.html.HtmlWindow instead. You can do the gradient background with an image file and the background attribute of the <body> tag, and widgets can be embedded using the <wxp> tag as shown in the demo.
···
On 10/22/10 10:40 AM, C M wrote:
On Fri, Oct 22, 2010 at 1:27 PM, Robin Dunn<robin@alldunn.com> wrote:
Ah-ha. I see. Ok, then aside from monkey patching fancytext, what
might you in terms of currently available conveniences, for getting
this effect:
I'd like to make a pleasant welcome screen (that comes after a splash
screen, for first time users) that is a (probably) a dialog that
displays (custom) colored text over a gradient background, possibly
some images or widgets, too. Draw it all on directly with DC myself?
Or is there a more convenient way?
Thanks, Robin. I have playing around with this for a few days and
find I like the second approach a lot. There's so much aesthetic good
that can come of this.
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
Thanks,
Che
···
On Fri, Oct 22, 2010 at 5:25 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/22/10 10:40 AM, C M wrote:
On Fri, Oct 22, 2010 at 1:27 PM, Robin Dunn<robin@alldunn.com> wrote:
Ah-ha. I see. Ok, then aside from monkey patching fancytext, what
might you in terms of currently available conveniences, for getting
this effect:
I'd like to make a pleasant welcome screen (that comes after a splash
screen, for first time users) that is a (probably) a dialog that
displays (custom) colored text over a gradient background, possibly
some images or widgets, too. Draw it all on directly with DC myself?
Or is there a more convenient way?
I probably depends on the nature and complexity of what it is you want to
show. If it's static then you could just create an image in a paint program
that you then show like a splash screen or draw in the window's paint
handler. Or perhaps a combination approach would work, create the
background image with the static elements and then draw the image and text
in the paint handler. Positioning live widgets over a drawn background is
no big deal, although you'll probably want to use absolute positioning
rather than sizers.
On the other hand, it's very easy to do stuff like this with
wx.html.HtmlWindow instead. You can do the gradient background with an
image file and the background attribute of the <body> tag, and widgets can
be embedded using the <wxp> tag as shown in the demo.
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to read items from various places (files, http or ftp URLs, etc.) with the same code. You can put the image data into a "file" in the "memory" file system and then just use "memory://" in your URLs and it will load the images from there. IIRC, adding the data for the virtual file is done something like this:
wx.FileSystem.AddHandler( wx.MemoryFSHandler() )
wx.MemoryFSHandler.AddFile("pathname1.png", rawData1)
wx.MemoryFSHandler.AddFile("pathname2.png", rawData2)
etc.
···
On 10/26/10 9:28 AM, C M wrote:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
PROBLEM: At this point I get a box that pops up with the words:
"Failed to store image 'background_image.gif' to memory VFS!" And
there is no background, despite the next step:
5) I use background="memory://background_image.gif" in the HTML of the
htmlWindow. But of course, nothing is shown, since it never got
stored in memory.
I can't figure out what I'm doing wrong.
Thanks,
Che
···
On Tue, Oct 26, 2010 at 3:29 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/26/10 9:28 AM, C M wrote:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to read
items from various places (files, http or ftp URLs, etc.) with the same
code. You can put the image data into a "file" in the "memory" file system
and then just use "memory://" in your URLs and it will load the images from
there. IIRC, adding the data for the virtual file is done something like
this:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to read
items from various places (files, http or ftp URLs, etc.) with the same
code. You can put the image data into a "file" in the "memory" file system
and then just use "memory://" in your URLs and it will load the images from
there. IIRC, adding the data for the virtual file is done something like
this:
wx.FileSystem.AddHandler( wx.MemoryFSHandler() )
wx.MemoryFSHandler.AddFile("pathname1.png", rawData1)
wx.MemoryFSHandler.AddFile("pathname2.png", rawData2)
etc.
So far I can't get that to work. This is what I am doing:
1) My background image, which was a .gif, is already made into a
string (called Background) by img2py.
On Tue, Oct 26, 2010 at 3:29 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 9:28 AM, C M wrote:
PROBLEM: At this point I get a box that pops up with the words:
"Failed to store image 'background_image.gif' to memory VFS!" And
there is no background, despite the next step:
5) I use background="memory://background_image.gif" in the HTML of the
htmlWindow. But of course, nothing is shown, since it never got
stored in memory.
Whoops, sorry, my mistake in typing this in for the email (yes, should
have copy/pasted it). I did use background_image originally. It
gives the same error.
···
On Tue, Oct 26, 2010 at 5:53 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/26/10 2:46 PM, C M wrote:
On Tue, Oct 26, 2010 at 3:29 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 9:28 AM, C M wrote:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to
read
items from various places (files, http or ftp URLs, etc.) with the same
code. You can put the image data into a "file" in the "memory" file
system
and then just use "memory://" in your URLs and it will load the images
from
there. IIRC, adding the data for the virtual file is done something like
this:
Hmmm... It should be working then, and it does here in a quickie test I did in PyCrust...
Ah, I know what is wrong. AddFile is going to convert the bitmap to an in-memory image file of the type you specified, but wx does not support writing GIF files, just reading them. The file format you use does not have to match what it was originally, because it is getting converted to PNG by the img2py tool anyway. Also, you can save a couple steps by not converting the data to a wx.Bitmap because AddFile is just going to convert it back to data anyhow. So try it like this:
You can verify what files are in the virtual filesystem like this:
fs = wx.FileSystem()
fs.ChangePathTo("memory:")
name = fs.FindFirst("*")
while name:
print name
name = fs.FindNext()
And it looks like the two slashes are not needed when accessing the root of the FS (unless you used slashes in the name of the file) so change your html to use "memory:bgimage.png".
···
On 10/26/10 3:39 PM, C M wrote:
On Tue, Oct 26, 2010 at 5:53 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 2:46 PM, C M wrote:
On Tue, Oct 26, 2010 at 3:29 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 9:28 AM, C M wrote:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to
read
items from various places (files, http or ftp URLs, etc.) with the same
code. You can put the image data into a "file" in the "memory" file
system
and then just use "memory://" in your URLs and it will load the images
from
there. IIRC, adding the data for the virtual file is done something like
this:
wx.FileSystem.AddHandler( wx.MemoryFSHandler() )
wx.MemoryFSHandler.AddFile("pathname1.png", rawData1)
wx.MemoryFSHandler.AddFile("pathname2.png", rawData2)
etc.
So far I can't get that to work. This is what I am doing:
1) My background image, which was a .gif, is already made into a
string (called Background) by img2py.
Whoops, sorry, my mistake in typing this in for the email (yes, should
have copy/pasted it). I did use background_image originally. It
gives the same error.
Works! That is excellent; thank you so much and for the explanation as well.
Che
···
On Tue, Oct 26, 2010 at 8:02 PM, Robin Dunn <robin@alldunn.com> wrote:
On 10/26/10 3:39 PM, C M wrote:
On Tue, Oct 26, 2010 at 5:53 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 2:46 PM, C M wrote:
On Tue, Oct 26, 2010 at 3:29 PM, Robin Dunn<robin@alldunn.com> wrote:
On 10/26/10 9:28 AM, C M wrote:
One question, though: I have a lot of images that go with an app and
I am using py2img to make them all into strings so that py2exe'ing it
up is easiest--so is it possible to use a py2img bitmap as the
background for the htmlWindow instead of loading the background image
from a file on the computer? If so, what is the syntax of doing that?
wx.html.HtmlWindow uses an abstraction of the files ystem to be able to
read
items from various places (files, http or ftp URLs, etc.) with the same
code. You can put the image data into a "file" in the "memory" file
system
and then just use "memory://" in your URLs and it will load the images
from
there. IIRC, adding the data for the virtual file is done something
like
this:
Whoops, sorry, my mistake in typing this in for the email (yes, should
have copy/pasted it). I did use background_image originally. It
gives the same error.
Hmmm... It should be working then, and it does here in a quickie test I did
in PyCrust...
Ah, I know what is wrong. AddFile is going to convert the bitmap to an
in-memory image file of the type you specified, but wx does not support
writing GIF files, just reading them. The file format you use does not have
to match what it was originally, because it is getting converted to PNG by
the img2py tool anyway. Also, you can save a couple steps by not converting
the data to a wx.Bitmap because AddFile is just going to convert it back to
data anyhow. So try it like this:
You can verify what files are in the virtual filesystem like this:
fs = wx\.FileSystem\(\)
fs\.ChangePathTo\("memory:"\)
name = fs\.FindFirst\("\*"\)
while name:
print name
name = fs\.FindNext\(\)
And it looks like the two slashes are not needed when accessing the root of
the FS (unless you used slashes in the name of the file) so change your html
to use "memory:bgimage.png".