Skip to content

Commit

Permalink
functions to change colour of list box items
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisteach committed Feb 11, 2017
1 parent b84d35e commit 479ee07
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 19 deletions.
13 changes: 13 additions & 0 deletions appJar/appjar.py
Expand Up @@ -4489,6 +4489,19 @@ def removeListItem(self, title, item):
pos -= 1
self.selectListItemPos(title, pos)

# functions to config
def configListItemAtPos(self, title, pos, col):
lb = self.__verifyItem(self.n_lbs, title)
lb.itemconfig(pos, bg=col)

def configListItem(self, title, item, col):
lb = self.__verifyItem(self.n_lbs, title)
items = lb.get(0, END)
for pos, val in enumerate(items):
if val == item:
self.configListItemAtPos(title, pos, col)


def clearListBox(self, title):
lb = self.__verifyItem(self.n_lbs, title)
lb.delete(0, END) # clear
Expand Down
73 changes: 54 additions & 19 deletions examples/rgb.py
Expand Up @@ -2,16 +2,31 @@
sys.path.append("../")
from appJar import gui

alreadyDone = False

# funciton to handle the button presses
def btnPress(btnName):
if btnName == "Reset":
app.setSpinBox("redSpin", 0)
app.setSpinBox("greSpin", 0)
app.setSpinBox("bluSpin", 0)
app.clearEntry("colCode")
elif btnName == "Convert":
elif btnName == "Log":
RGB = getRGB()
app.setEntry("colCode", RGB)
if RGB in app.getAllListItems("colours"):
app.selectListItem("colours", RGB)
else:
app.addListItem("colours", RGB)
app.configListItem("colours", RGB, RGB)
elif btnName == "colours":
RGB = app.getListItems("colours")
if len(RGB) > 0:
RGB = RGB[0]
app.setLabelBg("colBox", RGB)
app.setEntry("colCode", RGB)
loadRGB(RGB)
elif btnName == "Clear":
app.clearListBox("colours")


# function to convert the scale values to an RGB hex code
def getRGB():
Expand All @@ -31,8 +46,26 @@ def getRGB():

return RGB

def loadRGB(RGB):
# split the RGB string, then convert to ints
R = int(RGB[1:3], 16)
G = int(RGB[3:5], 16)
B = int(RGB[5:7], 16)

app.setScale("redScale", R)
app.setScale("greScale", G)
app.setScale("bluScale", B)

# funciton to update widgets
def updateRGB(name):
# this stops the changes in slider/spin from constantly calling each other
global alreadyDone
if alreadyDone:
alreadyDone = False
return
else:
alreadyDone = True

# split the widget's name into the type & colour
colour = name[0:3]
widg = name[3:]
Expand All @@ -52,18 +85,19 @@ def updateRGB(name):
app.setLabelBg("colBox", RGB)
app.setEntry("colCode", RGB)

app = gui()
app = gui("RGB COlours")
app.setBg("#B8DEE2")
app.setGuiPadding(5,5)
app.setFont(18)

# frame to contain sliders
app.startLabelFrame("Colour Codes")
app.setSticky("news")
app.setPadding(5,5)

app.addLabel("redLab", "Red Color (R):", 0, 0)
app.addLabel("greLab", "Green Color (G):", 1, 0)
app.addLabel("bluLab", "Blue Color (B):", 2, 0)
app.addLabel("redLab", "Red (R):", 0, 0)
app.addLabel("greLab", "Green (G):", 1, 0)
app.addLabel("bluLab", "Blue (B):", 2, 0)

app.setLabelAlign("redLab", "left")
app.setLabelAlign("greLab", "left")
Expand Down Expand Up @@ -97,25 +131,26 @@ def updateRGB(name):

# frame to hold coloured label
app.startLabelFrame("Colour Preview")

app.setInPadding(5,5)
app.setPadding(5,5)
app.setSticky("news")
app.addEmptyLabel("colBox", 3, 0, 3)
app.addEmptyLabel("colBox", colspan=3)
app.setLabelHeight("colBox", 5)
app.setLabelWidth("colBox", 25)
app.setLabelRelief("colBox", "ridge")

app.addHorizontalSeparator(colspan=3)
app.addLabel("colCodeLab", "HEX Colour Code:", column=0)
app.addEntry("colCode", row=2, column=1)
app.addButton("Reset", btnPress, row=2, column=2)
app.disableEntry("colCode")
app.stopLabelFrame()

# frame with result & buttons
app.startLabelFrame("Actions")

app.addLabel("colCodeLab", "HEX colour code:", 0, 0)
app.addEntry("colCode", 0, 1)
app.disableEntry("colCode")
app.startLabelFrame("Colour History")
app.setPadding(5,5)
app.setSticky("EW")
app.addButtons(["Convert", "Reset"], btnPress, 1, 0, 2)

app.addListBox("colours", [])
app.setListBoxRows("colours", 4)
app.setListBoxFunction("colours", btnPress)
app.addButtons(["Log", "Clear"], btnPress)
app.stopLabelFrame()

app.go()

0 comments on commit 479ee07

Please sign in to comment.