[Pykafe-commits] SF.net SVN: pykafe: [67] trunk/pykafe/client
Status: Pre-Alpha
Brought to you by:
jnmbk
|
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.
|