Bonjour,
Voila je rencontre un petit problème avec mon code.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hachemon's buttons</title>
<meta name="description" content="hachemon's buttons">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/main.css">
<script src="/js/main.js"></script>
</head>
<body>
<div>
<span id="responseBox"></span>
<form method="post" action="action.php">
arg1:
<input type="text" id ="of" name="of"><br>
arg2:
<input type="text" id="mat1" name="mat1"><br>
arg3:
<input type="text" id="mat2" name="mat2"><br>
arg4:
<input type="text" id="mat3" name="mat3"><br>
<button type="button" id="actionBtn">valider</button>
</form>
</div>
</body>
</html>
<?php
$responseObject = new stdClass();
$responseObject->success = 0;
$responseObject->msg = '';
$arg1 = $_POST['of'];
$arg2 = $_POST['mat1'];
$arg3 = $_POST['mat2'];
$arg4 = $_POST['mat3'];
exec("python /py/test1.py '". $arg1."' '".$arg2."' '". $arg3."' '". $arg4 ."' 2>&1",$output);
if (count($output) > 0 && strpos($output[0], 'Errno') !== false) {
$responseObject->msg = $output[0];
} else {
$responseObject->success = 1;
}
$jsonResponseObject = json_encode($responseObject);
echo $jsonResponseObject;
exit;
?>
Décrivez ici votre code ou ce que vous cherchez à faire
/ AJAX without jQuery helper functions /
var ajax = {};
ajax.x = function() {
if (typeof XMLHttpRequest !== 'undefined') {
return new XMLHttpRequest();
}
var versions = [
'MSXML2.XmlHttp.5.0',
'MSXML2.XmlHttp.4.0',
'MSXML2.XmlHttp.3.0',
'MSXML2.XmlHttp.2.0',
'Microsoft.XmlHttp'
];
var xhr;
for(var i = 0; i < versions.length; i++) {
try {
xhr = new ActiveXObject(versions[i]);
break;
} catch (e) {
}
}
return xhr;
};
ajax.send = function(url, callback, method, data, sync) {
var x = ajax.x();
x.open(method, url, sync);
x.onreadystatechange = function() {
if (x.readyState == 4) {
callback(x.responseText)
}
};
if (method == 'POST') {
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
}
x.send(data)
};
ajax.get = function(url, data, callback, sync) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url + '?' + query.join('&'), callback, 'GET', null, sync)
};
ajax.post = function(url, data, callback, sync) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
}
ajax.send(url, callback, 'POST', query.join('&'), sync)
};
/ document.ready without jQuery /
var doc = {};
doc.domReady = function (callback) {
// Mozilla, Opera and Webkit
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', callback, false);
// If IE event model is used
} else if (document.attachEvent) {
document.attachEvent('onreadystatechange', function() {
if (document.readyState === 'complete') {
callback();
}
});
// A fallback to window.onload, that will always work
} else {
var oldOnload = window.onload;
window.onload = function () {
oldOnload && oldOnload();
callback();
}
}
};
/ main application- most of your code will likely go here /
var app = {};
/ init /
app.init = function () {
console.log('app initilialized!');
responseBox = document.getElementById('responseBox');
responseCallback = function (response){
responseObj = JSON.parse(response);
console.log(responseObj);
if (responseObj.success !== 1) {
responseBox.innerHTML = responseObj.msg;
}
}
document.getElementById('actionBtn').onclick = function (event) {
event.preventDefault();
console.log('open button clicked');
ajax.post('/php/action.php', {}, responseCallback, false);
}
};
doc.domReady(app.init);
from PyQt4.QtGui import *
from PyQt4.QtCore import # inclut QTimer..
from appl import # fichier obtenu à partir QtDesigner et pyuic4
import os,sys
class myApp(QWidget, Ui_Form): # la classe reçoit le Qwidget principal ET la classe définie dans test.py obtenu avec pyuic4
def __init__(self, parent=None):
QWidget.__init__(self) # initialise le Qwidget principal
self.setupUi(parent) # Obligatoire
#Ici, personnalisez vos widgets si nécessaire
self.label.setText(sys.argv[1] +" " + sys.argv[2]+" "+ sys.argv[3]+" "+ sys.argv[4])
def message(arg1,arg2,arg3,arg4):
print arg1
print arg2
print arg3
print arg4
def main(args):
a=QApplication(args) # crée l'objet application
a.setStyle(QtGui.QStyleFactory.create("plastique"))
f=QWidget() # crée le QWidget racine
c=myApp(f) # appelle la classe contenant le code de l'application
f.showFullScreen()
f.show() # affiche la fenêtre QWidget
# Raccourcie <ctrl>+<Q> -> quit (juste pour le dev ...)
if len(sys.argv) > 1:
message(sys.argv[1] ,sys.argv[2],sys.argv[3],sys.argv[4])
else:
print 'No argument'
f.actionExit = QAction(('E&xit'), f)
f.actionExit.setShortcut(QKeySequence("Ctrl+Q"))
f.addAction(f.actionExit)
f.actionExit.triggered.connect(f.close)
r=a.exec_() # lance l'exécution de l'application
return r
if name=="main": # pour rendre le code exécutable
main(sys.argv) # appelle la fonction main
Entourez votre code pour bien le mettre en forme
lorsque je clique sur le bouton il va executer la commande exec(python .py) et afficher les valeurs des inputs dans la fenetre Pyqt
pour mon cas, lorsque je click , rien a affiché !!