Skip to content

Commit

Permalink
Several scrollbar fixes
Browse files Browse the repository at this point in the history
- make sure horizontal scrollbar can also displayed
- make sure both scrollbars can be displayed on the same widget
- make sure the canvas and its inner frame uses the maximum space
  • Loading branch information
1stthomas committed Apr 15, 2018
1 parent 612fd9a commit 7a22c3d
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 91 deletions.
Binary file added ctsoft/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added ctsoft/__pycache__/app_pva_3.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion ctsoft/app_pva_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def resetGui(self):

def run(self):
self.__cntGui.createGui()
self.setupGui()
# self.setupGui()
self.__cntGui.runGui()

def setFileName(self, fname):
Expand Down
Binary file added ctsoft/gui/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added ctsoft/gui/__pycache__/controller.cpython-36.pyc
Binary file not shown.
Binary file added ctsoft/gui/__pycache__/elements.cpython-36.pyc
Binary file not shown.
Binary file added ctsoft/gui/__pycache__/utils.cpython-36.pyc
Binary file not shown.
Binary file added ctsoft/gui/__pycache__/xml.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion ctsoft/gui/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self):
""" string : The name of the XML element id attribute. """
self.__identifier = "id"
""" ctsoft.gui.xml.Parser : The XMl parser. """
self.__parser = ctsxml.Parser(self, "settings.gui.xml")
self.__parser = ctsxml.Parser(self, "settings.gui.scrollbar.xml")
""" mixed : None or the root Tkinter element after GUI creation. """
self.__top = None
""" dict : A collection of GUI widgets with an id. """
Expand Down
158 changes: 114 additions & 44 deletions ctsoft/gui/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PIL import Image, ImageTk
import tkinter as tk
from tkinter.font import Font as tkFont
import xml.etree.ElementTree as xmlee


class TkBase(object):
Expand Down Expand Up @@ -942,85 +943,154 @@ def getValue(self):
class ContainerScrollable(object):
def __init__(self, parent, xml, *args, **kw):
self.__canvas = None
self.__canvasFrameDimension = None
self.__content = None
self.__frame = None
self.__parent = parent
self.__scrollbars = {}

self.createWidgets(xml)

def createScrollbarWidget(self, parent, canvas, xml):
def addScrollbar(self, orient, scrollbar):
self.__scrollbars[orient] = scrollbar

def createCanvas(self, parent, xmlCanvas):
canvas = TkCanvas(parent, xmlCanvas)
canvas.grid(column=0, row=0, sticky="nwse")
self.setCanvas(canvas)

return canvas

def createCanvasFrame(self, parent, xml):
frame = TkFrame(parent, xml)
self.setCanvasFrame(frame)

return frame

def createScrollbarWidget(self, parent, xml):
sb = TkScrollbar(parent, xml)
orientation = getattr(self.canvas, "orient", "vertical")
if orientation == "vertical":

if xml.attrib.get("orient", "vertical") == "vertical":
# Set the default value for the case it is not set already.
xml.attrib["orient"] = "vertical"
self.canvas.configure(yscrollcommand=sb.set)
sb.configure(command=self.canvas.yview)
# Compose the Canvas scrollcommand for y with the scrollbar.
self.__canvas.configure(yscrollcommand=sb.set)
# Compose the scrollbar action with the canvas viewport.
sb.configure(command=self.__canvas.yview)
# configure the layout manager of the scrollbar
sb.grid(column=1, row=0, sticky="nes")
else:
self.canvas.configure(xscrollcommand=sb.set)
sb.configure(command=self.canvas.xview)
# The vertical orientation is default.
sb.configure(orient="horizontal")
self.__canvas.configure(xscrollcommand=sb.set)
sb.configure(command=self.__canvas.xview)
sb.grid(column=0, row=1, sticky="esw")

self.addScrollbar(xml.attrib["orient"], sb)

return sb

def createWidgets(self, xml):
parent = self.getParent()
xmlSetup = xml.find("setup")

xmlCanvas = xmlSetup.find("canvas")
self.canvas = TkCanvas(parent, xmlCanvas)
self.canvas.pack(self.getPackOptions(xmlCanvas))
canvas = self.createCanvas(parent, xmlCanvas)

