I am new to Kivy and this is my first time trying to create a scrollView.
I am trying to do a 'Splitwise' ripoff where you can create expenses and let the app figure out who should pay who etc.
I am trying to create a method that opens a popup with all members and their balances as well as a button with the text 'Settle up'. Underneath the balances should be a list of all the registered debts, and you should be able to scroll down to see them all. The popup should also contain a 'Cancel'-button.
My problem is that my code doesn't enable scrolling, and also squishes together the content in the pop up. See picture.
All help highly appreciated!
See (messy) code below:
sbl_ret = GridLayout(cols = 1)
sbl_balances = GridLayout(cols = 3)
sbl_balances.add_widget(Label())
sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
sbl_balances.add_widget(Label())
for member in self.members:
sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))
sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))
sbl2 = BoxLayout(orientation = 'vertical')
sbl2.add_widget(Label(size_hint = (1,.2)))
btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
btn.bind(on_press = lambda member: self.settleUp())
sbl2.add_widget(btn)
sbl2.add_widget(Label(size_hint = (1,.2)))
sbl_balances.add_widget(sbl2)
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
for member in self.members:
for debt in member.getDebtList():
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.bind(minimum_height=sbl_balances.setter('height'))
sbl3 = BoxLayout(size_hint = (1,.15))
sbl3.add_widget(Label(size_hint = (.2,1)))
b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
b.bind(on_press = lambda x: self.balanceDialog.dismiss())
sbl3.add_widget(b)
sbl3.add_widget(Label(size_hint = (.2,1)))
sv = ScrollView(do_scroll_x = False)
sv.add_widget(sbl_balances)
sbl_ret.add_widget(sv)
sbl_ret.add_widget(sbl3)
self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
self.balanceDialog.open()
'''
Try adding size_hint_y=None to your code creating the GridLayout:
sbl_balances = GridLayout(cols = 3, size_hint_y=None)
See the documentation.
Related
I would love to have your input how to solve this issues.
I have a time series (x=date) ggplot with bars (y=cmass1), and my bars are on position="stack" using a factor (polymer) to display polymer types for each sample.
Each bar represents another sampling station (factor sample), and I would like to identify which bar is which station (factor "sample" in my data frame) and add the label above each bar.
I've come so far that I can show the "sample" labels, but then there appear multiple replicated labels (one for each data point in the stacked parts of the bar). But I need only one per bar!
Can someone help, how I can create one label per bar (above each bar) that identifies which sample it is (without manual annotation)?
Additional date display problem:
Also, on one date (11 November) I have two samples, and in this plot they are cumulated, but I would need them next to each - so two as stacked bars on one date (like with besides=TRUE, but that doesn't seem to work with stacked bars). Any help here?
I hope it is clear, and thanks so much for any help!
Cleo
The plot, where S1, S2 etc should be above each bar as a label
Dataframe view_partial
ggplot(Merg1[!(is.na(Merg1$campaign)),] ,
aes(date,y=cmass1,group_by(sample1), fill=polymer))+
geom_col(show.legend = T, alpha = 0.8, position="stack",
stat="identity")+
xlab("July 2021 November 2021 February 2022 July 2022") +
facet_grid(.~campaign, scales = "free_x",space = "free_x" )+
geom_point(aes(y=montsouris_mm*20 ),color="#A3009F",size=2.5, position="dodge")+
geom_point(aes(y=melun_mm*20 ),color="#558C8C",size=2.5, position="dodge")+
geom_point(aes(y=fauville_mm*20 ),color="#E8DB7D",size=2.5, position="dodge")+
scale_y_continuous(expand = c(0,0),limits=c(0, 1000), breaks = seq(0, 1000, by = 100),
sec.axis = sec_axis(~./20, name = "Precipitation (mm)",
breaks = seq(0, 50, by = 10))) +
scale_x_date(date_breaks = "1 day", labels = date_format("%d"))+
ylab(expression(bold(paste(~C[mass]~ (µg ~L^{-1}))))) +
theme(axis.text.x=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.text.y=element_text(color="black", size=12, angle=0, vjust=0.5),
axis.ticks.x=element_blank(),
axis.title.x = element_text(size = 12,
color = "black",
face = "bold"),
strip.background = element_rect(color="white", fill="white", size=0.5,
linetype="solid"),
legend.text = element_text(color = "black",size = 12),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_rect(size = 0.5,colour="#D4CDCB",
fill="white" ,linetype = 'solid'),
legend.key.height= unit(0.2, 'cm'),
legend.key.width= unit(0.4, 'cm'))+
scale_fill_manual(name = "", values = MPcol, breaks = c("abs","acrylic", "acrylic paints", "alkyd","epoxy", "pa", "pan_acrylic fibre", "pe", "polyester", "pp", "ps", "pu", "pvac", "pvc", "sbr", "vinyl copolymer"),
labels=c("Acrylonitrile butadiene styrene (ABS)","Acrylic", "Acrylic paint", "Alkyd", "Epoxy", "Polyamide (PA)", "Pan acrylic fibre", "Polyethylene (PE)", "Polyester (PET)", "Polypropylene (PP)", "Polystyrene (PS)", "Polyurethane (PU)", "Polyvinyl acetate (PVAC)", "Poly vinyl chloride (PVC)", "Styrene butadiene rubber (SBR)", "Vinyl copolymere"))+
theme(legend.position = "bottom",
legend.background = element_rect(fill = "#FFFCFB", # Background
colour = 1),
legend.title = element_text(family = "sans",
color = "black",
size = 10,
face = 2)) +
theme(panel.grid.minor = element_line(color = "#D4CDCB",
size = 0.15,
linetype = 2))+
theme(strip.text.x = element_text(size=14, face="bold",
vjust = 2, color="black")) +
#geom_text( label = label1, vjust = -1, position = position_dodge(0.90), size = 3, hjust=-0.5)+
labs(title = "Microplastics",
subtitle = "Mass Concentrations by Polymer Types",
caption = "Still missing S4 repeated samples and M1 in Campaign D. S4 in Campaign C cumulated repetaed samples. MPs >300µm are excluded, also natural particles are excluded.",
tag = "Fig. 5-1") +
theme(plot.title = element_text(family = "serif", # Font family
face = "bold", # Font face
color = 1, # Font color
size = 16, # Font size
hjust = 1, # Horizontal adjustment
vjust = 1, # Vertical adjustment
angle = 0, # Font angle
lineheight = 1, # Line spacing
margin = margin(5, 0, 0, 0)), # Margins (t, r, b, l)
plot.subtitle = element_text(family = "serif",
hjust = 1, size=14), # Subtitle customization
plot.caption = element_text(hjust = 0.25, size =11,
family = "serif",face = "italic"), # Caption customization
plot.tag = element_text(face = "italic"), # Tag customization
plot.title.position = "plot", # Title and subtitle position ("plot" or "panel")
plot.caption.position = "panel", # Caption position ("plot" or "panel")
plot.tag.position = "top") # Tag position
I have this two dataframes
1) t1 (Var1(numeric), Var2(string), Freq (numeric))
2) pref.media (pref.media (numeric)
I have this separated graphs, but I want to print like two series in the same graph
1) Column chart, ok
column1 <- highchart() %>%
hc_add_series(t1$Freq, type = "column") %>%
hc_xAxis(categories = t1$Var1) %>%
hc_plotOptions(series = list(showInLegend = FALSE,dataLabels = list(enabled = TRUE, color = t1$Var1)))
2) Solid gauge chart (ok)
gauge1 <- highchart(width = 800, height = 600) %>%
hc_chart(type = "solidgauge",backgroundColor = "#F0F0F0",marginTop = 50) %>%
hc_title(text = "Preferencia",style = list(fontSize = "24px")) %>%
hc_tooltip(borderWidth = 0, backgroundColor = 'none',shadow = FALSE,style = list(fontSize = '16px')) %>%
hc_pane(startAngle = -90,endAngle = 90) %>%
hc_yAxis(min = 0,max = 11,lineWidth = 0,tickPositions = list(0,1,2,3,4,5,6,7,8,9,10,11)) %>%
hc_plotOptions(solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE, style = list(borderWidth = 3,backgroundColor = 'none',shadow = FALSE, fontSize = '16px',color="#888800")),linecap = 'round',stickyTracking = FALSE)) %>%
hc_add_series(name = "Preferencia",borderColor = "#000000",data = list(list(color = "#888800"),radius = "100%",innerRadius = "100%",y = round(pref.media[[1,1]],2)))
3) Mixing the charts (not ok, with errors)
highchart() %>%
hc_add_series(t1, "column", hcaes(x = Var1, y = Freq), name = "Preferencia") %>%
hc_add_series(pref.media, "solidgauge", hcaes(name = "Gauge", y = round(pref.media[[1,1]],2)), name = "Indicador") %>%
hc_plotOptions(
series = list(showInLegend = FALSE,pointFormat = "{point.y}%"),
column = list(colorByPoint = TRUE),
solidgauge = list(borderWidth = '34px',dataLabels = list(enabled = TRUE),linecap = 'round',stickyTracking = FALSE)) %>%
hc_pane(startAngle = -90,endAngle = 90) %>%
hc_yAxis(title = list(text = "Porcentaje de preferencia"),labels = list(format = "{value}%"), max = 100) %>%
hc_xAxis(categories = t1$Var1) %>%
hc_title(text = "Título") %>%
hc_subtitle(text = "Subtítulo")
I don't understand the sequence for mixing two series. I tried it with a J.Kunst's example in http://jkunst.com/highcharter/highcharts.html
Thanks
I am trying to create a mobile application about healthcare. I have to create a survey like application to screen the patients. Right now i have completed a part of the survey using radio button, the other part also look something like this(see picture below) but i want the radio button change to numeric textbox. My application look something like this:
Right now I want to convert the radio button to a numeric textbox.
The question is: how can i make minimum code changes and replace all the radio button to numeric textbox?
Here is my code for the radio buttons:
local radioGroup = display.newGroup()
if(ebasRating_Arr[i] == 0) then
radioButton_0 = widget.newSwitch {
left = 565,
style = "radio",
initialSwitchState = true,
id = tostring(i),
width = 60,
height = 60,
onPress = setEBASRating0
}
radioGroup:insert( radioButton_0 )
radioButton_1 = widget.newSwitch {
style = "radio",
id = tostring(i),
initialSwitchState = false,
width = 60,
height = 60,
onPress = setEBASRating1
}
radioGroup:insert( radioButton_1 )
elseif (ebasRating_Arr[i] == 1) then
radioButton_0 = widget.newSwitch {
left = 565,
style = "radio",
initialSwitchState = false,
id = tostring(i),
width = 60,
height = 60,
onPress = setEBASRating0
}
radioGroup:insert( radioButton_0 )
radioButton_1 = widget.newSwitch {
style = "radio",
id = tostring(i),
initialSwitchState = true,
width = 60,
height = 60,
onPress = setEBASRating1
}
radioGroup:insert( radioButton_1 )
else
radioButton_0 = widget.newSwitch {
left = 565,
style = "radio",
initialSwitchState = false,
id = tostring(i),
width = 60,
height = 60,
onPress = setEBASRating0
}
radioGroup:insert( radioButton_0 )
radioButton_1 = widget.newSwitch {
style = "radio",
id = tostring(i),
initialSwitchState = false,
width = 60,
height = 60,
onPress = setEBASRating1
}
radioGroup:insert( radioButton_1 )
end
radioButton_0.y = 150 + (i * 450)
radioButton_1.x = 18 + radioButton_0.x+radioButton_0.width
radioButton_1.y = 150 + (i * 450)
scrollView:insert( radioGroup )
end
I'm trying to add object to the ScrollView and this is what happen:
ERROR:Table expected. if this is a function call, you might have used '.' instead of ':
What is that?
code:
This code is works:
scrollView = widget.newScrollView
{ -- ScrollView settings
width = _W,
height = 1760,
horizontalScrollDisabled = true,
hideBackground = true,
friction = 0.988,
x = display.contentCenterX,
y = _H*0.55,
isBounceEnabled = false,
bottomPadding = 260,
hideScrollBar = true
}
for i = 1, #allballs do
Frames[i] = display.newImage( "Frame.png" )
Frames[i].height = 0.12*_H
Frames[i].width = 0.38*_W
Frames[i].ballImage = allballs[i].Image
Frames[i].Purchased = allballs[i].Purchased
Frames[i].Price = allballs[i].Price
Frames[i].Place = i
if (i%2==0) then
Frames[i].y=(i-1)*140
Frames[i].x = 0.27*_W
PositionY = (i-1)*140
PositionX = 0.27*_W
else
Frames[i].y=i*140
Frames[i].x = 0.73*_W
PositionY = i*140
PositionX = 0.73*_W
end
if (allballs[i].Purchased) then
balls[i] = display.newImage( allballs[i].Image )
balls[i].height = 0.15*_W
balls[i].width = 0.15*_W
balls[i].x = PositionX
balls[i].y = PositionY
else
local txtoptions =
{
text = allballs[i].Price,
x = PositionX+0.055*_W,
y = PositionY,
width = 0.23*_W,
font = native.systemFontBold,
fontSize = _W*0.1,
align = "left"
}
balls[i] = display.newText( txtoptions )
end
Frames[i]:setFillColor( 1, 1, 0.4 )
Frames[i]:addEventListener( "tap", sellectball )
scrollView:insert( Frames[i] )
scrollView:insert( balls[i] )
end
Everything works perfectly. But when I add this (between the ***):
for i = 1, #allballs do
Frames[i] = display.newImage( "Frame.png" )
Frames[i].height = 0.12*_H
Frames[i].width = 0.38*_W
Frames[i].ballImage = allballs[i].Image
Frames[i].Purchased = allballs[i].Purchased
Frames[i].Price = allballs[i].Price
Frames[i].Place = i
if (i%2==0) then
Frames[i].y=(i-1)*140
Frames[i].x = 0.27*_W
PositionY = (i-1)*140
PositionX = 0.27*_W
else
Frames[i].y=i*140
Frames[i].x = 0.73*_W
PositionY = i*140
PositionX = 0.73*_W
end
if (allballs[i].Purchased) then
balls[i] = display.newImage( allballs[i].Image )
balls[i].height = 0.15*_W
balls[i].width = 0.15*_W
balls[i].x = PositionX
balls[i].y = PositionY
else
local txtoptions =
{
text = allballs[i].Price,
x = PositionX+0.055*_W,
y = PositionY,
width = 0.23*_W,
font = native.systemFontBold,
fontSize = _W*0.1,
align = "left"
}
balls[i] = display.newText( txtoptions )
***** coin = display.newImage( "coin.png", PositionX-0.07*_W, PositionY)
coin.width = _W*0.05
coin.height = _H*0.05 *******
end
Frames[i]:setFillColor( 1, 1, 0.4 )
Frames[i]:addEventListener( "tap", sellectball )
scrollView:insert( Frames[i] )
scrollView:insert( balls[i] )
******* scrollView:insert( coin ) ********
end
It dosent work...
youre probably calling the method like object.method() instead of object:method()
difference is that : syntax uses automatically this as reference to caller object, with . syntax you have to type it explicitly as first parameter
The error always occurs for the reason like Andoloon pointed out.
but it doesn't seem to be in your ******* code. The problem for the ***** section might be that your 'coin' var is not a list, but it is defined and inserted in the loop. Try move it out of the loop and also remember to use local before the declearation.
I'm guessing that coin.png doesn't exist, or may not be an exact file name match (if you're doing this on a device). Look for a warning in your console log about missing images.
My code was working properly but after including widget library, the output got messy. Can you please tell me what is the problem?
--Include sqlite
local sqlite3 = require "sqlite3"
local widget = require "widget"
W=display.contentWidth
H=display.contentHeight
--Open library database file
local path = system.pathForFile("library", system.ResourceDirectory)
db = sqlite3.open( path )
title = display.newText("LIBRARY", 0, 0, nil, 30)
title.x = W/2 title.y=50
--Access records of book table and display them as nx2 grid with title and cover.
xOffset = 10
yOffset = 100
items = display.newGroup()
for row in db:nrows("SELECT * FROM book") do
local text = row.bookName
local img = display.newImageRect("img"..row.bookId..".jpg", 200, 200 )
local t = display.newText(text, 0, 0, nil, 25)
t.x = img.x
t.y = img.contentBounds.yMax+50
item = display.newGroup(img,t)
item.anchorChildren = true
items:insert(item)
items.anchorChildren = true
if(xOffset==10) then
item.anchorX, item.anchorY = 0,0
item.x = xOffset
xOffset = W-10
item.y = yOffset
--t:setTextColor(0,255,0)
else
item.anchorX, item.anchorY = 1,0
item.x = xOffset
xOffset= 10
item.y = yOffset
yOffset = yOffset+item.contentBounds.yMax-50
--t:setTextColor(255,0,0)
end
end
EDIT:
Before including widget:
After including widget:
Ok, clearly the objects in the items display group are what have been affected - see how the library text isn't in that group and it stays where it is.
Just after the x and y of the item is set, print out its position. Also print the position and dimensions of the group - this will give you a better understanding of where the positioning is being taken from, or where the origin (0,0) is at.
local i = 1;
for row in db:nrows("SELECT * FROM book") do
local text = row.bookName
local img = display.newImageRect("img"..row.bookId..".jpg", 200, 200 )
local t = display.newText(text, 0, 0, nil, 25)
t.x = img.x
t.y = img.contentBounds.yMax+50
item = display.newGroup(img,t)
item.anchorChildren = true
items:insert(item)
items.anchorChildren = true
if(xOffset==10) then
item.anchorX, item.anchorY = 0,0
item.x = xOffset
xOffset = W-10
item.y = yOffset
--t:setTextColor(0,255,0)
else
item.anchorX, item.anchorY = 1,0
item.x = xOffset
xOffset= 10
item.y = yOffset
yOffset = yOffset+item.contentBounds.yMax-50
--t:setTextColor(255,0,0)
end
print("--------")
print("Item "..tostring(i).." is at ("..tostring(item.x)..","..tostring(item.y)..")")
print("Item group now at ("..tostring(items.x)..","..tostring(items.y)..")")
print("Item group size = width:"..tostring(items.contentWidth)..", height:"..tostring(items.contentHeight))
end
print("--------")
Compare the output for with/without including widget and you should be able to find the problem.