Sending an event to another window

I want to create a custom combobox that is linked in a parent-child relationship to another combobox, such that when the first one changes, the options in the second one change. I have figured out (with great difficulty) how to generate a custom event with my combobox, but so far, I can only send it to the parent frame, not to another window on that frame.

From reading the help and examples, it sounds to me like what I want to do is not possible; but since it seems like a rather basic request, I'm hoping that I'm misunderstanding the limitations of events. In particular, it seems like I ought to be able to send the event to another window by passing its id to the event, like this:

         x = MyCustomEvent( self.childBox ),

where "self.childBox" is a property of the parent combobox that gets set at design-time. Then I would want to catch this event inside the custom class, like this:

         EVT_MYCUSTOMEVENT(self, self.updateList)

This works if I try to catch the event in the parent frame, but that defeats the purpose -- in that case, the combo boxes aren't really linked at all. And if I would have to do that, how could anyone ever create data-aware controls that link to a database recordset? They would always have to pass through the frame, so each frame would have to go to the trouble of registering all the events -- in which case the value of a special control would be largely defeated (so it seems to me).

(If this question makes it sound like I don't have a good grasp of custom event creation, there is a good reason for this.)

Hi all,

I have started looking into the question of printing from my accounting
application.

My first attempt uses the printing framework that is part of
wxWindows/wxPython, as this seems to be the generic wx approach. I am using
two printers for testing - an HP LaserJetIIIP using PCL5, and a C-Itoh
dot-matrix printer. This is my initial test, just to see what would happen.

    def OnPrintPage(self, page):
        dc = self.GetDC()
        dc.DrawText('This is line 1',100,100)
        dc.DrawText('This is line 2',200,200)
        return True

My first impressions are that printing under MSW works pretty well - there
some oddities with font sizes on the HP, but I imagine that I can find
solutions to this. However, printing under Linux (Redhat 9) does not work at
all. My guess is that this is because my printers are not equipped for
PostScript.

If I run the above program on the HP, I get two tiny dotted lines where the
text should be. If I run it on the dot-matrix, I get eight and a half pages
of text, which seems to be the PostScript output. If I print the sample
PrintFramework page from the demo using the HP, the images appear correctly,
but none of the text appears at all. I did not attempt this with the
dot-matrix.

Another problem with Linux is that the PrintDialog does not give the option
to select a printer.

I can foresee a long period of trial and error ahead, so I would appreciate
any advice that will point me in the right direction.

These are the printing capabilities that I think I will require. Please add
to the list if there are other things that I should be catering for.

- I must support a wide range of printers, including laser, inkjet,
dot-matrix, label printers, barcode printers, thermal slip printers, Windows
printers, etc.

- The most common requirement will be text-based columnar reports, which
could potentially run to 100's of pages. The ability to select certain
sections to print in bold, compressed, underlined, etc. would be nice.

- I need to print various forms - invoices, statements, remittance advices,
etc. These could be printed on pre-printed stationery, or the program must
draw the various horizontal and vertical lines, logos, images, etc, as
required.

- I will need to plot information, using bar charts, line graphs, pie
charts, etc.

- I will need to print images on text-based reports, such as pictures of
inventory items in a catalogue.

- Any report, once generated, must be able to be faxed, emailed, output as
HTML, copied to a spreadheet, etc, instead of being output to a printer.
This means that the generation of the report and the output of the report
must be split into separate functions in my application.

I am sure there are more, but this is enough for now.

I would prefer to standardise on one framework which will handle all these
requirements on both MSW and Linux. I quite like the wx printing framework,
so if it is possible to overcome my problems, I would be happy to stick with
it. Alternatively, I am aware of ReportLab and its pdf capability, but I
have not looked into it yet. I believe it has a fairly steep learning curve,
so I would appreciate some feedback before I venture down this path. Would
it be a viable solution?

Any comments or advice will be much appreciated.

Many thanks

Frank Millman

I have started looking into the question of printing from my accounting
application.

I strongly recommend you look into HTMLEasyPrinting. You just have to
generate HTML and it handles all the rest.

Alternatively there is a table printer (see More Windows/Controls -> TablePrint
in the demo).

it. Alternatively, I am aware of ReportLab and its pdf capability, but I

Instead of getting your app to generate PDF, you can punt to Ghostscript
which will do conversion for you. You could use wxPostScriptDC to generate
the postscript. Or you can tell the users to setup a PDF printer. For
example on Windows PDFCreator works well, and it works for any app as
it sets itself up as a printer http://sector7g.wurzel6.de/pdfcreator/index_en.htm
You can do something similar on Linux.

Roger

HI & thanks in advance
Could someone please tell me where on a window GetSize measures and what
units does it use. Also GetPosition.
Thanks again
Greg

Pixels.

···

-----Original Message-----
From: Greg Binns [mailto:gregbin@bigpond.net.au]
Sent: Monday, November 17, 2003 5:10 AM
To: wxPython-users@lists.wxwindows.org
Subject: [wxPython-users] Size & Position

HI & thanks in advance
Could someone please tell me where on a window GetSize measures and what
units does it use. Also GetPosition.
Thanks again
Greg

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Frank Millman wrote:

I have started looking into the question of printing from my accounting
application.

I havn't done much with printing, but I think I have some useful
comments:

printing under Linux (Redhat 9) does not work at
all. My guess is that this is because my printers are not equipped for
PostScript.

Do you have printing from other apps set up under Linux? For the most
part, the way printing is done on Linux is that the app produced
Postscript (nice and device independent), and the printing system uses
ghostscript to translate the postscript into whatever language the
printer requires. The printing system also can generally detect a bunch
of other file types and translate them appropriately: text, jpeg, etc.
If yo have printing set up properly on Redhat, you should be able to
send a postscript docuemnt to lpr and have it print correctly.

text should be. If I run it on the dot-matrix, I get eight and a half pages
of text, which seems to be the PostScript output. If I print the sample
PrintFramework page from the demo using the HP, the images appear correctly,
but none of the text appears at all. I did not attempt this with the
dot-matrix.

Another problem with Linux is that the PrintDialog does not give the option
to select a printer.

Doesn't it give the option of typing in a print command? If so, then the
user would either use the default (usually lpr, and easy) or something
like "lpr -PMyPrinter", which is not a big deal for a unix savy user,
but could be a problem. New KDE (and I assume GNOME) apps are smarter,
and will give you alist of CUPS set up printers to choose from. That's
kind of KDE (or GNOME) dependent, however, so it's harder for the
wxWindows printer dialog to do that.

- I must support a wide range of printers, including laser, inkjet,
dot-matrix, label printers, barcode printers, thermal slip printers, Windows
printers, etc.

Most of these shouild be supported by the LInux or Windows print
framework, though for dot-matrix, you probably want raw text, rather
than postscript.

- Any report, once generated, must be able to be faxed, emailed, output as
HTML, copied to a spreadheet, etc, instead of being output to a printer.
This means that the generation of the report and the output of the report
must be split into separate functions in my application.

I was going to say reportLab and PDF, but output to html is harder.
Maybe you dould use HTML as your lowest common denominator.

I am aware of ReportLab and its pdf capability, but I
have not looked into it yet. I believe it has a fairly steep learning curve

I think you've got a fair bit to learn for all off this anyway...

By the way, as there is already a wxPostscriptDC, it probably wouldn't
be all that much work to make a wxPDF_DC. Is anyone working on that? it
would be a very nice addition.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Derek Croxton wrote:

I want to create a custom combobox that is linked in a parent-child relationship to another combobox, such that when the first one changes, the options in the second one change. I have figured out (with great difficulty) how to generate a custom event with my combobox, but so far, I can only send it to the parent frame, not to another window on that frame.

From reading the help and examples, it sounds to me like what I want to do is not possible; but since it seems like a rather basic request, I'm hoping that I'm misunderstanding the limitations of events. In particular, it seems like I ought to be able to send the event to another window by passing its id to the event, like this:

        x = MyCustomEvent( self.childBox ),

where "self.childBox" is a property of the parent combobox that gets set at design-time. Then I would want to catch this event inside the custom class, like this:

        EVT_MYCUSTOMEVENT(self, self.updateList)

This works if I try to catch the event in the parent frame, but that defeats the purpose

How are you sending the event, and to where? As you've seen command events only travel up the window heirarchy, not back down. So you need to send the event to the window that needs to receive it.

  self.otherCombo.GetEventHandler().ProcessEvent(event)
or
  wxPostEvent(self.otherCombo, event)

If you don't save a referece to the other combo then you can get it like this:

  otherCombo = self.GetParent().FindWindowById(self.childBox)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Chris Barker wrote:

Another problem with Linux is that the PrintDialog does not give the option
to select a printer.

Doesn't it give the option of typing in a print command? If so, then the
user would either use the default (usually lpr, and easy) or something
like "lpr -PMyPrinter", which is not a big deal for a unix savy user,
but could be a problem. New KDE (and I assume GNOME) apps are smarter,
and will give you alist of CUPS set up printers to choose from. That's
kind of KDE (or GNOME) dependent, however, so it's harder for the
wxWindows printer dialog to do that.

Although it shouldn't be too hard to add some CUPS support to wxWindows, at least printer selection and options. It just requires somebody willing and with time to do the work.

By the way, as there is already a wxPostscriptDC, it probably wouldn't
be all that much work to make a wxPDF_DC. Is anyone working on that?

Not that I know of.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Greg Binns wrote:

HI & thanks in advance
Could someone please tell me where on a window GetSize measures and what
units does it use. Also GetPosition.

Units are pixels.

GetSize measures the outer dimensions of the window, and GetClientSize measures the inner area usable for placing subwindows, drawing, etc. and excludes title bar, scrollbars, etc. GetPosition is the point of the upper left corner of the window relative to its parent (or the desktop for top-level windows). The exception to this are with some X11 Window Managers that don't properly report the frame size including the window decorations.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frank Millman wrote:

> I have started looking into the question of printing from my accounting
> application.

Roger Binns wrote

I strongly recommend you look into HTMLEasyPrinting. You just have to
generate HTML and it handles all the rest.

Alternatively there is a table printer (see More Windows/Controls ->

TablePrint

in the demo).

> it. Alternatively, I am aware of ReportLab and its pdf capability, but I

Instead of getting your app to generate PDF, you can punt to Ghostscript
which will do conversion for you. You could use wxPostScriptDC to

generate

the postscript. Or you can tell the users to setup a PDF printer. For
example on Windows PDFCreator works well, and it works for any app as
it sets itself up as a printer

http://sector7g.wurzel6.de/pdfcreator/index_en.htm

You can do something similar on Linux.

Roger

Thanks for the info, Roger.

I have a nasty feeling that there is not one simple solution for all the
things I want to do, so I will have to construct my own framework to allow
the user to set up their system according to what printers they have
available.

For example, printing invoices on a dot-matrix using pre-printed stationery
requires raw text output, with precise control of print positionsing, which
I do not think wxHtmlEasyPrinting gives you.

Thanks for the link to PDFCreator - it looks very interesting.

Frank

Frank Millman wrote:
> I have started looking into the question of printing from my accounting
> application.

Chris Barker wrote:

I havn't done much with printing, but I think I have some useful
comments:

> printing under Linux (Redhat 9) does not work at
> all. My guess is that this is because my printers are not equipped for
> PostScript.

Do you have printing from other apps set up under Linux? For the most
part, the way printing is done on Linux is that the app produced
Postscript (nice and device independent), and the printing system uses
ghostscript to translate the postscript into whatever language the
printer requires. The printing system also can generally detect a bunch
of other file types and translate them appropriately: text, jpeg, etc.
If yo have printing set up properly on Redhat, you should be able to
send a postscript docuemnt to lpr and have it print correctly.

Using the HP Laserjet with PCL5, I can print a CUPS test page perfectly.
Using the same driver, if I print the test page from the demo, the images
appear correctly, but none of the text appears.

Using the C-Itoh dot-matrix, I really just want generic text output. The MSW
generic text driver allows me to print text from wxPrinterDC with no
problem. If wxPostscriptDC did the same, I could plan to use wxPrintout for
all my printing, which I would prefer.

However, it seems that wxPostscriptDC does not cater for raw text. I can
configure the printer in CUPS as an Epson printer, but when I print the CUPS
test page, it prints perfectly, but takes over 5 minutes to print!
Definitely not what I want.

I am beginning to think I will have to create my own framework, with my own
printer defintions which include the capabilities of each printer, and then
decide the best method of output at runtime - either wxPrintout, or sending
a stream of bytes directly to the printer. Using Linux , I can use lpr to
send a file to a printer. Do you know if there is an equivalent in Windows?

I think you've got a fair bit to learn for all off this anyway...

Indeed I do :slight_smile: However, I am trying to identify the blind alleys in
advance, before venturing too far down them. Your reply has helped me to get
a better concept of what I am trying to achieve - many thanks.

Frank

See Reportlab

Cheers,
DKniep

···

On Monday 17 November 2003 23:36, Robin Dunn wrote:

Chris Barker wrote:

> By the way, as there is already a wxPostscriptDC, it probably wouldn't
> be all that much work to make a wxPDF_DC. Is anyone working on that?

Dick Kniep wrote:

> > By the way, as there is already a wxPostscriptDC, it probably wouldn't
> > be all that much work to make a wxPDF_DC. Is anyone working on that?

See Reportlab

ReportLab looks like a great package, though I havn't had a use for it
myself yet.

However, I'm not so much looking for a way to create PDFs, as I am
looking for a way to create PDFs with the same code I use to draw on the
screen, etc. That's the whole concept of a "Device Context"... you have
one interface to any number of devices.

I suspect it wouldn't be all that much work to adapt the wxPostscriptDC
to produce PDF in addition/instead, but someone has to do that work, and
I don't have the time myself.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Do you know if there is an equivalent in Windows?

On Windows, the only way to send raw data to a printer
is to have the driver open and then tell it you have
raw data (sorry about being vague, I last did this
5 years ago).

There used to be plenty of shareware and freeware programs
out there that did it. It actually is only a few lines
of C code. They were intended for people who did print
to file and then later wanted to submit it to the
printer again.

Roger

> Do you know if there is an equivalent in Windows?

Roger Binns wrote:

On Windows, the only way to send raw data to a printer
is to have the driver open and then tell it you have
raw data (sorry about being vague, I last did this
5 years ago).

There used to be plenty of shareware and freeware programs
out there that did it. It actually is only a few lines
of C code. They were intended for people who did print
to file and then later wanted to submit it to the
printer again.

Roger

Thanks for this, Roger. However, I have found that, on Windows 2000
Professional at least, there is a 'print' command that can send a text file
to a printer.

My current thoughts are that I will need different approaches for Windows
and Linux. With Windows, I *think* that I can use the wx printing framework,
as wxPrintout seems to work ok with raw text printers. With Linux, I cannot
get it to print text to a non-PostScript printer, so I think I will have to
write out a temporary file and send it to the printer with lpr.

I still have lots more experimenting to do before I am sure that this
approach will work, but these are my current thoughts.

Many thanks for your input.

Frank

Thanks for this, Roger. However, I have found that, on Windows 2000
Professional at least, there is a 'print' command that can send a text file
to a printer.

I don't know if that allows you to send a binary file with embedded codes.
Something else to watch out for is that some of those kind of commands
don't work with network printers (eg on netware), USB printers etc.

I cannot
get it to print text to a non-PostScript printer, so I think I will have to
write out a temporary file and send it to the printer with lpr.

Ghostscript does include a program that will take text back out of
Postscript. It didn't do too bad a job the last time I checked.

Roger

Maybe the answer Roger gave me for my earlier query will work for you.
Rather than using lpr or it's MS equivilent you can do it from within Python
using

Windows:

     f=open("lpt1:", "wb")
     f.write("this is a test\r\n")

Linux:

     f=open("/dev/lp0", "wb")
     f.write("this is a test\r\n")

The thread that lead to this was 'Line Printing?' It won't check for errors
or paperout though.

> Thanks for this, Roger. However, I have found that, on Windows 2000
> Professional at least, there is a 'print' command that can send a text

file

> to a printer.

I don't know if that allows you to send a binary file with embedded codes.
Something else to watch out for is that some of those kind of commands
don't work with network printers (eg on netware), USB printers etc.

> I cannot
> get it to print text to a non-PostScript printer, so I think I will have

to

···

> write out a temporary file and send it to the printer with lpr.

Ghostscript does include a program that will take text back out of
Postscript. It didn't do too bad a job the last time I checked.

Roger

Mike Edmonds wrote:

Maybe the answer Roger gave me for my earlier query will work for you.
Rather than using lpr or it's MS equivilent you can do it from within

Python

using

> Windows:
>
> f=open("lpt1:", "wb")
> f.write("this is a test\r\n")
>
> Linux:
>
> f=open("/dev/lp0", "wb")
> f.write("this is a test\r\n")
>

Thanks, Mike. I am beginning to think that I will have to go this route, as
I am really battling with wxPostScriptDC. I will send another post about
this shortly, after I have done some more experimenting.

One comment about the above approach. As my system will probably be used in
multi-user mode, I cannot write directly to the port, as separate jobs could
end up intermingled. Therefore I open a print file, and let the native
printing system handle the spooling. This is the syntax.

For Windows, assume a printer called 'text' on a computer called 'laptop'.
The printer must be shared for this to work.

f = file('\\\\laptop\\text','wb')
f.write('this is a test\r\n')
f.close()

For Linux, assume a printer called 'text'.

f = os.popen('lpr -Ptext','w')
f.write('this is a test\r\n')
f.close()

I have not actually tested this in multi-user mode, but I am pretty sure
that it will keep multiple print jobs separate from each other.

Frank Millman