xmlFrame = xmlCanvas.find("frame")
frame = TkFrame(self.canvas, xmlFrame)
frame = self.createCanvasFrame(canvas, xmlFrame)

xmlScrollbars = xmlSetup.findall("scrollbar")
for xmlScrollbar in xmlScrollbars:
sb = self.createScrollbarWidget(parent, self.canvas, xmlScrollbar)
sb.pack(self.getPackOptions(xmlScrollbar))
self.createScrollbarWidget(parent, xmlScrollbar)

# Define the row and column behavior on resizing.
parent.rowconfigure(0, weight=1)
parent.rowconfigure(1, weight=0)
parent.columnconfigure(0, weight=1)
parent.columnconfigure(1, weight=0)

self.canvasWindow = canvas.create_window((0, 0), window=frame,
anchor="nw",
tags="self.__frame")

self.canvas.create_window((0,0), window=frame,
anchor="nw", tags="frame")
frame.bind("<Configure>", self.onFrameConfigure)

# make sure the inner frames size is filled and updated if defined.
self.defineCanvasFrameDimension(xmlFrame)
self.setFrameDimensions(frame, xmlFrame)

self.populate(frame)
self.setContent({})

def getPackOptions(self, xmlWidget):
packOptions = xmlWidget.find("pack")
if packOptions:
return packOptions
else:
packOptions = {}

if xmlWidget.tag == "canvas":
packOptions["expand"] = "True"
packOptions["fill"] = "both"
packOptions["side"] = "left"
elif xmlWidget.tag == "frame":
packOptions["expand"] = "True"
packOptions["fill"] = "both"
packOptions["side"] = "top"
elif xmlWidget.tag == "scrollbar":
if xmlWidget.attrib["orient"] == "vertical":
# if getattr(xmlWidget.attrib, "orient") == "vertical":
packOptions["fill"] = "y"
packOptions["side"] = "right"
else:
packOptions["fill"] = "x"
packOptions["side"] = "left"
def defineCanvasFrameDimension(self, xml):
xmlDimension = xml.find("dimension")

if "fill" in xmlDimension.attrib:
if xmlDimension.attrib["fill"] == "both":
self.__canvasFrameDimension = "both"
elif xmlDimension.attrib["fill"] == "x":
self.__canvasFrameDimension = "x"
elif xmlDimension.attrib["fill"] == "y":
self.__canvasFrameDimension = "y"

def getCanvas(self):
return self.__canvas

return packOptions
def getCanvasFrame(self):
return self.__frame

def getContent(self):
return self.__content

def getParent(self):
return self.__parent

def getScrollbar(self, orient):
return self.__scrollbars.get(orient, None)

def getScrollbars(self):
return self.__scrollbars

def onCanvasFrameDimension(self, event):
canvas = self.getCanvas()
frame = self.getCanvasFrame()

canvasHeight = event.height
canvasWidth = event.width

if canvasWidth <= frame.winfo_reqwidth():
canvasWidth = frame.winfo_reqwidth()
if canvasHeight <= frame.winfo_reqheight():
canvasHeight = frame.winfo_reqheight()

if self.__canvasFrameDimension == "both":
canvas.itemconfig(self.canvasWindow, height=canvasHeight,
width=canvasWidth)
elif self.__canvasFrameDimension == "x":
canvas.itemconfig(self.canvasWindow, width=canvasWidth)
elif self.__canvasFrameDimension == "y":
canvas.itemconfig(self.canvasWindow, height=canvasHeight)

def onFrameConfigure(self, event):
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
self.getCanvas().configure(scrollregion=self.__canvas.bbox("all"))

def setCanvas(self, canvas):
self.__canvas = canvas

def setCanvasFrame(self, frame):
self.__frame = frame

def setContent(self, xml):
self.__content = xml

