Thread: [Pykafe-commits] SF.net SVN: pykafe: [59] trunk/pykafe/client
Status: Pre-Alpha
Brought to you by:
jnmbk
|
From: <jn...@us...> - 2007-06-01 12:07:41
|
Revision: 59
http://pykafe.svn.sourceforge.net/pykafe/?rev=59&view=rev
Author: jnmbk
Date: 2007-06-01 05:07:43 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
added getNetworkBytes function
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/session.py
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-02 09:55:36
|
Revision: 65
http://pykafe.svn.sourceforge.net/pykafe/?rev=65&view=rev
Author: jnmbk
Date: 2007-06-02 02:55:38 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
changes in session and config, now it keeps trying until connected to a server
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/config.py
trunk/pykafe/client/login.py
trunk/pykafe/client/session.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-02 09:54:44 UTC (rev 64)
+++ trunk/pykafe/client/client.py 2007-06-02 09:55:38 UTC (rev 65)
@@ -15,23 +15,40 @@
from PyQt4 import QtNetwork, QtCore
from config import PykafeConfiguration
from session import ClientSession
-import base64, sys, os, socket
+import base64, sys, os, socket, time
import locale, gettext
locale.setlocale(locale.LC_ALL, "C")
_ = gettext.translation("pyKafe_client", fallback=True).ugettext
+config = PykafeConfiguration()
+
+class SenderThread(QtCore.QThread):
+ def __init__(self, data):
+ QtCore.QThread.__init__(self)
+ self.data = data
+ def run(self):
+ while not sendDataToServer(self.data):
+ self.emit(QtCore.SIGNAL("connectionError"))
+ time.sleep(10)
+ self.emit(QtCore.SIGNAL("messageSent"))
+
def sendDataToServer(data):
tcpSocket = QtNetwork.QTcpSocket()
- tcpSocket.connectToHost(QtNetwork.QHostAddress(PykafeConfiguration().network.serverIP), PykafeConfiguration().network.port)
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(config.network_serverIP), config.network_port)
tcpSocket.waitForConnected(-1)
- tcpSocket.write(base64.encodestring(data))
- tcpSocket.waitForBytesWritten()
- print "sent to server:", data
+ print "trying to send:", data
+ if tcpSocket.write(base64.encodestring(data)) == -1:
+ print "failed"
+ return False
+ else:
+ print "success"
+ tcpSocket.waitForBytesWritten()
+ return True
def sendDataToUi(data):
tcpSocket = QtNetwork.QTcpSocket()
- tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), PykafeConfiguration().network.localPort)
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
tcpSocket.waitForConnected(-1)
tcpSocket.write(base64.encodestring(data))
tcpSocket.waitForBytesWritten()
@@ -95,12 +112,11 @@
self.client.session.state = ClientSession.loggedIn
sendDataToUi("005")
elif data[:3] == "007":
- self.emit(QtCore.SIGNAL("filter"), data[4:])
iptablesFile = "*filter\n:INPUT ACCEPT [94:7144]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [177:10428]\n"
for site in data[3:].split('\n'):
ip = getSiteIP(site)
if ip:
- iptablesFile += "-A INPUT -s %s -j DROP\n" % site
+ iptablesFile += "-A INPUT -s %s -j DROP\n" % ip
iptablesFile += "COMMIT\n"
file = open("/etc/pyKafe/iptables.conf", "w")
file.write(iptablesFile)
@@ -108,11 +124,17 @@
os.system("iptables-restore < /etc/pyKafe/iptables.conf")
elif data[:3] == "010":
os.system("init 0")
- self.exit()
+ elif data[:3] == "016":
+ for c, value in map(lambda x,y:(x,y), ("price_fixedprice", "price_fixedpriceminutes", "price_onehourprice", "price_rounding"), data[3:].split("|")):
+ config.set(c, value)
+ self.terminate()
def readUi(self):
data = base64.decodestring(self.tcpSocket.readAll())
print "received from user:", data
+ if self.client.session.state == ClientSession.notConnected:
+ sendDataToUi("014")
+ return
if data[:3] == "000":
if self.client.session.state == ClientSession.working:
sendDataToServer("000")
@@ -123,7 +145,7 @@
if self.client.session.state == ClientSession.working:
sendDataToServer(data)
elif data[:3] == "004":
- if self.client.session.state == ClientSession.notConnected:
+ if self.client.session.state == ClientSession.notReady:
sendDataToServer("004")
self.client.session.state = ClientSession.working
else:
@@ -139,18 +161,19 @@
class PykafeClient(QtNetwork.QTcpServer):
def __init__(self):
QtNetwork.QTcpServer.__init__(self)
- self.config = PykafeConfiguration()
self.session = ClientSession()
- self.threads = []
- self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any), self.config.network.port)
- print "listening?", self.isListening()
- print "listening to:", QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any).toString() ,self.config.network.port
+ if not self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.Any), config.network_port):
+ print "cant bind, exitting"
+ sys.exit()
+ thread = SenderThread("011")
+ QtCore.QObject.connect(thread, QtCore.SIGNAL("messageSent"), self.initialConnection)
+ self.threads = [thread]
+ print "trying to connect to server"
def incomingConnection(self, socketDescriptor):
- print "called incomingConnection"
thread = ListenerThread(socketDescriptor, self)
thread.start()
- QtCore.QObject.connect(thread,QtCore.SIGNAL("filter"),self.filterCame)
self.threads.append(thread)
print "We have " + str(len(self.threads)) + " thread(s)"
- def filterCame(self, text):
- print "filtering:", text
+ def initialConnection(self):
+ print "connected to server"
+ self.session.setState(ClientSession.notReady)
Modified: trunk/pykafe/client/config.py
===================================================================
--- trunk/pykafe/client/config.py 2007-06-02 09:54:44 UTC (rev 64)
+++ trunk/pykafe/client/config.py 2007-06-02 09:55:38 UTC (rev 65)
@@ -12,7 +12,9 @@
#TODO: Read config from config file
class PykafeConfiguration:
- class network:
- serverIP = "192.168.2.2"
- port = 23105
- localPort = 23106
\ No newline at end of file
+ network_serverIP = "192.168.2.2"
+ network_port = 23105
+ network_localPort = 23106
+
+ def set(self, config, value):
+ setattr(self, config, value)
Modified: trunk/pykafe/client/login.py
===================================================================
--- trunk/pykafe/client/login.py 2007-06-02 09:54:44 UTC (rev 64)
+++ trunk/pykafe/client/login.py 2007-06-02 09:55:38 UTC (rev 65)
@@ -10,7 +10,7 @@
# Please read the COPYING file.
#
-import base64, os, sys
+import base64, os, sys, sha, time
from PyQt4 import QtCore, QtGui, QtNetwork
from config import PykafeConfiguration
@@ -18,22 +18,28 @@
locale.setlocale(locale.LC_ALL, "C")
_ = gettext.translation("pyKafe_client", fallback=True).ugettext
+config = PykafeConfiguration()
+
class SenderThread(QtCore.QThread):
- def __init__(self, parent, data):
+ def __init__(self, parent, data, retry = False):
QtCore.QThread.__init__(self, parent)
self.data = data
+ self.retry = retry
def run(self):
tcpSocket = QtNetwork.QTcpSocket()
- tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), PykafeConfiguration().network.port)
- print "connecting to:", QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost).toString(), PykafeConfiguration().network.port
- if not tcpSocket.waitForConnected(-1):
- print "error:", tcpSocket.errorString(), "sending exit signal"
- self.emit(QtCore.SIGNAL("exit()"))
- else:
- tcpSocket.write(base64.encodestring(self.data))
- tcpSocket.waitForBytesWritten()
- print "sent:", self.data
- tcpSocket.disconnectFromHost()
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
+ while not tcpSocket.waitForConnected(-1) and self.retry:
+ self.emit(QtCore.SIGNAL("connectionError()"))
+ print "trying to reconnect in 5 seconds"
+ time.sleep(5)
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
+ if tcpSocket.write(base64.encodestring(self.data)) == -1:
+ print "couldn't send:", self.data
+ self.emit(QtCore.SIGNAL("connectionError()"))
+ self.terminate()
+ tcpSocket.waitForBytesWritten()
+ print "sent:", self.data
+ tcpSocket.disconnectFromHost()
class ListenerThread(QtCore.QThread):
def __init__(self, parent, socketDescriptor):
@@ -42,7 +48,8 @@
def run(self):
self.tcpSocket = QtNetwork.QTcpSocket()
self.tcpSocket.setSocketDescriptor(self.socketDescriptor)
- self.tcpSocket.waitForReadyRead()
+ self.tcpSocket.isReadable()
+ self.tcpSocket.waitForReadyRead(-1)
data = base64.decodestring(self.tcpSocket.readAll())
print "received:", data
if data[:3] == "001":
@@ -60,6 +67,8 @@
elif data[:3] == "005":
os.system("pyKafeclient&")
self.emit(QtCore.SIGNAL("close"))
+ elif data[:3] == "014":
+ self.emit(QtCore.SIGNAL("message"), _("Can't connect to server"))
self.tcpSocket.disconnectFromHost()
self.exec_()
@@ -67,10 +76,13 @@
def __init__(self, parent, ui):
QtNetwork.QTcpServer.__init__(self, parent)
self.ui = ui
- self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), PykafeConfiguration().network.localPort)
- print "listening localhost on port:", PykafeConfiguration().network.localPort
- thread = SenderThread(self.parent(), "004")
- QtCore.QObject.connect(thread, QtCore.SIGNAL("exit()"), parent.close)
+ listening = self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
+ if not listening:
+ print "Can't bind port %d" % config.network_localPort
+ sys.exit()
+ print "listening localhost on port:", config.network_localPort
+ thread = SenderThread(self.parent(), "004", retry = True)
+ QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
self.threads = [thread]
def incomingConnection(self, socketDescriptor):
@@ -81,13 +93,17 @@
self.threads.append(thread)
print "login has %d threads" % len(self.threads)
def login(self):
- thread = SenderThread(self.parent(), "002" + unicode(self.ui.username.text()) + "|" + unicode(self.ui.password.text()))
+ thread = SenderThread(self.parent(), "002" + unicode(self.ui.username.text()) + "|" + sha.new(unicode(self.ui.password.text())).hexdigest())
+ QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
self.threads.append(thread)
def request(self):
thread = SenderThread(self.parent(), "000")
+ QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
self.threads.append(thread)
+ def connectionError(self):
+ self.ui.statusbar.showMessage(_("Can't connect to local daemon, please contact cashier"))
class Ui_LoginWindow(object):
def setupUi(self, MainWindow):
@@ -165,7 +181,7 @@
MainWindow.setTabOrder(self.password,self.loginButton)
def retranslateUi(self, LoginWindow):
- LoginWindow.setWindowTitle(_("pyKafe"))
+ LoginWindow.setWindowTitle("pyKafe")
self.textLabel1.setText(_("Username:"))
self.loginButton.setText(_("Login"))
self.textLabel2.setText(_("Password:"))
Modified: trunk/pykafe/client/session.py
===================================================================
--- trunk/pykafe/client/session.py 2007-06-02 09:54:44 UTC (rev 64)
+++ trunk/pykafe/client/session.py 2007-06-02 09:55:38 UTC (rev 65)
@@ -16,12 +16,13 @@
class ClientSession:
"""class for managing client sessions"""
- notAvailable, notConnected, working, loggedIn, requestedOpening = range(5)
+ notConnected, notReady, working, loggedIn, requestedOpening, waitingMoney = range(6)
def __init__(self):
self.state = 0
self.user = None
self.settings = None
self.startTime = None
+ self.endTime = None
self.orders = []
def isReachable(self):
@@ -39,16 +40,20 @@
return True
else:
return False
- def getCurrentState(self):
+ def toString(self):
"""returns current state as a string"""
- if self.state == self.notAvailable:
- return _("N/A")
+ if self.state == self.notConnected:
+ return _("Not Connected")
elif self.state == self.working:
return _("Ready")
elif self.state == self.loggedIn:
return _("Logged In")
elif self.state == self.requestedOpening:
return _("Requested Opening")
+ elif self.state == self.waitingMoney:
+ return _("Waiting for Payment")
+ elif self.state == self.notReady:
+ return _("Not ready")
def setState(self, stateNumber):
- self.state = stateNumber
\ No newline at end of file
+ self.state = stateNumber
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-02 13:44:46
|
Revision: 67
http://pykafe.svn.sourceforge.net/pykafe/?rev=67&view=rev
Author: jnmbk
Date: 2007-06-02 06:44:46 -0700 (Sat, 02 Jun 2007)
Log Message:
-----------
We'll calculate pricing things in root side
Currency things are handled as in python 2.5 now
Modified Paths:
--------------
trunk/pykafe/client/client.py
Added Paths:
-----------
trunk/pykafe/client/currencyformat.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-02 09:56:16 UTC (rev 66)
+++ trunk/pykafe/client/client.py 2007-06-02 13:44:46 UTC (rev 67)
@@ -15,6 +15,7 @@
from PyQt4 import QtNetwork, QtCore
from config import PykafeConfiguration
from session import ClientSession
+from currencyformat import currency
import base64, sys, os, socket, time
import locale, gettext
@@ -156,6 +157,27 @@
print "gdg"
sendDataToServer(data)
os.system("service kdebase stop && sleep 3 && service kdebase start")
+ elif data[:3] == "017":
+ currentTime = QtCore.QDateTime.currentDateTime()
+ usedTime = self.client.session.startTime.secsTo(currentTime)
+ price = (usedTime/600)*(config.price_onehourprice/6.0)
+ remainingTime = QtCore.QDateTime()
+ if self.endTime.isValid():
+ remainingTime.setTime_t(currentTime.secsTo(self.client.session.endTime))
+ else:
+ remainingTime.setTime_t(0)
+ temp = usedTime
+ usedTime = QtCore.QDateTime()
+ usedTime.setTime_t(temp)
+ text = self.startTime.time().toString("hh.mm") + "\n" +\
+ remainingTime.toUTC().time().toString("hh.mm") + "\n" +\
+ usedTime.toUTC().time().toString("hh.mm") + "|"
+ if float(config.price_fixedprice) < price:
+ text += currency(price)
+ else:
+ text += currency(float(config.price_fixedprice))
+ self.tcpSocket.write(text)
+ self.tcpSocket.waitForBytesWritten()
self.exit()
class PykafeClient(QtNetwork.QTcpServer):
Added: trunk/pykafe/client/currencyformat.py
===================================================================
--- trunk/pykafe/client/currencyformat.py (rev 0)
+++ trunk/pykafe/client/currencyformat.py 2007-06-02 13:44:46 UTC (rev 67)
@@ -0,0 +1,93 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007, pyKafe Development Team
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# Please read the COPYING file.
+#
+
+import locale
+
+#taken from python 2.5 sources
+#TODO: Remove these when Python 2.5 is widely available
+def format(percent, value, grouping=False, monetary=False, *additional):
+ """Returns the locale-aware substitution of a %? specifier
+ (percent).
+
+ additional is for format strings which contain one or more
+ '*' modifiers."""
+ # this is only for one-percent-specifier strings and this should be checked
+ if percent[0] != '%':
+ raise ValueError("format() must be given exactly one %char "
+ "format specifier")
+ if additional:
+ formatted = percent % ((value,) + additional)
+ else:
+ formatted = percent % value
+ # floats and decimal ints need special action!
+ if percent[-1] in 'eEfFgG':
+ seps = 0
+ parts = formatted.split('.')
+ if grouping:
+ parts[0], seps = locale._group(parts[0], monetary=monetary)
+ decimal_point = locale.localeconv()[monetary and 'mon_decimal_point'
+ or 'decimal_point']
+ formatted = decimal_point.join(parts)
+ while seps:
+ sp = formatted.find(' ')
+ if sp == -1: break
+ formatted = formatted[:sp] + formatted[sp+1:]
+ seps -= 1
+ elif percent[-1] in 'diu':
+ if grouping:
+ formatted = locale._group(formatted, monetary=monetary)[0]
+ return formatted
+
+def currency(val, symbol=True, grouping=False, international=False):
+ """Formats val according to the currency settings
+ in the current locale."""
+ conv = locale.localeconv()
+
+ # check for illegal values
+ digits = conv[international and 'int_frac_digits' or 'frac_digits']
+ if digits == 127:
+ raise ValueError("Currency formatting is not possible using "
+ "the 'C' locale.")
+
+ s = format('%%.%if' % digits, abs(val), grouping, monetary=True)
+ # '<' and '>' are markers if the sign must be inserted between symbol and value
+ s = '<' + s + '>'
+
+ if symbol:
+ smb = conv[international and 'int_curr_symbol' or 'currency_symbol']
+ precedes = conv[val<0 and 'n_cs_precedes' or 'p_cs_precedes']
+ separated = conv[val<0 and 'n_sep_by_space' or 'p_sep_by_space']
+
+ if precedes:
+ s = smb + (separated and ' ' or '') + s
+ else:
+ s = s + (separated and ' ' or '') + smb
+
+ sign_pos = conv[val<0 and 'n_sign_posn' or 'p_sign_posn']
+ sign = conv[val<0 and 'negative_sign' or 'positive_sign']
+
+ if sign_pos == 0:
+ s = '(' + s + ')'
+ elif sign_pos == 1:
+ s = sign + s
+ elif sign_pos == 2:
+ s = s + sign
+ elif sign_pos == 3:
+ s = s.replace('<', sign)
+ elif sign_pos == 4:
+ s = s.replace('>', sign)
+ else:
+ # the default if nothing specified;
+ # this should be the most fitting sign position
+ s = sign + s
+
+ return s.replace('<', '').replace('>', '')
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-03 16:26:52
|
Revision: 86
http://pykafe.svn.sourceforge.net/pykafe/?rev=86&view=rev
Author: jnmbk
Date: 2007-06-03 09:26:55 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
make client work with new things
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-03 16:26:05 UTC (rev 85)
+++ trunk/pykafe/client/client.py 2007-06-03 16:26:55 UTC (rev 86)
@@ -96,22 +96,16 @@
data = base64.decodestring(self.tcpSocket.readAll())
print "received from server:", data
if data[:3] == "001":
- if self.client.session.state == ClientSession.ready:
- sendDataToUi(data)
- else:
- sys.stderr.write(_("Received ack from server, state was: %s") % self.client.session.toString())
+ sendDataToUi(data)
elif data[:3] == "003":
- if self.client.session.state == ClientSession.ready:
- sendDataToUi(data)
- if data[3] == "1":
- self.client.session.state = ClientSession.loggedIn
- else:
- sys.stderr.write(_("Received %s from server, state was: %s") % (data, self.client.session.toString()))
+ sendDataToUi(data)
+ if data[3] == "1":
+ self.client.setState(ClientSession.loggedIn)
elif data[:3] == "005":
- if self.client.session.state == ClientSession.ready:
- self.client.session.user = "guest"
- self.client.session.state = ClientSession.loggedIn
- sendDataToUi("005")
+ self.client.setState(ClientSession.loggedIn)
+ sendDataToUi("005")
+ elif data[:3] == "006":
+ self.client.setState(ClientSession.loggedIn, endTime = QtCore.QDateTime.fromTime_t(int(data[3:])))
elif data[:3] == "007":
iptablesFile = "*filter\n:INPUT ACCEPT [94:7144]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [177:10428]\n"
for site in data[3:].split('\n'):
@@ -152,31 +146,24 @@
else:
sys.stderr.write(_("Client tried to say I'm here, state was: %s") % self.client.session.toString())
elif data[:3] == "008":
- print 8
- if self.client.session.state == ClientSession.loggedIn:
- print "gdg"
- sendDataToServer(data)
- os.system("service kdebase stop && sleep 3 && service kdebase start")
+ sendDataToServer(data)
+ os.system("restartkde&")
elif data[:3] == "017":
currentTime = QtCore.QDateTime.currentDateTime()
usedTime = self.client.session.startTime.secsTo(currentTime)
- price = (usedTime/600)*(config.price_onehourprice/6.0)
remainingTime = QtCore.QDateTime()
- if self.endTime.isValid():
+ if self.client.session.endTime:
remainingTime.setTime_t(currentTime.secsTo(self.client.session.endTime))
else:
remainingTime.setTime_t(0)
temp = usedTime
usedTime = QtCore.QDateTime()
usedTime.setTime_t(temp)
- text = self.startTime.time().toString("hh.mm") + "\n" +\
+ text = self.client.session.startTime.time().toString("hh.mm") + "\n" +\
remainingTime.toUTC().time().toString("hh.mm") + "\n" +\
usedTime.toUTC().time().toString("hh.mm") + "|"
- if float(config.price_fixedprice) < price:
- text += currency(price)
- else:
- text += currency(float(config.price_fixedprice))
- self.tcpSocket.write(text)
+ text += currency(self.client.session.calculatePrice(config))
+ self.tcpSocket.write(base64.encodestring(text))
self.tcpSocket.waitForBytesWritten()
self.exit()
@@ -192,11 +179,21 @@
thread.start()
self.threads = [thread]
print "trying to connect to server"
+
def incomingConnection(self, socketDescriptor):
thread = ListenerThread(socketDescriptor, self)
thread.start()
self.threads.append(thread)
print "We have " + str(len(self.threads)) + " thread(s)"
+
def initialConnection(self):
print "connected to server"
self.session.setState(ClientSession.notReady)
+
+ def setState(self, state, user = "guest", endTime = ""):
+ if state == ClientSession.loggedIn:
+ self.session.user = user
+ self.session.startTime = QtCore.QDateTime.currentDateTime()
+ if endTime:
+ self.session.endTime = endTime
+ self.session.setState(state)
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-03 16:26:05 UTC (rev 85)
+++ trunk/pykafe/client/clientmain.py 2007-06-03 16:26:55 UTC (rev 86)
@@ -86,11 +86,10 @@
self.sendMessage("008")
class TimerThread(QtCore.QThread):
- def __init__(self, parent, startTime, endTime, currencyConfig):
+ def __init__(self, parent, startTime, endTime):
QtCore.QThread.__init__(self, parent)
self.startTime = startTime
self.endTime = endTime
- self.currencyConfig = currencyConfig
def run(self):
while True:
self.do()
@@ -99,10 +98,12 @@
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
tcpSocket.waitForConnected()
- tcpSocket.write("017")
+ tcpSocket.write(base64.encodestring("017"))
tcpSocket.waitForReadyRead()
- text = tcpSocket.readAll()
+ text = base64.decodestring(tcpSocket.readAll())
text1, text2 = text.rsplit('|', 1)
+ #there's a big problem here, somehow time returns "1" and money returns ""
+ #TODO: fix it
self.emit(QtCore.SIGNAL("changeTimeLabel"), text1)
self.emit(QtCore.SIGNAL("changeMoneyLabel"), text2)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-03 19:52:33
|
Revision: 90
http://pykafe.svn.sourceforge.net/pykafe/?rev=90&view=rev
Author: jnmbk
Date: 2007-06-03 12:52:34 -0700 (Sun, 03 Jun 2007)
Log Message:
-----------
trying to make it right
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-03 18:32:33 UTC (rev 89)
+++ trunk/pykafe/client/client.py 2007-06-03 19:52:34 UTC (rev 90)
@@ -131,20 +131,13 @@
sendDataToUi("014")
return
if data[:3] == "000":
- if self.client.session.state == ClientSession.ready:
- sendDataToServer("000")
- self.client.session.setState(ClientSession.requestedOpening)
- else:
- sys.stderr.write(_("Client tried to send opening request, state was: %s") % self.client.session.toString())
+ sendDataToServer("000")
+ self.client.session.setState(ClientSession.requestedOpening)
elif data[:3] == "002":
- if self.client.session.state == ClientSession.ready:
- sendDataToServer(data)
+ sendDataToServer(data)
elif data[:3] == "004":
- if self.client.session.state == ClientSession.notReady:
- sendDataToServer("004")
- self.client.session.state = ClientSession.ready
- else:
- sys.stderr.write(_("Client tried to say I'm here, state was: %s") % self.client.session.toString())
+ sendDataToServer("004")
+ self.client.session.state = ClientSession.ready
elif data[:3] == "008":
sendDataToServer(data)
os.system("restartkde&")
@@ -163,6 +156,7 @@
remainingTime.toUTC().time().toString("hh.mm") + "\n" +\
usedTime.toUTC().time().toString("hh.mm") + "|"
text += currency(self.client.session.calculatePrice(config))
+ print "sending:", text
self.tcpSocket.write(base64.encodestring(text))
self.tcpSocket.waitForBytesWritten()
self.exit()
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-03 18:32:33 UTC (rev 89)
+++ trunk/pykafe/client/clientmain.py 2007-06-03 19:52:34 UTC (rev 90)
@@ -44,21 +44,6 @@
self.tcpSocket.waitForReadyRead()
data = base64.decodestring(self.tcpSocket.readAll())
print "received:", data
- """if data[:3] == "001":
- if data[3] == "1":
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))
- elif data[3] == "0":
- self.emit(QtCore.SIGNAL("message"), _("Server didn't give acknowledge"))
- elif data[:3] == "003":
- if data[3] == 1:
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))
- else:
- self.emit(QtCore.SIGNAL("message"), _("Wrong username or password"))
- elif data[:3] == "005":
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))"""
self.tcpSocket.disconnectFromHost()
self.exec_()
@@ -182,10 +167,10 @@
self.trayIcon.show()
self.ui = MainWindow
QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.iconActivated)
- self.thread = TimerThread(MainWindow)
- QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeTimeLabel"),self.timeLabel.setText)
- QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeMoneyLabel"),self.moneyLabel.setText)
- self.thread.start()
+ thread = TimerThread()
+ QtCore.QObject.connect(thread,QtCore.SIGNAL("changeTimeLabel"),self.timeLabel.setText)
+ QtCore.QObject.connect(thread,QtCore.SIGNAL("changeMoneyLabel"),self.moneyLabel.setText)
+ thread.start()
def iconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
if self.ui.isVisible():
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-04 15:38:52
|
Revision: 92
http://pykafe.svn.sourceforge.net/pykafe/?rev=92&view=rev
Author: jnmbk
Date: 2007-06-04 08:38:47 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
cafeteria thing and fixes
Modified Paths:
--------------
trunk/pykafe/client/cafeteria.ui
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
trunk/pykafe/client/login.py
Added Paths:
-----------
trunk/pykafe/client/cafeteria.py
Added: trunk/pykafe/client/cafeteria.py
===================================================================
--- trunk/pykafe/client/cafeteria.py (rev 0)
+++ trunk/pykafe/client/cafeteria.py 2007-06-04 15:38:47 UTC (rev 92)
@@ -0,0 +1,157 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007, pyKafe Development Team
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# Please read the COPYING file.
+#
+
+from PyQt4 import QtCore, QtGui
+
+import locale, gettext
+locale.setlocale(locale.LC_ALL, "C")
+_ = gettext.translation("pyKafe_client", fallback=True).ugettext
+
+class Product:
+ def __init__(self, values):
+ print values
+ self.name, self.price, self.quantity = values.split('|',3)
+
+class Order(QtGui.QTreeWidgetItem):
+ def __init__(self, parent, product, value, quantity):
+ QtGui.QTreeWidgetItem.__init__(self, parent)
+ self.setText(0, product)
+ self.setText(1, value)
+ self.setText(2, quantity)
+
+def findProductPrice(products, name):
+ for product in products:
+ if product.name == name:
+ return float(product.value)
+
+class Ui_Dialog(object):
+ def setupUi(self, Dialog, client):
+ Dialog.setObjectName("Dialog")
+ Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,361,300).size()).expandedTo(Dialog.minimumSizeHint()))
+ Dialog.setWindowIcon(QtGui.QIcon("../../data/icons/pyKafe.png"))
+
+ self.gridlayout = QtGui.QGridLayout(Dialog)
+ self.gridlayout.setMargin(9)
+ self.gridlayout.setSpacing(6)
+ self.gridlayout.setObjectName("gridlayout")
+
+ self.gridlayout1 = QtGui.QGridLayout()
+ self.gridlayout1.setMargin(0)
+ self.gridlayout1.setSpacing(6)
+ self.gridlayout1.setObjectName("gridlayout1")
+
+ spacerItem = QtGui.QSpacerItem(20,16,QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Fixed)
+ self.gridlayout1.addItem(spacerItem,0,2,1,1)
+
+ self.addOrder = QtGui.QPushButton(Dialog)
+ self.addOrder.setIcon(QtGui.QIcon("../../data/icons/edit_add.png"))
+ self.addOrder.setObjectName("addOrder")
+ self.gridlayout1.addWidget(self.addOrder,1,2,1,1)
+
+ self.product = QtGui.QComboBox(Dialog)
+ self.product.setObjectName("product")
+ self.gridlayout1.addWidget(self.product,1,0,1,1)
+
+ self.label = QtGui.QLabel(Dialog)
+
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Policy(5),QtGui.QSizePolicy.Policy(0))
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
+ self.label.setSizePolicy(sizePolicy)
+ self.label.setObjectName("label")
+ self.gridlayout1.addWidget(self.label,0,0,1,1)
+
+ self.quantity = QtGui.QSpinBox(Dialog)
+ self.quantity.setMinimum(1)
+ self.quantity.setObjectName("quantity")
+ self.gridlayout1.addWidget(self.quantity,1,1,1,1)
+
+ self.label_2 = QtGui.QLabel(Dialog)
+
+ sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Policy(5),QtGui.QSizePolicy.Policy(0))
+ sizePolicy.setHorizontalStretch(0)
+ sizePolicy.setVerticalStretch(0)
+ sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
+ self.label_2.setSizePolicy(sizePolicy)
+ self.label_2.setObjectName("label_2")
+ self.gridlayout1.addWidget(self.label_2,0,1,1,1)
+ self.gridlayout.addLayout(self.gridlayout1,0,0,1,1)
+
+ self.buttonBox = QtGui.QDialogButtonBox(Dialog)
+ self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
+ self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok)
+ self.buttonBox.setObjectName("buttonBox")
+ self.gridlayout.addWidget(self.buttonBox,2,0,1,1)
+
+ self.tabWidget = QtGui.QTabWidget(Dialog)
+ self.tabWidget.setObjectName("tabWidget")
+
+ self.tab = QtGui.QWidget()
+ self.tab.setObjectName("tab")
+
+ self.gridlayout2 = QtGui.QGridLayout(self.tab)
+ self.gridlayout2.setMargin(9)
+ self.gridlayout2.setSpacing(6)
+ self.gridlayout2.setObjectName("gridlayout2")
+
+ self.ordersToSend = QtGui.QTreeWidget(self.tab)
+ self.ordersToSend.setObjectName("ordersToSend")
+ self.gridlayout2.addWidget(self.ordersToSend,0,0,1,1)
+ self.tabWidget.addTab(self.tab,"")
+
+ self.tab_2 = QtGui.QWidget()
+ self.tab_2.setObjectName("tab_2")
+
+ self.gridlayout3 = QtGui.QGridLayout(self.tab_2)
+ self.gridlayout3.setMargin(9)
+ self.gridlayout3.setSpacing(6)
+ self.gridlayout3.setObjectName("gridlayout3")
+
+ self.sentOrders = QtGui.QTreeWidget(self.tab_2)
+ self.sentOrders.setObjectName("sentOrders")
+ self.gridlayout3.addWidget(self.sentOrders,0,0,1,1)
+ self.tabWidget.addTab(self.tab_2,"")
+ self.gridlayout.addWidget(self.tabWidget,1,0,1,1)
+
+ self.retranslateUi(Dialog)
+ self.tabWidget.setCurrentIndex(0)
+ self.client = client
+ self.products = []
+ for product in client.cafeteriaContents:
+ self.products.append(Product(product))
+ self.product.addItem(self.products[-1].name)
+ self.orders = []
+ QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),Dialog.accept)
+ QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),Dialog.reject)
+ QtCore.QObject.connect(self.addOrder,QtCore.SIGNAL("clicked()"),self.orderAdd)
+ QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+ def retranslateUi(self, Dialog):
+ Dialog.setWindowTitle(_("Cafeteria"))
+ self.addOrder.setText(_("Add Order"))
+ self.label.setText(_("Product"))
+ self.label_2.setText(_("Quantity"))
+ self.ordersToSend.headerItem().setText(0,_("Item"))
+ self.ordersToSend.headerItem().setText(1,_("Cost"))
+ self.ordersToSend.headerItem().setText(2,_("Quantity"))
+ self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _("Orders to Send"))
+ self.sentOrders.headerItem().setText(0,_("Item"))
+ self.sentOrders.headerItem().setText(1,_("Cost"))
+ self.sentOrders.headerItem().setText(2,_("Quantity"))
+ self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _("Sent Orders"))
+
+ def orderAdd(self):
+ print 1234
+ cost = self.quantity.value() * findProductPrice(self.products, self.product.currentText())
+ self.orders.append(Order(self.ordersToSend, self.product.currentText(), cost, self.quantity.value()))
+ self.client.temporders.append[self.product.currentText() + '|' + str(self.quantity.value())]
Modified: trunk/pykafe/client/cafeteria.ui
===================================================================
--- trunk/pykafe/client/cafeteria.ui 2007-06-03 20:20:15 UTC (rev 91)
+++ trunk/pykafe/client/cafeteria.ui 2007-06-04 15:38:47 UTC (rev 92)
@@ -47,7 +47,7 @@
</spacer>
</item>
<item row="1" column="2" >
- <widget class="QPushButton" name="pushButton" >
+ <widget class="QPushButton" name="addOrder" >
<property name="text" >
<string>Add Order</string>
</property>
@@ -57,7 +57,7 @@
</widget>
</item>
<item row="1" column="0" >
- <widget class="QComboBox" name="comboBox" />
+ <widget class="QComboBox" name="product" />
</item>
<item row="0" column="0" >
<widget class="QLabel" name="label" >
@@ -75,7 +75,11 @@
</widget>
</item>
<item row="1" column="1" >
- <widget class="QSpinBox" name="spinBox" />
+ <widget class="QSpinBox" name="quantity" >
+ <property name="minimum" >
+ <number>1</number>
+ </property>
+ </widget>
</item>
<item row="0" column="1" >
<widget class="QLabel" name="label_2" >
@@ -121,7 +125,7 @@
<number>6</number>
</property>
<item row="0" column="0" >
- <widget class="QTreeWidget" name="treeWidget" >
+ <widget class="QTreeWidget" name="ordersToSend" >
<column>
<property name="text" >
<string>Item</string>
@@ -153,7 +157,7 @@
<number>6</number>
</property>
<item row="0" column="0" >
- <widget class="QTreeWidget" name="treeWidget_2" >
+ <widget class="QTreeWidget" name="sentOrders" >
<column>
<property name="text" >
<string>Item</string>
@@ -211,5 +215,21 @@
</hint>
</hints>
</connection>
+ <connection>
+ <sender>addOrder</sender>
+ <signal>clicked()</signal>
+ <receiver>Dialog</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel" >
+ <x>295</x>
+ <y>46</y>
+ </hint>
+ <hint type="destinationlabel" >
+ <x>180</x>
+ <y>149</y>
+ </hint>
+ </hints>
+ </connection>
</connections>
</ui>
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-03 20:20:15 UTC (rev 91)
+++ trunk/pykafe/client/client.py 2007-06-04 15:38:47 UTC (rev 92)
@@ -103,8 +103,9 @@
self.client.setState(ClientSession.loggedIn)
elif data[:3] == "005":
self.client.setState(ClientSession.loggedIn)
+ sendDataToUi(data)
+ elif data[:3] == "006":
sendDataToUi("005")
- elif data[:3] == "006":
self.client.setState(ClientSession.loggedIn, endTime = QtCore.QDateTime.fromTime_t(int(data[3:])))
elif data[:3] == "007":
iptablesFile = "*filter\n:INPUT ACCEPT [94:7144]\n:FORWARD ACCEPT [0:0]\n:OUTPUT ACCEPT [177:10428]\n"
@@ -118,8 +119,13 @@
file.close()
print iptablesFile
os.system("iptables-restore < /etc/pyKafe/iptables.conf")
+ elif data[:3] == "009":
+ os.system("restartkde&")
elif data[:3] == "010":
os.system("init 0")
+ elif data[:3] == "015":
+ if self.client.state == ClientSession.ready:
+ sendDataToServer("004")
elif data[:3] == "016":
for c, value in map(lambda x,y:(x,y), ("price_fixedprice", "price_fixedpriceminutes", "price_onehourprice", "price_rounding"), data[3:].split("|")):
config.set(c, value)
@@ -132,12 +138,12 @@
return
if data[:3] == "000":
sendDataToServer("000")
- self.client.session.setState(ClientSession.requestedOpening)
+ self.client.setState(ClientSession.requestedOpening)
elif data[:3] == "002":
sendDataToServer(data)
elif data[:3] == "004":
sendDataToServer("004")
- self.client.session.state = ClientSession.ready
+ self.client.setState(ClientSession.ready)
elif data[:3] == "008":
sendDataToServer(data)
os.system("restartkde&")
@@ -159,7 +165,16 @@
print "sending:", text
self.tcpSocket.write(base64.encodestring(text))
self.tcpSocket.waitForBytesWritten()
- self.exit()
+ elif data[:3] == "018":
+ tcpSocket = QtNetwork.QTcpSocket()
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(config.network_serverIP), config.network_port)
+ tcpSocket.waitForConnected()
+ tcpSocket.write(base64.encodestring(data))
+ tcpSocket.waitForBytesWritten()
+ tcpSocket.waitForReadyRead()
+ data = tcpSocket.readAll()
+ self.tcpSocket.write(data)
+ self.tcpSocket.waitForBytesWritten()
class PykafeClient(QtNetwork.QTcpServer):
def __init__(self):
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-03 20:20:15 UTC (rev 91)
+++ trunk/pykafe/client/clientmain.py 2007-06-04 15:38:47 UTC (rev 92)
@@ -13,6 +13,7 @@
import sys, base64
from PyQt4 import QtCore, QtGui, QtNetwork
from config import PykafeConfiguration
+import cafeteria
import locale, gettext
locale.setlocale(locale.LC_ALL, "C")
@@ -21,8 +22,8 @@
config = PykafeConfiguration()
class SenderThread(QtCore.QThread):
- def __init__(self, parent, data):
- QtCore.QThread.__init__(self, parent)
+ def __init__(self, data):
+ QtCore.QThread.__init__(self)
self.data = data
def run(self):
tcpSocket = QtNetwork.QTcpSocket()
@@ -53,6 +54,8 @@
self.ui = ui
self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
self.threads = []
+ self.orders = []
+ self.temporders = []
def incomingConnection(self, socketDescriptor):
thread = ListenerThread(self.parent(), socketDescriptor)
QtCore.QObject.connect(thread,QtCore.SIGNAL("close"),self.parent().close)
@@ -60,15 +63,39 @@
thread.start()
self.threads.append(thread)
def sendMessage(self, data):
- thread = SenderThread(self.parent(), data)
+ thread = SenderThread(data)
thread.start()
self.threads.append(thread)
def cafeteria(self):
- pass
+ tcpSocket = QtNetwork.QTcpSocket()
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
+ tcpSocket.waitForConnected()
+ tcpSocket.write(base64.encodestring("018"))
+ tcpSocket.waitForBytesWritten()
+ tcpSocket.waitForReadyRead()
+ data = base64.decodestring(tcpSocket.readAll())
+ print "received:", data
+ tcpSocket.disconnectFromHost()
+ self.cafeteriaContents = []
+ for i in data.split('||'):
+ self.cafeteriaContents.append(i)
+ self.cafeteriaWindow = QtGui.QDialog(self.parent())
+ QtCore.QObject.connect(self.cafeteriaWindow, QtCore.SIGNAL("accepted()"), self.sendOrders)
+ dialog = cafeteria.Ui_Dialog()
+ dialog.setupUi(self.cafeteriaWindow, self)
+ self.cafeteriaWindow.setModal(True)
+ self.cafeteriaWindow.show()
def logout(self):
answer = QtGui.QMessageBox.question(self.parent(), _("Are you sure?"), _("Do you really want to logout?"), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes).__or__(QtGui.QMessageBox.No), QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.Yes:
self.sendMessage("008")
+ def sendOrders(self):
+ text = "019"
+ for order in self.temporders:
+ text += order
+ self.orders.append(order)
+ if len(text)>3:
+ self.sendMessage(text)
class TimerThread(QtCore.QThread):
def run(self):
@@ -167,10 +194,13 @@
self.trayIcon.show()
self.ui = MainWindow
QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.iconActivated)
- thread = TimerThread()
- QtCore.QObject.connect(thread,QtCore.SIGNAL("changeTimeLabel"),self.timeLabel.setText)
- QtCore.QObject.connect(thread,QtCore.SIGNAL("changeMoneyLabel"),self.moneyLabel.setText)
- thread.start()
+ self.thread = TimerThread()
+ QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeTimeLabel"),self.timeLabel.setText)
+ QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeMoneyLabel"),self.moneyLabel.setText)
+ QtCore.QObject.connect(self.thread,QtCore.SIGNAL("setCafeteria"),self.setCafeteria)
+ self.thread.start()
+ def setCafeteria(self, cafeteria):
+ self.cafeteria = cafeteria
def iconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
if self.ui.isVisible():
Modified: trunk/pykafe/client/login.py
===================================================================
--- trunk/pykafe/client/login.py 2007-06-03 20:20:15 UTC (rev 91)
+++ trunk/pykafe/client/login.py 2007-06-04 15:38:47 UTC (rev 92)
@@ -54,23 +54,23 @@
print "received:", data
if data[:3] == "001":
if data[3] == "1":
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))
+ self.login()
elif data[3] == "0":
self.emit(QtCore.SIGNAL("message"), _("Server didn't give acknowledge"))
elif data[:3] == "003":
if data[3] == "1":
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))
+ self.login()
else:
self.emit(QtCore.SIGNAL("message"), _("Wrong username or password"))
elif data[:3] == "005":
- os.system("pyKafeclient&")
- self.emit(QtCore.SIGNAL("close"))
+ self.login()
elif data[:3] == "014":
self.emit(QtCore.SIGNAL("message"), _("Can't connect to server"))
self.tcpSocket.disconnectFromHost()
self.exec_()
+ def login(self):
+ os.system("pyKafeclient&")
+ self.emit(QtCore.SIGNAL("close"))
class PykafeClient(QtNetwork.QTcpServer):
def __init__(self, parent, ui):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-04 21:58:09
|
Revision: 94
http://pykafe.svn.sourceforge.net/pykafe/?rev=94&view=rev
Author: jnmbk
Date: 2007-06-04 14:58:11 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
fixed
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-04 15:39:40 UTC (rev 93)
+++ trunk/pykafe/client/client.py 2007-06-04 21:58:11 UTC (rev 94)
@@ -52,9 +52,14 @@
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
tcpSocket.waitForConnected(-1)
- tcpSocket.write(base64.encodestring(data))
- tcpSocket.waitForBytesWritten()
- print "sent to ui:", data
+ print "trying to send to ui:", data
+ if tcpSocket.write(base64.encodestring(data)) == -1:
+ print "failed"
+ return False
+ else:
+ print "success"
+ tcpSocket.waitForBytesWritten()
+ return True
def getSiteIP(site):
try:
@@ -163,8 +168,13 @@
usedTime.toUTC().time().toString("hh.mm") + "|"
text += currency(self.client.session.calculatePrice(config))
print "sending:", text
- self.tcpSocket.write(base64.encodestring(text))
- self.tcpSocket.waitForBytesWritten()
+ tcpSocket = QtNetwork.QTcpSocket()
+ tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
+ tcpSocket.waitForConnected()
+ temp = data+text
+ tcpSocket.write(str(temp))
+ tcpSocket.waitForBytesWritten()
+ #sendDataToUi(data+text)
elif data[:3] == "018":
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(config.network_serverIP), config.network_port)
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-04 15:39:40 UTC (rev 93)
+++ trunk/pykafe/client/clientmain.py 2007-06-04 21:58:11 UTC (rev 94)
@@ -10,7 +10,7 @@
# Please read the COPYING file.
#
-import sys, base64
+import sys, base64, socket
from PyQt4 import QtCore, QtGui, QtNetwork
from config import PykafeConfiguration
import cafeteria
@@ -36,17 +36,26 @@
tcpSocket.disconnectFromHost()
class ListenerThread(QtCore.QThread):
- def __init__(self, parent, socketDescriptor):
- QtCore.QThread.__init__(self, parent)
+ def __init__(self, socketDescriptor):
+ QtCore.QThread.__init__(self)
self.socketDescriptor = socketDescriptor
def run(self):
self.tcpSocket = QtNetwork.QTcpSocket()
self.tcpSocket.setSocketDescriptor(self.socketDescriptor)
- self.tcpSocket.waitForReadyRead()
- data = base64.decodestring(self.tcpSocket.readAll())
+ print "connection request from:", self.tcpSocket.peerAddress().toString()
+ QtCore.QObject.connect(self.tcpSocket, QtCore.SIGNAL("readyRead()"), self.readRoot)
+ self.tcpSocket.waitForDisconnected()
+ self.exec_()
+ def readRoot(self):
+ data = self.tcpSocket.readAll()
print "received:", data
- self.tcpSocket.disconnectFromHost()
- self.exec_()
+ if data[:3] == "017":
+ text = data[3:]
+ if not text:
+ print "couldn't read"
+ else:
+ text1, text2 = text.split('|',1)
+ self.emit(QtCore.SIGNAL("updateLabels"), str(text1), str(text2))
class PykafeClientMain(QtNetwork.QTcpServer):
def __init__(self, parent, ui):
@@ -57,9 +66,10 @@
self.orders = []
self.temporders = []
def incomingConnection(self, socketDescriptor):
- thread = ListenerThread(self.parent(), socketDescriptor)
+ thread = ListenerThread(socketDescriptor)
QtCore.QObject.connect(thread,QtCore.SIGNAL("close"),self.parent().close)
QtCore.QObject.connect(thread,QtCore.SIGNAL("message"),self.ui.statusbar.showMessage)
+ QtCore.QObject.connect(thread,QtCore.SIGNAL("updateLabels"),self.ui.updateLabels)
thread.start()
self.threads.append(thread)
def sendMessage(self, data):
@@ -100,17 +110,11 @@
class TimerThread(QtCore.QThread):
def run(self):
while True:
- tcpSocket = QtNetwork.QTcpSocket()
- tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
- tcpSocket.waitForConnected()
- tcpSocket.write(base64.encodestring("017"))
- tcpSocket.waitForReadyRead()
- text = base64.decodestring(tcpSocket.readAll())
- text1, text2 = text.rsplit('|', 1)
- #there's a big problem here, somehow time returns the first letter of time and money returns ""
- #TODO: fix it
- self.emit(QtCore.SIGNAL("changeTimeLabel"), text1)
- self.emit(QtCore.SIGNAL("changeMoneyLabel"), text2)
+ #self.emit(QtCore.SIGNAL("updateLabels"), "sadasf","retr")
+ tcpSocket = socket.socket()
+ tcpSocket.connect(("",config.network_port))
+ tcpSocket.send(base64.encodestring("017"))
+ tcpSocket.close()
self.sleep(60)
class Ui_MainWindow(object):
@@ -195,12 +199,12 @@
self.ui = MainWindow
QtCore.QObject.connect(self.trayIcon, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.iconActivated)
self.thread = TimerThread()
- QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeTimeLabel"),self.timeLabel.setText)
- QtCore.QObject.connect(self.thread,QtCore.SIGNAL("changeMoneyLabel"),self.moneyLabel.setText)
QtCore.QObject.connect(self.thread,QtCore.SIGNAL("setCafeteria"),self.setCafeteria)
self.thread.start()
+
def setCafeteria(self, cafeteria):
self.cafeteria = cafeteria
+
def iconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.Trigger:
if self.ui.isVisible():
@@ -208,6 +212,10 @@
else:
self.ui.show()
+ def updateLabels(self, text1, text2):
+ self.timeLabel.setText(text1)
+ self.moneyLabel.setText(text2)
+
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_("pyKafe"))
self.logoutButton.setText(_("Logout"))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-04 22:39:30
|
Revision: 96
http://pykafe.svn.sourceforge.net/pykafe/?rev=96&view=rev
Author: jnmbk
Date: 2007-06-04 15:39:31 -0700 (Mon, 04 Jun 2007)
Log Message:
-----------
be secure
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-04 21:58:27 UTC (rev 95)
+++ trunk/pykafe/client/client.py 2007-06-04 22:39:31 UTC (rev 96)
@@ -167,14 +167,7 @@
remainingTime.toUTC().time().toString("hh.mm") + "\n" +\
usedTime.toUTC().time().toString("hh.mm") + "|"
text += currency(self.client.session.calculatePrice(config))
- print "sending:", text
- tcpSocket = QtNetwork.QTcpSocket()
- tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_localPort)
- tcpSocket.waitForConnected()
- temp = data+text
- tcpSocket.write(str(temp))
- tcpSocket.waitForBytesWritten()
- #sendDataToUi(data+text)
+ sendDataToUi(str(data+text))
elif data[:3] == "018":
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(config.network_serverIP), config.network_port)
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-04 21:58:27 UTC (rev 95)
+++ trunk/pykafe/client/clientmain.py 2007-06-04 22:39:31 UTC (rev 96)
@@ -47,7 +47,7 @@
self.tcpSocket.waitForDisconnected()
self.exec_()
def readRoot(self):
- data = self.tcpSocket.readAll()
+ data = base64.decodestring(self.tcpSocket.readAll())
print "received:", data
if data[:3] == "017":
text = data[3:]
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-06 10:11:22
|
Revision: 98
http://pykafe.svn.sourceforge.net/pykafe/?rev=98&view=rev
Author: jnmbk
Date: 2007-06-06 03:11:23 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
sorry for the huge changes
Modified Paths:
--------------
trunk/pykafe/client/cafeteria.py
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
trunk/pykafe/client/login.py
trunk/pykafe/client/session.py
Modified: trunk/pykafe/client/cafeteria.py
===================================================================
--- trunk/pykafe/client/cafeteria.py 2007-06-04 22:43:09 UTC (rev 97)
+++ trunk/pykafe/client/cafeteria.py 2007-06-06 10:11:23 UTC (rev 98)
@@ -11,6 +11,7 @@
#
from PyQt4 import QtCore, QtGui
+from currencyformat import currency
import locale, gettext
locale.setlocale(locale.LC_ALL, "C")
@@ -25,13 +26,13 @@
def __init__(self, parent, product, value, quantity):
QtGui.QTreeWidgetItem.__init__(self, parent)
self.setText(0, product)
- self.setText(1, value)
- self.setText(2, quantity)
+ self.setText(1, currency(value))
+ self.setText(2, str(quantity))
def findProductPrice(products, name):
for product in products:
if product.name == name:
- return float(product.value)
+ return float(product.quantity)
class Ui_Dialog(object):
def setupUi(self, Dialog, client):
@@ -130,10 +131,15 @@
for product in client.cafeteriaContents:
self.products.append(Product(product))
self.product.addItem(self.products[-1].name)
+ self.sentOrdersHolder = []
+ for order in client.orders:
+ name, quantity = order.split('|')
+ self.sentOrdersHolder.append(Order(self.sentOrders, name, findProductPrice(self.products, name), quantity))
self.orders = []
+ self.adder = Adder(self)
QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),Dialog.accept)
QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),Dialog.reject)
- QtCore.QObject.connect(self.addOrder,QtCore.SIGNAL("clicked()"),self.orderAdd())
+ QtCore.QObject.connect(self.addOrder,QtCore.SIGNAL("clicked()"),self.adder.orderAdd)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
@@ -150,7 +156,10 @@
self.sentOrders.headerItem().setText(2,_("Quantity"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _("Sent Orders"))
+class Adder:
+ def __init__(self, ui):
+ self.ui = ui
def orderAdd(self):
- cost = self.quantity.value() * findProductPrice(self.products, self.product.currentText())
- self.orders.append(Order(self.ordersToSend, self.product.currentText(), cost, self.quantity.value()))
- self.client.temporders.append[self.product.currentText() + '|' + str(self.quantity.value())]
+ cost = self.ui.quantity.value() * findProductPrice(self.ui.products, self.ui.product.currentText())
+ self.ui.orders.append(Order(self.ui.ordersToSend, self.ui.product.currentText(), cost, self.ui.quantity.value()))
+ self.ui.client.temporders.append(self.ui.product.currentText() + '|' + str(self.ui.quantity.value()))
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-04 22:43:09 UTC (rev 97)
+++ trunk/pykafe/client/client.py 2007-06-06 10:11:23 UTC (rev 98)
@@ -73,7 +73,7 @@
transferredBytes = 0
interfaces = os.listdir("/sys/class/net")
for interface in interfaces:
- if file("/sys/class/net/%s/operstate" % interface).read() == "up\n":
+ if file("/sys/class/net/%s/operstate" % interface).read() in ("up\n", "unknown\n"):
receivedBytes += int(file("/sys/class/net/%s/statistics/rx_bytes" % interface).read())
transferredBytes += int(file("/sys/class/net/%s/statistics/tx_bytes" % interface).read())
return receivedBytes, transferredBytes
@@ -101,11 +101,13 @@
data = base64.decodestring(self.tcpSocket.readAll())
print "received from server:", data
if data[:3] == "001":
+ if data[3] == "1":
+ self.client.setState(ClientSession.loggedIn)
sendDataToUi(data)
elif data[:3] == "003":
sendDataToUi(data)
if data[3] == "1":
- self.client.setState(ClientSession.loggedIn)
+ self.client.setState(ClientSession.loggedIn, user = data[4:data.find('|')])
elif data[:3] == "005":
self.client.setState(ClientSession.loggedIn)
sendDataToUi(data)
@@ -125,15 +127,19 @@
print iptablesFile
os.system("iptables-restore < /etc/pyKafe/iptables.conf")
elif data[:3] == "009":
+ received, transferred = getNetworkBytes()
+ sendDataToServer("023" + self.client.session.user + '|' + str(received - self.client.session.receivedBytes) +'|'+ str(transferred - self.client.session.transferredBytes))
os.system("restartkde&")
elif data[:3] == "010":
os.system("init 0")
elif data[:3] == "015":
- if self.client.state == ClientSession.ready:
- sendDataToServer("004")
+ self.client.setState(ClientSession.notReady)
+ sendDataToUi("020")
elif data[:3] == "016":
for c, value in map(lambda x,y:(x,y), ("price_fixedprice", "price_fixedpriceminutes", "price_onehourprice", "price_rounding"), data[3:].split("|")):
config.set(c, value)
+ elif data[:3] == "021":
+ sendDataToUi(data)
def readUi(self):
data = base64.decodestring(self.tcpSocket.readAll())
@@ -141,22 +147,31 @@
if self.client.session.state == ClientSession.notConnected:
sendDataToUi("014")
return
+ if self.client.session.state == ClientSession.waitingMoney:
+ sendDataToUi("012")
+ return
if data[:3] == "000":
sendDataToServer("000")
self.client.setState(ClientSession.requestedOpening)
elif data[:3] == "002":
sendDataToServer(data)
elif data[:3] == "004":
- sendDataToServer("004")
- self.client.setState(ClientSession.ready)
+ if not self.client.session.state == ClientSession.waitingMoney:
+ sendDataToServer("004")
+ self.client.setState(ClientSession.ready)
elif data[:3] == "008":
+ received, transferred = getNetworkBytes()
+ sendDataToServer("023" + self.client.session.user + '|' + str(received - self.client.session.receivedBytes) +'|'+ str(transferred - self.client.session.transferredBytes))
sendDataToServer(data)
os.system("restartkde&")
+ self.client.setState(ClientSession.waitingMoney)
elif data[:3] == "017":
+ if self.client.session.state != ClientSession.loggedIn:
+ return
currentTime = QtCore.QDateTime.currentDateTime()
usedTime = self.client.session.startTime.secsTo(currentTime)
remainingTime = QtCore.QDateTime()
- if self.client.session.endTime:
+ if self.client.session.endTime and currentTime.secsTo(self.client.session.endTime)>0:
remainingTime.setTime_t(currentTime.secsTo(self.client.session.endTime))
else:
remainingTime.setTime_t(0)
@@ -178,6 +193,11 @@
data = tcpSocket.readAll()
self.tcpSocket.write(data)
self.tcpSocket.waitForBytesWritten()
+ elif data[:3] == "019":
+ sendDataToServer(data)
+ elif data[:3] == "022":
+ if self.client.session.user != "guest":
+ sendDataToServer(data)
class PykafeClient(QtNetwork.QTcpServer):
def __init__(self):
@@ -190,6 +210,7 @@
QtCore.QObject.connect(thread, QtCore.SIGNAL("messageSent"), self.initialConnection)
thread.start()
self.threads = [thread]
+ self.login = False
print "trying to connect to server"
def incomingConnection(self, socketDescriptor):
@@ -201,6 +222,7 @@
def initialConnection(self):
print "connected to server"
self.session.setState(ClientSession.notReady)
+ sendDataToUi("020")
def setState(self, state, user = "guest", endTime = ""):
if state == ClientSession.loggedIn:
@@ -208,4 +230,6 @@
self.session.startTime = QtCore.QDateTime.currentDateTime()
if endTime:
self.session.endTime = endTime
+ self.session.receivedBytes, self.session.transferredBytes = getNetworkBytes()
+ print getNetworkBytes()
self.session.setState(state)
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-04 22:43:09 UTC (rev 97)
+++ trunk/pykafe/client/clientmain.py 2007-06-06 10:11:23 UTC (rev 98)
@@ -10,7 +10,7 @@
# Please read the COPYING file.
#
-import sys, base64, socket
+import os, sys, base64, socket
from PyQt4 import QtCore, QtGui, QtNetwork
from config import PykafeConfiguration
import cafeteria
@@ -24,7 +24,7 @@
class SenderThread(QtCore.QThread):
def __init__(self, data):
QtCore.QThread.__init__(self)
- self.data = data
+ self.data = str(data)
def run(self):
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
@@ -56,6 +56,9 @@
else:
text1, text2 = text.split('|',1)
self.emit(QtCore.SIGNAL("updateLabels"), str(text1), str(text2))
+ if data[:3] == "021":
+ wallpaper = os.popen("dcop kdesktop KBackgroundIface currentWallpaper 1").read().strip()
+ self.sendMessage("022" + wallpaper)
class PykafeClientMain(QtNetwork.QTcpServer):
def __init__(self, parent, ui):
@@ -98,14 +101,16 @@
def logout(self):
answer = QtGui.QMessageBox.question(self.parent(), _("Are you sure?"), _("Do you really want to logout?"), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes).__or__(QtGui.QMessageBox.No), QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.Yes:
+ wallpaper = os.popen("dcop kdesktop KBackgroundIface currentWallpaper 1").read().strip()
+ self.sendMessage("022" + wallpaper)
self.sendMessage("008")
def sendOrders(self):
text = "019"
for order in self.temporders:
- text += order
+ text += order + "||"
self.orders.append(order)
- if len(text)>3:
- self.sendMessage(text)
+ if len(text)>5:
+ self.sendMessage(text[:-2])
class TimerThread(QtCore.QThread):
def run(self):
Modified: trunk/pykafe/client/login.py
===================================================================
--- trunk/pykafe/client/login.py 2007-06-04 22:43:09 UTC (rev 97)
+++ trunk/pykafe/client/login.py 2007-06-06 10:11:23 UTC (rev 98)
@@ -10,7 +10,7 @@
# Please read the COPYING file.
#
-import base64, os, sys, sha, time
+import base64, os, sys, sha
from PyQt4 import QtCore, QtGui, QtNetwork
from config import PykafeConfiguration
@@ -19,10 +19,11 @@
_ = gettext.translation("pyKafe_client", fallback=True).ugettext
config = PykafeConfiguration()
+timeOut = 5000
class SenderThread(QtCore.QThread):
- def __init__(self, parent, data, retry = False):
- QtCore.QThread.__init__(self, parent)
+ def __init__(self, data, retry = False):
+ QtCore.QThread.__init__(self)
self.data = data
self.retry = retry
def run(self):
@@ -31,7 +32,7 @@
while not tcpSocket.waitForConnected(-1) and self.retry:
self.emit(QtCore.SIGNAL("connectionError()"))
print "trying to reconnect in 5 seconds"
- time.sleep(5)
+ self.sleep(5)
tcpSocket.connectToHost(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), config.network_port)
if tcpSocket.write(base64.encodestring(self.data)) == -1:
print "couldn't send:", self.data
@@ -55,16 +56,28 @@
if data[3] == "1":
self.login()
elif data[3] == "0":
- self.emit(QtCore.SIGNAL("message"), _("Server didn't give acknowledge"))
+ self.emit(QtCore.SIGNAL("message"), _("Server didn't give acknowledge"), timeOut)
elif data[:3] == "003":
if data[3] == "1":
+ wallpaper = data.split('|')[1]
+ if wallpaper:
+ os.system("dcop kdesktop KBackgroundIface setWallpaper %s 8" % wallpaper)
self.login()
else:
- self.emit(QtCore.SIGNAL("message"), _("Wrong username or password"))
+ self.emit(QtCore.SIGNAL("message"), _("Wrong username or password"), timeOut)
elif data[:3] == "005":
self.login()
+ elif data[:3] == "012":
+ self.emit(QtCore.SIGNAL("message"), _("Previous customer didn't make payment"))
elif data[:3] == "014":
- self.emit(QtCore.SIGNAL("message"), _("Can't connect to server"))
+ self.emit(QtCore.SIGNAL("message"), _("Can't connect to server"), timeOut)
+ self.sleep(5)
+ thread = SenderThread("004")
+ thread.start()
+ elif data[:3] == "020":
+ thread=SenderThread("004")
+ thread.start()
+ self.emit(QtCore.SIGNAL("message"),"")
self.tcpSocket.disconnectFromHost()
self.exec_()
def login(self):
@@ -80,7 +93,7 @@
print "Can't bind port %d" % config.network_localPort
sys.exit()
print "listening localhost on port:", config.network_localPort
- thread = SenderThread(self.parent(), "004", retry = True)
+ thread = SenderThread("004", retry = True)
QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
self.threads = [thread]
@@ -92,17 +105,18 @@
self.threads.append(thread)
print "login has %d threads" % len(self.threads)
def login(self):
- thread = SenderThread(self.parent(), "002" + unicode(self.ui.username.text()) + "|" + sha.new(unicode(self.ui.password.text())).hexdigest())
+ thread = SenderThread("002" + unicode(self.ui.username.text()) + "|" + sha.new(unicode(self.ui.password.text())).hexdigest())
QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
self.threads.append(thread)
def request(self):
- thread = SenderThread(self.parent(), "000")
+ thread = SenderThread("000")
QtCore.QObject.connect(thread, QtCore.SIGNAL("connectionError()"), self.connectionError)
thread.start()
+ self.ui.statusbar.showMessage(_("Sent opening request to server"), timeOut)
self.threads.append(thread)
def connectionError(self):
- self.ui.statusbar.showMessage(_("Can't connect to local daemon, please contact cashier"))
+ self.ui.statusbar.showMessage(_("Can't connect to local daemon, please contact cashier"), timeOut)
class Ui_LoginWindow(object):
def setupUi(self, MainWindow):
Modified: trunk/pykafe/client/session.py
===================================================================
--- trunk/pykafe/client/session.py 2007-06-04 22:43:09 UTC (rev 97)
+++ trunk/pykafe/client/session.py 2007-06-06 10:11:23 UTC (rev 98)
@@ -26,6 +26,8 @@
self.startTime = None
self.endTime = None
self.orders = []
+ self.receivedBytes = 0
+ self.transferredBytes = 0
def calculatePrice(self, config):
time = self.startTime.secsTo(QtCore.QDateTime.currentDateTime())
@@ -35,6 +37,11 @@
#TODO: round the price using price_rounding
price = float(config.price_onehourprice)/3600 * time
return price
+ def calculateTotal(self, config):
+ total = self.calculatePrice(config)
+ for i in self.orders:
+ total += i
+ return total
def toString(self):
"""returns current state as a string"""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-10 05:32:38
|
Revision: 106
http://pykafe.svn.sourceforge.net/pykafe/?rev=106&view=rev
Author: jnmbk
Date: 2007-06-09 22:32:38 -0700 (Sat, 09 Jun 2007)
Log Message:
-----------
changes for my new test environment
Modified Paths:
--------------
trunk/pykafe/client/config.py
trunk/pykafe/client/login.py
Modified: trunk/pykafe/client/config.py
===================================================================
--- trunk/pykafe/client/config.py 2007-06-10 05:31:44 UTC (rev 105)
+++ trunk/pykafe/client/config.py 2007-06-10 05:32:38 UTC (rev 106)
@@ -12,7 +12,7 @@
#TODO: Read config from config file
class PykafeConfiguration:
- network_serverIP = "192.168.2.6"
+ network_serverIP = "192.168.2.2"
network_port = 23105
network_localPort = 23106
Modified: trunk/pykafe/client/login.py
===================================================================
--- trunk/pykafe/client/login.py 2007-06-10 05:31:44 UTC (rev 105)
+++ trunk/pykafe/client/login.py 2007-06-10 05:32:38 UTC (rev 106)
@@ -81,7 +81,7 @@
self.tcpSocket.disconnectFromHost()
self.exec_()
def login(self):
- os.system("pyKafeclient&")
+ os.system("pykafeclient&")
self.emit(QtCore.SIGNAL("close"))
class PykafeClient(QtNetwork.QTcpServer):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jn...@us...> - 2007-06-10 05:33:29
|
Revision: 107
http://pykafe.svn.sourceforge.net/pykafe/?rev=107&view=rev
Author: jnmbk
Date: 2007-06-09 22:33:31 -0700 (Sat, 09 Jun 2007)
Log Message:
-----------
remaining time warning
Modified Paths:
--------------
trunk/pykafe/client/client.py
trunk/pykafe/client/clientmain.py
Modified: trunk/pykafe/client/client.py
===================================================================
--- trunk/pykafe/client/client.py 2007-06-10 05:32:38 UTC (rev 106)
+++ trunk/pykafe/client/client.py 2007-06-10 05:33:31 UTC (rev 107)
@@ -183,6 +183,8 @@
usedTime.toUTC().time().toString("hh.mm") + "|"
text += currency(self.client.session.calculatePrice(config))
sendDataToUi(str(data+text))
+ if 120>remainingTime.toTime_t()>0:
+ sendDataToUi("024" + str(remainingTime.toTime_t()))
elif data[:3] == "018":
tcpSocket = QtNetwork.QTcpSocket()
tcpSocket.connectToHost(QtNetwork.QHostAddress(config.network_serverIP), config.network_port)
Modified: trunk/pykafe/client/clientmain.py
===================================================================
--- trunk/pykafe/client/clientmain.py 2007-06-10 05:32:38 UTC (rev 106)
+++ trunk/pykafe/client/clientmain.py 2007-06-10 05:33:31 UTC (rev 107)
@@ -52,9 +52,12 @@
text = data[3:]
text1, text2 = text.split('|',1)
self.emit(QtCore.SIGNAL("updateLabels"), str(text1), str(text2))
+ #TODO: Show a baloon when we're close to the end time
if data[:3] == "021":
wallpaper = os.popen("dcop kdesktop KBackgroundIface currentWallpaper 1").read().strip()
self.sendMessage("022" + wallpaper)
+ if data[:3] == "024":
+ self.emit(QtCore.SIGNAL("showMessage"), _("Warning"), _("You have %s seconds remaining!") % data[3:], QtGui.QSystemTrayIcon.Warning, 60000)
self.tcpSocket.disconnectFromHost()
class PykafeClientMain(QtNetwork.QTcpServer):
@@ -70,6 +73,7 @@
QtCore.QObject.connect(thread,QtCore.SIGNAL("close"),self.parent().close)
QtCore.QObject.connect(thread,QtCore.SIGNAL("message"),self.ui.statusbar.showMessage)
QtCore.QObject.connect(thread,QtCore.SIGNAL("updateLabels"),self.ui.updateLabels)
+ QtCore.QObject.connect(thread,QtCore.SIGNAL("showMessage"),self.ui.trayIcon.showMessage)
thread.start()
self.threads.append(thread)
def sendMessage(self, data):
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|