martin
martin

Reputation: 676

set maximum window size

How can I set the maximum window size of a LTK window?

(ql:quickload "ltk")

(defpackage :pub-quiz
  (:use :ltk :cl))

(in-package :pub-quiz)

(defun pub-quiz-window ()
  (with-ltk ()
    (let* ((f (make-instance 'frame :relief :groove :height 500 :width 300))
           (pub (make-instance 'label :master f :text "Pub Quiz"))
           (outtext (make-instance 'text :font "monospaced" :wrap :word))
           (tf (make-instance 'text  :font "monospaced")))
      (pack f)
      (pack pub :side :left)
      (pack outtext :ipady 100)
      (pack tf))))

If I set the frame size to height and width like in the above code sample, my window wm does not respect these values at all.

The Tk docs have this

wm maxsize .window 500 500

but I don't know how to translate this into something LTK understands.

Upvotes: 0

Views: 437

Answers (2)

Sim
Sim

Reputation: 4184

I am not sure I understand your query correctly, but given the title I assume you want to ensure that the window opened must not be expanded beyond a given dimension?

If so, you have to set the master window . which is accessible via *tk*:

(defun pub-quiz-window ()
  (maxsize *tk* 300 300)
  (minsize *tk* 300 300)
  (let* ((f (make-instance 'frame :relief :groove :height 50 :width 30))
         (pub (make-instance 'label :master f :text "Pub Quiz"))
         (outtext (make-instance 'text :font "monospaced" :width 10 :height 10))
         (tf (make-instance 'text  :font "monospaced" :height 10 :width 10)))
    (pack f :side :left)
    (pack pub :side :left)
    (pack outtext :side :left)
    (pack tf :side :left)))

(defun create-local-view ()
  (with-ltk ()
    (pub-quiz-window)))

Upvotes: 0

Joshua Taylor
Joshua Taylor

Reputation: 85863

I haven't used LTK, so I can't make much claim about how this is supposed to be done; I'm just answering based on what I've found online. The LTK manual mentions in section 3.7 that there is a maxsize function:

(maxsize toplevel width height)

Set the maximum size of the window in pixels.

Calling (maxsize f 500 500) doesn't work though. The implementation of maxsize is:

(defgeneric maxsize (widget x y))
(defmethod maxsize ((w widget) x y)
  (format-wish "wm maxsize ~a ~a ~a" (widget-path w) (tk-number x) (tk-number y))
  w)

The number translation works just fine, I think (ltk::tk-number 500) => 500. However, (widget-path f), for the f in your code returns .wc, not .window, as the TK snippet you posted shows. You could run that code directly with

(format-wish "wm maxsize .window 500 500")

but that causes an error too:

Tcl/Tk error: bad window path name ".window"

I'm not sure what element's path will work for you in this case, but it seems like once you've found that, maxsize will do what you need it to. There is a toplevel class, and calling maxsize with instances of it seems to work, so perhaps you should explore

(let* ((f (make-instance 'toplevel :relief :groove :height 500 :width 300))
       ...)
  ...
  (maxsize f 500 500))

Playing around with it, I can sort of get that to work, although that "Pub Quiz" label seems to keep appearing as a separate window…

Upvotes: 1

Related Questions