def populate(self, frame): # just for testing..
for row in range(100):
tk.Label(frame, text="%s" % row, width=3, borderwidth="1",
def setFrameDimensions(self, frame, xml):
if self.__canvasFrameDimension is not None:
self.getCanvas().bind('<Configure>', self.onCanvasFrameDimension)

def populate(self, parent): # just for testing..
for row in range(15):
tk.Label(parent, text="%s" % row, width=3, borderwidth="1",
relief="solid").grid(row=row, column=0)
t = "this is the second column for row %s" %row
tk.Label(frame, text=t).grid(row=row, column=1)
t = "this is the second column for row %s" % row
tk.Label(parent, text=t).grid(row=row, column=1)
1 change: 0 additions & 1 deletion ctsoft/gui/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ def create(self, xml, parent):
self.__current = ctsel.RadiobuttonGroup(parent, xml)
return False
elif xml.tag == "scrollable":
print("builder scrollable")
self.__current = ctsel.ContainerScrollable(parent, xml)
self.setChangedXml(self.__current.getContent())
self.__doChangeXml = True
Expand Down
Binary file added ctsoft/math1/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file added ctsoft/math1/__pycache__/plots.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion ctsoft/math1/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def createPieChart(self, data):
return self.__fName

def createHistogram(self, data):
num_bins = 5
num_bins = 50
n, bins, patches = plt.hist(data, num_bins)
# n, bins, patches = plt.hist(data, num_bins, facecolor="blue")
plt.savefig(self.__fName)
Expand Down
4 changes: 2 additions & 2 deletions data01b.csv → data01a.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1;1
2;4
3;9
4;16
5;25
4;12
5;14
5 changes: 5 additions & 0 deletions data02a.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1;1;3
2;4;5
3;9;9
4;12;11
5;14;12
5 changes: 5 additions & 0 deletions data03a.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1;1;3
2;4;5
3;9;9
4;12;11
5;14;12
5 changes: 5 additions & 0 deletions data04a.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3.33333
52
21
9
14.66667
21 changes: 21 additions & 0 deletions data05a.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
21
22
23
4
5
6
77
8
9
10
31
32
33
34
35
36
37
18
49
50
100
Binary file removed fib_runtime_plot.png
Binary file not shown.
Binary file added function_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 0 additions & 26 deletions settings.gui.extended.xml

This file was deleted.

14 changes: 0 additions & 14 deletions settings.gui.minimal.xml

This file was deleted.

17 changes: 17 additions & 0 deletions settings.gui.scrollbar.01.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<gui>
<window bg="#EFEFEF" minsize-x="500" minsize-y="100" title="FFHS - AWD - PVA 2">
<row num="0" weight="1" />
<frame bg="#EFEFEF">
<grid row="0" column="0" sticky="nesw">
<column num="0" weight="1" uniform="group1" />
</grid>
<scrollbar>
<pack expand="true" fill="y" side="right" />
</scrollbar>
<label anchor="nw" bg="green" id="gui-message" text="1\n2\n3\n4\n5\n67\n8\n9\n" wraplength="5">
<pack expand="true" fill="both" side="top" />
</label>
</frame>
</window>
</gui>
41 changes: 41 additions & 0 deletions settings.gui.scrollbar.02.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<gui>
<!--<window bg="#EFEFEF" title="FFHS - AWD - PVA 2">-->
<window bg="#EFEFEF" minsize-x="50" minsize-y="50" title="FFHS - AWD - PVA 2">
<row num="0" weight="1" />
<row num="1" weight="0" />
<canvas bg="orange" bd="2">
<grid column="0" row="0" sticky="nswe">
<column num="0" weight="1" />
</grid>
<!--<label bg="red" height="50" text="row 0, col 0" width="100">-->
<label bg="red" text="row 0, col 0">
<pack expand="True" fill="both" />
</label>
</canvas>
<frame>
<grid column="1" row="0">
<column num="1" weight="0" />
</grid>
<label bg="green" text="row 0, col 1">
<pack expand="True" fill="both" />
</label>
</frame>
<frame bg="cyan" bd="2">
<grid column="0" row="1" sticky="nswe">
<column num="0" weight="1" />
</grid>
<label bg="blue" text="row 1, col 0">
<pack />
</label>
</frame>
<frame>
<grid column="1" row="1">
<column num="1" weight="0" />
</grid>
<label bg="yellow" text="row 1, col 1">
<pack expand="True" fill="both" />
</label>
</frame>
</window>
</gui>
Loading

0 comments on commit 7a22c3d

Please sign in to comment.