Change widget background color in Kivy - widget

As the title suggests, I want to be able to change the background color of a gridlayout widget in Kivy
I'm using the following code:
from kivy.utils import get_color_from_hex
from kivy.graphics import Color, Rectangle
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.gridlayout import GridLayout
Builder.load_string('''
#:import utils kivy.utils
<BlueGrid>:
GridLayout:
canvas.before:
Color:
rgb: utils.get_color_from_hex("#39B3F2")
Rectangle:
size: self.size
pos: self.pos
rows: 1
cols: 2
pos_hint: {"top": 1, "left": 1}
size_hint: 1, 1
Label:
text: "First Label"
id: Label_1
Label:
text: "Second Label"
id: Label_2
''')
class BlueGrid(GridLayout):
pass
runTouchApp(BlueGrid())
I am expecting a blue gridlayout where each column is completing filled by one label. Instead, I get
the output below, where everything is concentrated in the bottom left corner:
output gridlayout
I have also tried running the "BlueGrid" class without the runTouchapp, with the same result:
class MyApp(App):
def build(self):
return BlueGrid()
if __name__ == "__main__":
MyApp().run()
print(kivy.__file__)
What am I missing? Why are the two labels and the Rectangle in the Gridlayout all positioned on top of each other?

Did you notice the warning:
[WARNING] <__main__.BlueGrid object at 0x7f2d2a414e18> have no cols or rows set, layout is not triggered.
That is because you have defined BlueGrid as an extension of GridLayout, but did not specify cols or rows in your kv for BlueGrid. You can correct that by just adding a cols specification:
<BlueGrid>:
cols: 1
But because BlueGrid is a GridLayout, do you really want another GridLayout inside it? Perhaps a better solution is:
#:import utils kivy.utils
<BlueGrid>:
canvas.before:
Color:
rgb: utils.get_color_from_hex("#39B3F2")
Rectangle:
size: self.size
pos: self.pos
rows: 1
cols: 2
pos_hint: {"top": 1, "left": 1}
size_hint: 1, 1
Label:
text: "First Label"
id: Label_1
Label:
text: "Second Label"
id: Label_2

The reason for this, is that the default size of the GridLayout is not enough to display both of the labels.
Also the root layout of your app might be better to be a FloatLayout or a BoxLayout, so it can occupy all of the window.
So one solution would be to set class BlueGrid(FloatLayout):
Another solution would be to keep it as a GridLayout but set its child GridLayout to a bigger size like this:
<BlueGrid>:
GridLayout:
size_hint: None, 1
width: 300

Related

Dash Unable to Center Table Horizontally

My code below reads in a small CSV file, defines the styles, and displays the output.
The H1 tag is centred, as expected.
But for some reason, my table is not centered horizontally.
What am I doing wrong?
df = pd.read_csv('myfile.csv')
app = Dash(__name__)
hdg_style = {'color': '#055d9c', 'text-align': 'center'}
tblh_style = {'backgroundColor': 'Linen', 'fontWeight': 'semi-bold'}
tbl_style = {'textAlign': 'center', 'maxWidth': '1000px', 'border': 'thin #055d9c solid'}
app.layout = html.Div([
html.H1(children="My Project", style=hdg_style),
dash_table.DataTable(
data = df.to_dict('records'),
columns = [{'id': c, 'name': c} for c in df.columns],
style_cell = {'textAlign': 'center'},
style_header = tblh_style,
style_table = tbl_style)])
if __name__ == '__main__':
app.run_server(debug=True)
I tried the CSS below to center the table horizontally, but it did not work.
style={'margin-left': 'auto', 'margin-right': 'auto'}
If you include the margin attributes in your tbl_style definition, it'll center the table - it did for me in my test case:
tbl_style = {'textAlign': 'center', 'maxWidth': '1000px', 'border': 'thin #055d9c solid', 'marginLeft': 'auto', 'marginRight': 'auto'}
I suspect your attempts with CSS modifications get caught up in the vagaries of Dash configuration of serving static css files.
app.layout = dbc.Container(). In that, you put multiple dbc.Row. Then, dbc.Col in them. In these columns you put objects (your datatable). You can then align anything you wish moving objects by defining size and offset. Check official dash bootstrap components doc for the detail

Remove spacing between bar in bar graph( react-chart-js)

issue that i am facing is, i have my bar graph made using react-chart-js. i want to remove space between the bar and center align the bar's . The bar's should have Thickness equal to 50
I try using dummy data ,that way i got the desired output but that is not the correct way of doing . Also I try using barPercentage , categoryPercentage option but didnt get the desired output
Link for CodeSandbox
I don't know if this actually works out of the box. There is nothing in the documentation about this use case either.
You could do it with ghost values to extend the chart in general.
This is not really a solution, but it may be an option.
const labels = ["","","January", "February", "March","",""];
export const data = {
labels,
datasets: [
{
label: "Dataset 1",
data: labels.map((elem, index) => {
if (index > 1 && index < 5)
return faker.datatype.number({ min: 0, max: 1000 })
}),
backgroundColor: "rgba(255, 99, 132, 0.5)",
barThickness: 50
}
]
};

Kivy - Label text = data (all) from mysql query

How to display on Label text, all data I've got from mysql query?
If I print "cont_number" in console displays everything fine (multiple rows) but in Kivy file only last one.
cursor.execute(query4, (jobstatus, user_id))
for rowen in cursor:
cont_number = rowen[4]
user_screen.cont_number = cont_number
print("====>>" + str(cont_number))
.kv
Label:
_id: ""
size_hint: 1.0, 0.15
font_size: 35
text: str(root.cont_number)
It could be problem with label and font size. If Label cant display all text it will show what it can, to check it try to use smaller font size or bigger label
Label:
_id: ""
font_size: 6
text: str(root.cont_number)

Drawing text at different heights in CesiumJS

I'm trying to draw some text at a particular height (so it's drawn at the same height as some other primitive) in Cesium. Text-wise, I can't seem to be able to draw anything but labels clamps to the ground (in the example below, the first little circle is at ground level). As such:
var entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(parseFloat(terrain[5]), parseFloat(terrain[4])),
ellipse : {
semiMinorAxis : 10000,
semiMajorAxis : 10000,
height : 1000,
fill : true,
outline: true,
material : Cesium.Color.fromCssColorString(someColour).withAlpha(0.5),
outlineWidth : 2
},
label: {
id: 'my label',
text: "Blabla",
scale: .5,
height: 1000
}
});
Is there any way to draw text at a specific height in Cesium?
The text height needs to be part of entity.position. Try adding it as a 3rd parameter to Cartesian3.fromDegrees on the 2nd line there.

Bar chart with two series of different date/values ranges

I am using jqplot through Primefaces and Have input to Bar Chart like this:
Series 1:
label: "Company 1"
data: {"01-05-2015": 10, "06-05-2015": 3}
Series 2:
label: "Company 2"
data: {"03-05-2015": 10, "06-05-2015": 3}
When I pass this data as BarChartModel, I got data wrongly drawn on the chart.
The data follows the first series, as the Series 2 is drawn after the Series 1 dates. I've to convert the data to be as follows in order to get the chart drawn fine:
Series 1:
label: "Company 1"
data: {"01-05-2015": 10, *"03-05-2015": 0*, "06-05-2015": 3}
Series 2:
label: "Company 2"
data: { *"01-05-2015": 0* , "03-05-2015": 10, "06-05-2015": 3}
Notice the data items between * and *.
Any advice here? (if using DateAxis helps?)
I had the same problem with LinearChartModel when I has not using DateAxis.
As a workaround, I filled my series with all possible data and then reordered the list. Urg!
Should work with BarChartModel too.
Using DateAxis you just need to add your date axis with the timestamp, like this:
serie.set(new Date().getTime(), new Double(123));
or this
serie.set("2015-09-08", new Double(123));
Put the DateAxis in your LineChartModel like this:
DateAxis axis = new DateAxis("Data da inspeção");
linearModel.setZoom(true);
linearModel.getAxes().put(AxisType.X, axis);
linearModel.setExtender("linhaSetor");
And format your date in the extender.js:
function linhaSetor() {
this.cfg.axes.xaxis.tickOptions = {
show : true,
angle : 45,
formatString : '%d/%m/%y %Hh'
};
}
You don't even need to put the data in order.