Tk Source Code

View Ticket
Login
Ticket UUID: 92ab4292952a3fa10a15f414d59a4aa9984650ad
Title: Add new subcommand [tk systray exists] to [tk systray]
Type: RFE Version: 8.7
Submitter: emiliano Created on: 2023-07-21 03:55:50
Subsystem: -- New Commands Assigned To: fvogel
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2023-07-26 20:14:45
Resolution: Fixed Closed By: fvogel
    Closed on: 2023-07-26 20:14:45
Description:
This RFE proposes extending the [tk systray] ensemble to include a [tk systray exists] subcommand.

The [tk systray create] subcommand can be called only once. Calling it twice resuts in an error "only one system tray icon supported per interpeter".
This forces the calling code to use [catch] to either destroy a previously exist
ing tktray or to create a new one.

Attached patch implements a [tk systray exists] subcommand.
User Comments: fvogel added on 2023-07-26 20:14:45:
Now all done as proposed below. Closing.

fvogel added on 2023-07-23 16:22:10:

I have committed your patch as the first commit in branch bug-92ab429295.

On my side I have added tests and documentation.

Suggestions? Please drop them here.

Normally this would require a TIP. However in this specific case we can probably consider this as a bug fix (considering the use case you brought forward). Moreover the systray command didn't yet escape in an official (non-beta) release (so the user-visible interface to Tk is not changed). Finally I'm sure the vote for TIP #325 would have been the same with this small addition.

I'll merge in a day or two, and add a post-vote note to TIP #325. If anyone has objections, please speak up now.


fvogel added on 2023-07-23 07:47:24:
Understood. I'll commit this soon and add a post-vote note to mention it to the adequate TIP that had introduced the systray command. Should be enough I think.

emiliano added on 2023-07-22 21:54:05:
I don't think unconditionally destroying any existing systray icon is a good idea.

The use case scenario I have in mind is:

* if there's no systray created, create one and proceed.
* if it was already created, instrospect its config (for example, whether button3 popups a menu), peraphs extending the menu.

Destroying any previously existing systray prevents this.

Nowadays the only viable approaches are:

* [catch {tk systray destroy}] if I want a clean slate.
* [if {[catch {tk systray create -image $img}]} {# systray already exists} else {...}] if I want to reuse the already existing one (or create it otherwise)

fvogel added on 2023-07-22 06:54:21:

Why not. Another possibility would be [tk systray create] to automatically destroy any previously existing systray icon:

Index: library/systray.tcl
==================================================================
--- library/systray.tcl
+++ library/systray.tcl
@@ -202,11 +202,11 @@
     variable _options
     variable _current
     variable _ico
 
     if {$_created} {
-	return -code error -errorcode {TK SYSTRAY CREATE} "only one system tray icon supported per interpeter"
+	::tk::systray::destroy
     }
     _check_options $args 0
     if {![dict exists $args -image]} {
 	return -code error -errorcode {TK SYSTRAY CREATE} "missing required option \"-image\""
     }

And update the man page which says "attempts to create additional icons will return an error". Plus add one or two tests about this.

What do you think?


Attachments: