I am trying to create a Kivy popup for general use
From my code below you may see that I am a beginner
I am trying to understand the KIVY language, ids, kivy properties, how to apply rules and the interaction between the KV and Python files
I will appreciate your answers and comments, that may teach me
Ho do I dismiss the popup?
Thank you for your aid
===================================================================
My KV file
'''
<MB_Body>
id: id_body
size_hint: 0.9, 0.9
Label:
id: id_label
size_hint: (0.6, 0.2)
pos_hint: {'x': 0.2, 'top': 0.9}
text: 'Sibs text'
Button:
text: 'Dismiss'
size_hint: 0.8, 0.2
pos_hint: {'x': 0.1, 'y': 0.1}
on_release: root.dismiss_msgbox()
id: pop
auto_dismiss: False
size_hint: 0.6, 0.4
title: 'si8bs title'
canvas.before:
Color:
rgba: 0, 1, 0, 1
Rectangle:
size: self.size
pos: self.pos
MB_Body:
'''
##########################################################
My PY file:
'''
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty, ObjectProperty
class MsgBox(Popup):
pass
class MB_Body(FloatLayout):
def dismiss_msgbox(self):
print('In Finis')
print(App.get_running_app())
dismiss() #---> This line is my problem. How do I dismiss the popup???????????
def showMsg(_title, _msg):
mb = MsgBox()
mb.title = _title
mb.content.ids.id_label.text = _msg
mypopup = mb
print(_msg)
mb.open()
'''
Related
When i was doing an interface which dynamically create buttons after an upload of multiple pictures using dcc.Upload, i noticed only the last file treated have the buttons active. The other files have the interface layout correctly adjoined, but none of the callback works.
So i would like to know how to properly handle having multiple pictures uploaded using dcc.Upload so i can interact with all pictures.
Here is my code (simplified) to reproduce the problem (simply upload 2 pictures and try to click on the buttons) :
from dash import Dash, html, dcc
from dash.dependencies import Input, Output, State
import dash_bootstrap_components as dbc
#CSS
external_stylesheets=[dbc.themes.BOOTSTRAP]
#app
app = Dash(__name__,external_stylesheets=external_stylesheets,suppress_callback_exceptions=True)
#layout
app.layout = html.Div([
dcc.Upload(
id='upload-image',
children=html.Div([
'Drag and Drop or ',
html.A('Select Files')
]),
style={
'width': '70%',
'height': '60px',
'justify':'center',
'text-align':'center',
'lineHeight': '60px',
'borderWidth': '1px',
'borderStyle': 'dashed',
'borderRadius': '500px',
'textAlign': 'center',
'margin': '10px'
},
# Allow multiple files to be uploaded
multiple=True
),
html.Div(id='output-image-upload'),
])
#callback upload button
#app.callback(Output('output-image-upload', 'children'),
Input('upload-image', 'contents'),
State('upload-image', 'filename'),
State('upload-image', 'last_modified'))
def update_output(list_of_contents, list_of_names, list_of_dates):
if list_of_contents is not None:
children = [
parse_contents(c, n, d) for c, n, d in
zip(list_of_contents, list_of_names, list_of_dates)]
return children
def parse_contents(contents,unused,unused2):
import random
result = random.randrange(1000)
return html.Div([
dcc.Store(id='store-picture',data=result),
dbc.Row([
dbc.Col(
html.Img(
src=contents,
style={
'margin-left':'auto',
'margin-right':'0px',
'width':'40%',
'padding-left':'20px'}),
),
dbc.Col(
html.Div(result,
style={
'font-size':'40px',
'padding-top':'10px',
'font-weight':'bold',
'font-family':'courier',
}
)
),
dbc.Col([
dbc.Row(html.Div('Is the prediction correct?')),
dbc.Row([
dbc.Col(
html.Button('Yes',id='button-pred-yes',n_clicks=0)
),
dbc.Col(
html.Button('No',id='button-pred-no',n_clicks=0)
)
]),
dbc.Row(
html.Div(id='div-prediction-result')
)
])
])
])
#app.callback(
Output('div-prediction-result','children'),
[Input('button-pred-yes','n_clicks'),Input('button-pred-no','n_clicks')],
[State('store-picture','data')]
)
def confirm_prediction(bpy,bpn,data):
prediction = data
if bpy:
return prediction
elif bpn:
return prediction
#--------- LAUNCHER ------------
if __name__ == '__main__':
app.run_server(debug=True)
What confuses me is that there's multiple buttons appearing, but only the last one works.
Good afternoon, I have a great difficulty, which seems easy to solve.
The question is as follows:
I have my TextInput created this way, in my :
KV = """
WindowManager:
ScreenLogin:
ScreenPaginaInicial:
PaginaEntradas:
id: data_scr
ScreenInicioProducao:
PaginaMovInterna:
PaginaMovExterna:
PaginaEditarArtigoOriginalInterna:
PaginaEditarArtigoBob1Interna:
PaginaEditarArtigoBob2Interna:
PaginaEditarArtigoBob3Interna:
PaginaEditarArtigoOriginalExterna:
PaginaEditarArtigoBob1Externa:
PaginaEditarArtigoBob2Externa:
PaginaEditarArtigoBob3Externa:
<ScreenLogin>:
name: "ScreenLogin"
FloatLayout:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
Image:
size_hint: .3, .3
pos_hint: {"center_x": .5, "center_y": .75}
source: 'G:\O meu disco\Gestao_Stocks\logo.png'
GridLayout:
cols: 1
spacing: 5
size_hint: .7, .37
pos_hint: {"center_x": .5, "center_y": .3}
Label:
text: "Utilizador"
size_hint_x: .3
text_size: self.size
halign: 'center'
valign: 'middle'
color: 0,0,0,1
allow_copy: True
TextInput:
id: utilizador
multiline: False
halign: 'center'
focus: True
size_hint_x: 5
"""
class PLASbritos(MDApp):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.data_tables = None
def build(self):
return Builder.load_string(KV)
def login(self):
utilizador = self.root.ids.utilizador.text
print(utilizador)
password = '1'
#Implemesta regras para acesso. Exemplo:
if utilizador == '1' and password == '1':
.........................................
.........................................
........................................
else:
........................................
I would like to access the utilizador through the textinput(id: utilizador)
error:
AttributeError: 'super' object has no attribute '__getattr__'
I've already looked for all the information on google, I've seen videos on youtube, and I can't find anything. What seemed to be the easiest, is extremely difficult, if someone can help me, I am extremely grateful.
I thank you in advance for any attention you can give me.
I've already looked for all the information on google, inclusive in stackoverflow similiar problems, I've seen videos on youtube, and I can't find anything. What seemed to be the easiest, is extremely difficult, if someone can help me, I am extremely grateful.
I am trying to set the height of a popup in kivy so that it varies to fit its content. However, I cannot use height: self.minimum_height, as Popup has no attribute minimum_height.
I have also tried setting the height of the popup equal to the height of the content, but the result is far from ideal (and especially wouldn't be consistent across different screen sizes).
This is my code:
#:set row_height '35sp'
<ConfirmPopup#Popup>:
box: box
message: message
noButton: noButton
yesButton: yesButton
size_hint: .8, None
height: box.height + sp(80)
auto_dismiss: False
StackLayout:
id: box
orientation: 'lr-tb'
size_hint: 1, None
height: self.minimum_height
padding: main_padding
Label:
id: message
text: "" # This text is updated later from the py script
text_size: self.width, None
size_hint: None, None
width: self.parent.width
height: self.texture_size[1]
Label: # just empty space
size_hint: .15, None
Button:
id: noButton
size_hint: .3, None
height: row_height
Label:
size_hint: .1, None
Button:
id: yesButton
size_hint: .3, None
height: row_height
Label:
size_hint: .15, None
I spent the last few days playing with react-native-html-to-pdf (https://github.com/christopherdro/react-native-html-to-pdf ), react-native-mail (by chirag04) and react-native-view-pdf (by cnjon)
There is another version of react-native-mail by parkerdan that I have yet to try, but the chrirag04's version basically corrupted all my projects and was a pain to uninstall.
react-native-html-to-pdf doesn't seem to generate any error, and I can't seem have access to the pdf generated. here a snippet of the code I am running:
import RNHTMLtoPDF from 'react-native-html-to-pdf';
import PDFView from 'react-native-pdf-view';
...
createPDF() {
var options = {
html: '<h1>PDF TEST</h1>', // HTML String
// ****************** OPTIONS BELOW WILL NOT WORK ON ANDROID **************
fileName: 'test', /* Optional: Custom Filename excluded extention
Default: Randomly generated
*/
directory: 'docs', /* Optional: 'docs' will save the file in the `Documents`
Default: Temp directory
*/
height: 800, /* Optional: 800 sets the height of the DOCUMENT that will be produced
Default: 612
*/
width: 1056, /* Optional: 1056 sets the width of the DOCUMENT that will produced
Default: 792
*/
padding: 24, /* Optional: 24 is the # of pixels between the outer paper edge and
corresponding content edge. Example: width of 1056 - 2*padding
=> content width of 1008
Default: 10
*/
};
RNHTMLtoPDF.convert(options).then((filePath) => {
AlertIOS.alert(
'creat pdf',
'filePath=' + filePath
);
return (
<PDFView ref={(pdf)=>{this.pdfView = pdf;}}
src={filePath}
onLoadComplete = {(pageCount)=>{
this.pdfView.setNativeProps({
zoom: 1.5
});
}}
/>
)
});
};
and later in the code I call it with:
<TouchableHighlight onPress={this.createPDF} style={styles.button}>
<Text>create pdf </Text>
</TouchableHighlight>
I get the AlertIOS, with something that looks like a valid filepath (any hint to check the path is correct, let me know)
But that's it, I don't seem to find the test.pdf document anywhere.
Can anyone tell what I am doing wrong?
Many Thanks,
Cheufte
I think the file path is document directory you can go through the file path by first clicking the windows option in xcode after that find devices option upon clicking device option all the information of your device will appear then select the application and see it's container and you will find your pdf file.
var localpath= RNFS.DocumentDirectoryPath + filePath
<PDFView ref={(pdf)=>{this.pdfView = pdf;}}
path={localpath}
onLoadComplete = {(pageCount)=>{
this.pdfView.setNativeProps({
zoom: 1.5
});
}}
/>
write path in place of src because it is deprecated.
import React, { Component } from 'react';
import {
AlertIOS,
AppRegistry,
StyleSheet,
Text,
TouchableHighlight,
View
} from 'react-native';
import RNHTMLtoPDF from 'react-native-html-to-pdf';
export default class testApp extends Component {
createPDF() {
var options2 = {
html: '<h1>PDF TEST</h1>', // HTML String
// ****************** OPTIONS BELOW WILL NOT WORK ON ANDROID **************
fileName: 'test2', /* Optional: Custom Filename excluded extension
Default: Randomly generated
*/
directory: 'docs', /* Optional: 'docs' will save the file in the `Documents`
Default: Temp directory */
base64: true ,
height: 800,
width: 1056, /* Optional: 1056 sets the width of the DOCUMENT that will produced
Default: 792
*/
padding: 24, /* Optional: 24 is the # of pixels between the outer paper edge and
corresponding content edge. Example: width of 1056 - 2*padding
=> content width of 1008
Default: 10
*/
};
RNHTMLtoPDF.convert(options2).then((data2) => {
console.log(data2.filePath);
console.log(data2.base64);
AlertIOS.alert(
'options2 filename' + options2.fileName,
'data2 filePath=' + data2.filePath
);
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to testApp
</Text>
<TouchableHighlight onPress={this.createPDF}>
<Text>Create PDF</Text>
</TouchableHighlight>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('testApp', () => testApp);
Im currently using ExtJs5 MVVM architecture and I require "sencha-chart" than "ext-chart" on the app.json file, Charts works fine but adding tooltip on the bar series im using doesn't work. No error logs.
I also check their example on sencha chart kitchensink (which chart tooltip is working) found out that they require "ext-chart" for that. My code for bar series with tooltip config:
series: [{
type: 'bar',
xField: 'name',
yField: ['data1'],
style: {
opacity: 0.80
},
highlight: {
fill: '#000',
'stroke-width': 20,
stroke: '#fff'
},
tips: {
trackMouse: true,
style: 'background: #FFF',
height: 20,
renderer: function(storeItem, item) {
this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + '%');
}
}
}]
Is there something wrong with my codes?
Thanks
Your code needs one small change "tips" for EXTjs 5 becomes "tooltip."
tooltip: {
trackMouse: true,
style: 'background: #FFF',
height: 20,
renderer: function(storeItem, item) {
this.setTitle(storeItem.get('name') + ': ' + storeItem.get('data1') + '%');
}
}
However, there are a lot of bugs with the EXTjs 5 charts. I had this same issue, and submitted a bug to Sencha:
http://www.sencha.com/forum/showthread.php?289313-Sencha-EXTjs-5-Charts-Broken-Tooltips
tooltip: {
trackMouse: true,
style: 'background: #FFF',
height: 20,
renderer: function(storeItem, item) {
this.setHtml(storeItem.get('name') + ': ' + storeItem.get('data1') + '%');
}
}
I used tooltip inplace of tips and this.setHtml() in place of this.setTitle() ,and it worked for me.