From c2db35c6fc5c6f3a7ffe1bf53058906ab3975f48 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Thu, 30 Apr 2026 23:01:43 +0200 Subject: [PATCH] wv tray docs --- example1/example.rkt | 4 +- info.rkt | 1 + scrbl/wv-tray.scrbl | 99 +++++++++++++++++++++++++++++++++++++++++++ scrbl/wv-window.scrbl | 69 ++++++++++++++++++++++++++---- wv-window.rkt | 4 ++ 5 files changed, 167 insertions(+), 10 deletions(-) create mode 100644 scrbl/wv-tray.scrbl diff --git a/example1/example.rkt b/example1/example.rkt index e217a31..d5f9292 100644 --- a/example1/example.rkt +++ b/example1/example.rkt @@ -113,7 +113,9 @@ (unless (eq? counter-thread #f) (send this message 'warning "Cannot close window" "Cannot close this window while the counter runs")) - (eq? counter-thread #f)) + (if (eq? counter-thread #f) + (super can-close?) + #f)) (define start-stop-btn #f) diff --git a/info.rkt b/info.rkt index d1d5e26..213b5e6 100644 --- a/info.rkt +++ b/info.rkt @@ -12,6 +12,7 @@ ("scrbl/wv-context.scrbl" () (gui-library) "wv-context") ("scrbl/wv-settings.scrbl" () (gui-library) "wv-settings") ("scrbl/wv-window.scrbl" () (gui-library) "wv-window") + ("scrbl/wv-tray.scrbl" () (gui-library) "wv-tray") ("scrbl/menu.scrbl" () (gui-library) "menu") ("scrbl/wv-dialog.scrbl" () (gui-library) "wv-dialog") ("scrbl/wv-element.scrbl" () (gui-library) "wv-element") diff --git a/scrbl/wv-tray.scrbl b/scrbl/wv-tray.scrbl new file mode 100644 index 0000000..aed28aa --- /dev/null +++ b/scrbl/wv-tray.scrbl @@ -0,0 +1,99 @@ +#lang scribble/manual + +@(require (for-label racket/base + racket/class + racket/contract + "../wv-tray.rkt" + "../menu.rkt")) + +@title{Tray Icons} + +@author[@author+email["Hans Dijkema" "hans@dijkewijk.nl"]] + +@defmodule[(file "../wv-tray.rkt")] + +The @racketmodname[(file "../wv-tray.rkt")] module provides the +@racket[wv-tray%] class. A tray object represents a native system tray +icon backed by the webview runtime. + +@defclass[wv-tray% object% ()]{ + +Creates a native tray icon. + +@bold{Initialization fields} + +@itemlist[#:style 'compact + @item{@racket[icon] — mandatory} + @item{@racket[tooltip] — default @racket[""]} + @item{@racket[menu] — default @racket[#f]}] + +If a menu is provided, it is installed during initialization. + +@bold{Events} + +These methods can be overridden. + +@defmethod[(activated [reason symbol?]) any/c]{ +Called when the tray icon is activated. The @racket[reason] is derived +from the native event. +} + +@defmethod[(message-clicked) any/c]{ +Called when a tray message is clicked. +} + +@defmethod[(menu-item-chosen [id symbol?]) any/c]{ +Called when a menu item is chosen without a registered callback. +} + +@defmethod[(unhandled-event [evt hash?]) any/c]{ +Called for unhandled native events. +} + +@bold{Commands} + +@defmethod[(show) (is-a?/c wv-tray%)]{ +Shows the tray icon and returns the tray object. +} + +@defmethod[(hide) (is-a?/c wv-tray%)]{ +Hides the tray icon and returns the tray object. +} + +@defmethod[(close) (is-a?/c wv-tray%)]{ +Closes the tray icon and returns the tray object. +} + +@defmethod[(set-icon! [icon-file path-string?]) (is-a?/c wv-tray%)]{ +Changes the tray icon and returns the tray object. +} + +@defmethod[(set-tooltip! [text string?]) (is-a?/c wv-tray%)]{ +Changes the tooltip and returns the tray object. +} + +@defmethod[(show-message [title string?] + [message string?]) + (is-a?/c wv-tray%)]{ +Shows a native tray message and returns the tray object. +} + +@defmethod[(set-menu! [menu-def any/c]) (is-a?/c wv-tray%)]{ +Installs a tray menu and returns the tray object. +} + +@defmethod[(connect-menu! [id symbol?] + [callback procedure?]) + (is-a?/c wv-tray%)]{ +Registers a callback for a menu item and returns the tray object. +} + +@defmethod[(disconnect-menu! [id symbol?]) (is-a?/c wv-tray%)]{ +Removes a menu callback and returns the tray object. +} + +@defmethod[(handle) any/c]{ +Returns the native tray handle. +} + +} \ No newline at end of file diff --git a/scrbl/wv-window.scrbl b/scrbl/wv-window.scrbl index ad9950a..46b1afd 100644 --- a/scrbl/wv-window.scrbl +++ b/scrbl/wv-window.scrbl @@ -55,6 +55,7 @@ API. [settings (send wv-context settings (string->symbol (format "~a" html-path)))] [title string? "Racket Webview Window"] + [icon (or/c path-string? #f) #f] [width (or/c exact-integer? #f) #f] [height (or/c exact-integer? #f) #f] [x (or/c exact-integer? #f) #f] @@ -78,7 +79,9 @@ After construction, the class: @item{creates the underlying webview window} @item{installs the internal event handler} @item{sets the title} - @item{initializes position and size from settings or defaults}] + @item{Applies the icon during construction when it is not @racket[#f]} + @item{initializes position and size from settings or defaults} + ] If a parent is supplied, the underlying lower-level parent window is passed to @racket[webview-create]. @@ -148,13 +151,6 @@ Updates the internal size and stores the new dimensions in @racket[settings] under @racket['width] and @racket['height]. } -@defmethod[(window-state-changed [st symbol?]) any/c]{ - -Called when the underlying window state changes. - -The default implementation returns @racket[#t]. -} - @defmethod[(page-loaded [oke any/c]) any/c]{ Called when a @racket['page-loaded] event is received. @@ -223,6 +219,8 @@ window. Opens the developer tools and returns this window. } +@bold{Window manipulation and information} + @defmethod[(move [x exact-integer?] [y exact-integer?]) (is-a?/c wv-window%)]{ Moves the window and returns this window. @@ -238,6 +236,45 @@ Resizes the window and returns this window. Closes the window and returns this window. } +@defmethod[(show) (is-a?/c wv-window%)]{Shows the window.} +@defmethod[(present) (is-a?/c wv-window%)]{Presents the window.} +@defmethod[(hide) (is-a?/c wv-window%)]{Hides the window.} +@defmethod[(maximize) (is-a?/c wv-window%)]{Maximizes the window.} +@defmethod[(minimize) (is-a?/c wv-window%)]{Minimizes the window.} +@defmethod[(show-normal) (is-a?/c wv-window%)]{Restores normal state.} + + +@defmethod[(window-state) symbol?]{ + Returns the current native window state. + } + +@defmethod[(window-state-changed [st symbol?]) any/c]{ + Called when the underlying window state changes. + + Window states following calls to @racket{show}, @racket{present}, @racket{hide}, etc.: + @itemlist[#:style 'compact + @item{@racket{'normal}} + @item{@racket{'hidden}} + @item{@racket{'minimized}} + @item{@racket{'maximized}} + @item{@racket{'maximized-active} and} + @item{@racket{'normal-active}} + ] + are forwarded to @racket{window-state-changed}. + } + +@defmethod[(quit) (is-a?/c wv-window%)]{Quits the webview runtime.} + + +@bold{Menu's and binding elements to events} + +@defmethod[(popup-menu! [menu-def is-wv-menu?] + [x exact-integer?] + [y exact-integer?]) + any/c]{ +Shows @racket[menu-def] as a popup menu at @racket[x], @racket[y]. +} + @defmethod[(bind! [selector (or/c symbol? string?)] [events (or/c symbol? list?)] [callback procedure?]) @@ -269,7 +306,7 @@ internal cache. The returned value is the list produced by @racket[webview-unbind!]. } - @defmethod[(set-menu! [menu is-wv-menu?]) +@defmethod[(set-menu! [menu is-wv-menu?]) (is-a?/c wv-window%)]{ Installs @racket[menu] in this window and returns this window. @@ -305,6 +342,20 @@ chosen. Sets the window title. } +@defmethod[(set-icon! [icon-file path-string?]) any/c]{ + Sets the window icon. + } + + +@bold{Javascript methods} + +See also **Javascript syntax module** + +@defmethod[(run-js [js string?]) any/c]{ Runs JavaScript in the window. } +@defmethod[(call-js [js string?]) any/c]{ Calls JavaScript in the window and returns the decoded result. } + +@bold{File dialog methods} + @defmethod[(file-dialog-done [flag symbol?] [file any/c] [dir any/c] diff --git a/wv-window.rkt b/wv-window.rkt index aa2522b..1db0176 100644 --- a/wv-window.rkt +++ b/wv-window.rkt @@ -60,6 +60,7 @@ [height #f] [x #f] [y #f] + [quit-on-close #t] ) (define wv #f) @@ -247,6 +248,8 @@ #t) (define/public (can-close?) + (when quit-on-close + (send this quit)) #t) (define/public (closed) @@ -341,6 +344,7 @@ this) (define/public (quit) + (dbg-webview "Quit called") (webview-quit) this)