diff --git a/TermTk/TTkWidgets/window copy.py b/TermTk/TTkWidgets/window copy.py deleted file mode 100644 index c4d2ebd4..00000000 --- a/TermTk/TTkWidgets/window copy.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env python3 - -# MIT License -# -# Copyright (c) 2021 Eugenio Parodi -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -from TermTk.TTkCore.cfg import * -from TermTk.TTkCore.constant import * -from TermTk.TTkCore.log import TTkLog -from TermTk.TTkCore.color import TTkColor -from TermTk.TTkWidgets.frame import TTkFrame -from TermTk.TTkWidgets.widget import TTkWidget - - -class TTkWindow(TTkWidget): - __slots__ = ('_title', '_mouseDelta', '_draggable', '_resizable') - def __init__(self, *args, **kwargs): - TTkWidget.__init__(self, *args, **kwargs) - self._name = kwargs.get('name' , 'TTkWindow' ) - self._title = kwargs.get('title' , 0 ) - self.setPadding(3,1,1,1) - self._mouseDelta = (0,0) - self.setFocusPolicy(TTkK.ClickFocus) - self._draggable = False - self._resizable = TTkK.NONE - - def paintEvent(self): - if self.hasFocus(): - color = TTkColor.fg("#ffff55") - else: - color = TTkColor.RST - self._canvas.drawText(pos=(2,1),text=self._title) - self._canvas.drawGrid( - color=color, - pos=(0,0), size=self.size(), - hlines=[2], grid=2) - #self._canvas.drawBox(pos=(0,0), color=color, size=(self._width,3)) - #self._canvas.drawBox(pos=(0,2), color=color, size=(self._width,self._height-2)) - #self._canvas.drawText(pos=(0,2), color=color, text="╟"+("─"*(self._width-2))+"╢") - - def mousePressEvent(self, evt): - self._mouseDelta = (evt.x, evt.y) - w,h = self.size() - x,y = evt.x, evt.y - # If the mouse position is inside the header box enable the dragging feature - if x >= 1 and y>=1 and x tmpw: tmpw=minw; dx= w-tmpw - elif maxw < tmpw: tmpw=maxw; dx= w-tmpw - x += dx ; w = tmpw - elif self._resizable & TTkK.RIGHT: - if minw > evt.x: w = minw - elif maxw < evt.x: w = maxw - else: w = evt.x+1 - if self._resizable & TTkK.TOP: - tmph = h-dy - if minh > tmph: tmph=minh; dy= h-tmph - elif maxh < tmph: tmph=maxh; dy= h-tmph - y += dy ; h = tmph - elif self._resizable & TTkK.BOTTOM: - if minh > evt.y: h = minh - elif maxh < evt.y: h = maxh - else: h = evt.y+1 - self.move(x,y) - self.resize(w,h) - return True - return False - - def layoutUpdated(self): - pass - # maxw,maxh = self.layout.maximumSize() - # minw,minh = self.layout.maximumSize() - # if - # self.resize(w+self._padl+self._padr,h+self._padt+self._padb) - - - def focusInEvent(self): - self.update() - - def focusOutEvent(self): - self._draggable = False - self._resizable = TTkK.NONE - self.update() \ No newline at end of file diff --git a/TermTk/TTkWidgets/window.py b/TermTk/TTkWidgets/window.py index c4d2ebd4..213f2605 100644 --- a/TermTk/TTkWidgets/window.py +++ b/TermTk/TTkWidgets/window.py @@ -26,21 +26,20 @@ from TermTk.TTkCore.cfg import * from TermTk.TTkCore.constant import * from TermTk.TTkCore.log import TTkLog from TermTk.TTkCore.color import TTkColor -from TermTk.TTkWidgets.frame import TTkFrame +from TermTk.TTkWidgets.resizableframe import TTkResizableFrame from TermTk.TTkWidgets.widget import TTkWidget -class TTkWindow(TTkWidget): - __slots__ = ('_title', '_mouseDelta', '_draggable', '_resizable') +class TTkWindow(TTkResizableFrame): + __slots__ = ('_title', '_mouseDelta', '_draggable') def __init__(self, *args, **kwargs): - TTkWidget.__init__(self, *args, **kwargs) + TTkResizableFrame.__init__(self, *args, **kwargs) self._name = kwargs.get('name' , 'TTkWindow' ) self._title = kwargs.get('title' , 0 ) self.setPadding(3,1,1,1) self._mouseDelta = (0,0) self.setFocusPolicy(TTkK.ClickFocus) self._draggable = False - self._resizable = TTkK.NONE def paintEvent(self): if self.hasFocus(): @@ -52,82 +51,29 @@ class TTkWindow(TTkWidget): color=color, pos=(0,0), size=self.size(), hlines=[2], grid=2) - #self._canvas.drawBox(pos=(0,0), color=color, size=(self._width,3)) - #self._canvas.drawBox(pos=(0,2), color=color, size=(self._width,self._height-2)) - #self._canvas.drawText(pos=(0,2), color=color, text="╟"+("─"*(self._width-2))+"╢") def mousePressEvent(self, evt): self._mouseDelta = (evt.x, evt.y) - w,h = self.size() + self._draggable = False + w,_ = self.size() x,y = evt.x, evt.y # If the mouse position is inside the header box enable the dragging feature if x >= 1 and y>=1 and x tmpw: tmpw=minw; dx= w-tmpw - elif maxw < tmpw: tmpw=maxw; dx= w-tmpw - x += dx ; w = tmpw - elif self._resizable & TTkK.RIGHT: - if minw > evt.x: w = minw - elif maxw < evt.x: w = maxw - else: w = evt.x+1 - if self._resizable & TTkK.TOP: - tmph = h-dy - if minh > tmph: tmph=minh; dy= h-tmph - elif maxh < tmph: tmph=maxh; dy= h-tmph - y += dy ; h = tmph - elif self._resizable & TTkK.BOTTOM: - if minh > evt.y: h = minh - elif maxh < evt.y: h = maxh - else: h = evt.y+1 - self.move(x,y) - self.resize(w,h) - return True - return False - - def layoutUpdated(self): - pass - # maxw,maxh = self.layout.maximumSize() - # minw,minh = self.layout.maximumSize() - # if - # self.resize(w+self._padl+self._padr,h+self._padt+self._padb) - + return TTkResizableFrame.mouseDragEvent(self, evt) def focusInEvent(self): self.update() def focusOutEvent(self): - self._draggable = False - self._resizable = TTkK.NONE self.update() \ No newline at end of file