diff --git a/TermTk/TTkCore/canvas.py b/TermTk/TTkCore/canvas.py index 3172906a..3896eaf6 100644 --- a/TermTk/TTkCore/canvas.py +++ b/TermTk/TTkCore/canvas.py @@ -192,10 +192,10 @@ class TTkCanvas: else: self._colors[y][x+i] = colors[i].mod(x+i,y) # Check the full wide chars on the edge of the two canvasses - if self._data[y][x+a] == '': + if 0 <= (x+a) < self._width and self._data[y][x+a] == '': self._data[y][x+a] = TTkCfg.theme.unicodeWideOverflowCh[0] self._colors[y][x+a] = TTkCfg.theme.unicodeWideOverflowColor - if TTkString._isWideCharData(self._data[y][x+b-1]): + if 0 <= (x+b-1) < self._width and TTkString._isWideCharData(self._data[y][x+b-1]): self._data[y][x+b-1] = TTkCfg.theme.unicodeWideOverflowCh[1] self._colors[y][x+b-1] = TTkCfg.theme.unicodeWideOverflowColor @@ -614,16 +614,16 @@ class TTkCanvas: self._colors[y+iy][a:b] = canvas._colors[iy][xoffset:wslice] # Check the full wide chars on the edge of the two canvasses - if self._data[y+iy][a]=='': + if 0 <= a < self._width and self._data[y+iy][a]=='': self._data[y+iy][a] = TTkCfg.theme.unicodeWideOverflowCh[0] self._colors[y+iy][a] = TTkCfg.theme.unicodeWideOverflowColor - if TTkString._isWideCharData(self._data[y+iy][b-1]): + if 0 < b <= self._width and TTkString._isWideCharData(self._data[y+iy][b-1]): self._data[y+iy][b-1] = TTkCfg.theme.unicodeWideOverflowCh[1] self._colors[y+iy][b-1] = TTkCfg.theme.unicodeWideOverflowColor - if TTkString._isWideCharData(self._data[y+iy][a-1]): + if 0 < a <= self._width and TTkString._isWideCharData(self._data[y+iy][a-1]): self._data[y+iy][a-1] = TTkCfg.theme.unicodeWideOverflowCh[1] self._colors[y+iy][a-1] = TTkCfg.theme.unicodeWideOverflowColor - if ( b +# +# 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. + +import sys, os + +sys.path.append(os.path.join(sys.path[0],'../../tmp')) +sys.path.append(os.path.join(sys.path[0],'../..')) +import TermTk as ttk + + +class WindowFlagsTest(ttk.TTkWindow): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + rb = ttk.TTkCheckbox( + parent=self, pos=(0,0), size=(20,1), text='Reduce Button', + checked=bool(self.windowFlag()&ttk.TTkK.WindowFlag.WindowReduceButtonHint)) + minb = ttk.TTkCheckbox( + parent=self, pos=(0,1), size=(20,1), text='Minimize Button', + checked=bool(self.windowFlag()&ttk.TTkK.WindowFlag.WindowMinimizeButtonHint)) + maxb = ttk.TTkCheckbox( + parent=self, pos=(0,2), size=(20,1), text='Maximize Button', + checked=bool(self.windowFlag()&ttk.TTkK.WindowFlag.WindowMaximizeButtonHint)) + cb = ttk.TTkCheckbox( + parent=self, pos=(0,3), size=(20,1), text='Close Button', + checked=bool(self.windowFlag()&ttk.TTkK.WindowFlag.WindowCloseButtonHint)) + + def _cbStateChanged(state,field): + if state==ttk.TTkK.Checked: + self.setWindowFlag(self.windowFlag()|field) + else: + self.setWindowFlag(self.windowFlag()&(~field)) + + rb.stateChanged.connect( lambda x: _cbStateChanged(x,ttk.TTkK.WindowFlag.WindowReduceButtonHint)) + minb.stateChanged.connect(lambda x: _cbStateChanged(x,ttk.TTkK.WindowFlag.WindowMinimizeButtonHint)) + maxb.stateChanged.connect(lambda x: _cbStateChanged(x,ttk.TTkK.WindowFlag.WindowMaximizeButtonHint)) + cb.stateChanged.connect( lambda x: _cbStateChanged(x,ttk.TTkK.WindowFlag.WindowCloseButtonHint)) + + + +def demoWindowsFlags(root=None): + frame = ttk.TTkFrame(parent=root, border=False) + + WindowFlagsTest(parent=frame, pos = (0,0), size=(40,8), title="Test Window 1") + WindowFlagsTest(parent=frame, pos = (2,2), size=(40,8), title="Test Window 2", + flags = ttk.TTkK.WindowFlag.WindowMaximizeButtonHint | ttk.TTkK.WindowFlag.WindowCloseButtonHint) + WindowFlagsTest(parent=frame, pos = (4,4), size=(40,8), title="Test Window 3", + flags = ttk.TTkK.NONE) + WindowFlagsTest(parent=frame, pos = (6,6), size=(40,8), title="Test Window 4", + flags = ttk.TTkK.WindowFlag.WindowMinMaxButtonsHint) + WindowFlagsTest(parent=frame, pos = (8,8), size=(40,8), title="Test Window 5", + flags = ttk.TTkK.WindowFlag.WindowReduceButtonHint) + + return frame + + + +def main(): + ttk.TTkLog.use_default_file_logging() + root = ttk.TTk() + win1 = ttk.TTkWindow(parent=root,pos = (1,1), size=(60,30), title="Test Window Flags", border=True, layout=ttk.TTkGridLayout(), flags=ttk.TTkK.NONE) + demoWindowsFlags(win1) + root.mainloop() + +if __name__ == "__main__": + main() \ No newline at end of file