00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 from xml.etree.ElementTree import parse, SubElement
00034
00035 import sys, os
00036
00037 if os.name == 'nt':
00038 sys.path.append('.')
00039
00040 from distutils.sysconfig import get_python_lib
00041 terp_path = "/".join([get_python_lib(), 'Koo'])
00042 sys.path.append(terp_path)
00043
00044 from Koo.Common.Settings import Settings
00045 from Koo.Common import CommandLine
00046 from Koo.Common import Localization
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 Settings.loadFromFile()
00061 Settings.loadFromRegistry()
00062 Localization.initializeTranslations(Settings.value('client.language'))
00063
00064 arguments = CommandLine.parseArguments(sys.argv)
00065
00066 Localization.initializeTranslations(Settings.value('client.language'))
00067
00068
00069 imports={}
00070
00071 from PyQt4.QtCore import *
00072 from PyQt4.QtGui import *
00073 from Koo.Common import Notifier, Common
00074 from Koo.Common import DBus
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 class KeyPressEventFilter(QObject):
00094
00095 def __init__(self, parent=None):
00096 QObject.__init__(self, parent)
00097
00098 def eventFilter(self, target, event):
00099 if event.type() == QEvent.KeyPress:
00100 try:
00101 if event.force:
00102 return False
00103 except:
00104 return True
00105 if event.type() == QEvent.KeyRelease:
00106 newEvent = QKeyEvent( QEvent.KeyPress, event.key(), event.modifiers(), event.text(), event.isAutoRepeat(), event.count() )
00107 newEvent.force = True
00108 QApplication.sendEvent( target, newEvent )
00109 return QObject.eventFilter( self, target, event )
00110
00111 class PosMessageBox(QWidget):
00112 def __init__(self, title, message, parent):
00113 QWidget.__init__(self, parent)
00114
00115
00116 self.uiTitle = QLabel( self )
00117 self.uiTitle.setWordWrap( True )
00118 self.uiTitle.setText( title )
00119 self.uiMessage = QLabel( self )
00120 self.uiMessage.setWordWrap( True )
00121 self.uiMessage.setText( '<b>%s</b>' % message )
00122 self.pushOk = QPushButton( self )
00123 self.pushOk.setText( _('Ok') )
00124 self.pushOk.setIcon( QIcon( ':/images/ok.png' ) )
00125 self.connect( self.pushOk, SIGNAL('clicked()'), self.accepted)
00126
00127 self.layout = QVBoxLayout( self )
00128 self.layout.setAlignment( Qt.AlignCenter )
00129 self.layout.addWidget( self.uiTitle )
00130 self.layout.addStretch( 5 )
00131 self.layout.addWidget( self.uiMessage )
00132 self.layout.addStretch( 10 )
00133 self.layout.addWidget( self.pushOk )
00134
00135 self.previous = mainWindow.centralWidget()
00136
00137
00138 self.previous.setParent( self )
00139 self.previous.hide()
00140
00141 mainWindow.setCentralWidget( self )
00142 mainWindow.show()
00143
00144 def accepted(self):
00145 self.previous.show()
00146 self.previous.setParent( None )
00147 mainWindow.setCentralWidget( self.previous )
00148 mainWindow.show()
00149
00150
00151 def messageBox(title, message):
00152 dialog = PosMessageBox( title, message, mainWindow )
00153
00154 def handleError(title, message, details=''):
00155 messageBox( title, message )
00156
00157 def handleWarning(title, message):
00158 messageBox( title, message )
00159
00160 def handleConcurrency(model, id, context):
00161 pass
00162
00163
00164 Notifier.errorHandler = handleError
00165 Notifier.warningHandler = handleWarning
00166 Notifier.concurrencyErrorHandler = handleConcurrency
00167
00168
00169
00170
00171 if Common.isKdeAvailable:
00172 from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs
00173 from PyKDE4.kdeui import KApplication
00174
00175 appName = "Koo"
00176 catalog = ""
00177 programName = ki18n ("Koo")
00178 version = "1.0"
00179 description = ki18n ("KDE OpenObject Client")
00180 license = KAboutData.License_GPL
00181 copyright = ki18n ("(c) 2009 Albert Cervera i Areny")
00182 text = ki18n ("none")
00183 homePage = "www.nan-tic.com"
00184 bugEmail = "albert@nan-tic.com"
00185
00186 aboutData = KAboutData (appName, catalog, programName, version, description,
00187 license, copyright, text, homePage, bugEmail)
00188
00189 KCmdLineArgs.init (arguments, aboutData)
00190
00191 app = KApplication ()
00192 else:
00193 app = QApplication( arguments )
00194
00195 app.setApplicationName( 'Koo POS' )
00196 app.setOrganizationDomain( 'www.NaN-tic.com' )
00197 app.setOrganizationName( 'NaN' )
00198
00199 try:
00200 f = open( Settings.value('koo.stylesheet'), 'r' )
00201 try:
00202 app.setStyleSheet( f.read() )
00203 finally:
00204 f.close()
00205 except:
00206 pass
00207
00208 Localization.initializeQtTranslations(Settings.value('client.language'))
00209
00210
00211 from Koo.Dialogs.KooMainWindow import *
00212 from Koo.Dialogs.WindowService import *
00213 import Koo.Actions
00214
00215 mainWindow = QMainWindow(None, Qt.CustomizeWindowHint)
00216
00217 from Koo.Common import Api
00218
00219 class KooApi(Api.KooApi):
00220 def execute(self, actionId, data={}, type=None, context={}):
00221 Koo.Actions.execute( actionId, data, type, context )
00222
00223 def executeReport(self, name, data={}, context={}):
00224 return Koo.Actions.executeReport( name, data, context )
00225
00226 def executeAction(self, action, data={}, context={}):
00227 Koo.Actions.executeAction( action, data, context )
00228
00229 def executeKeyword(self, keyword, data={}, context={}):
00230 return Koo.Actions.executeKeyword( keyword, data, context )
00231
00232 def createWindow(self, view_ids, model, res_id=False, domain=None,
00233 view_type='form', window=None, context=None, mode=None, name=False, autoReload=False,
00234 target='current'):
00235 WindowService.createWindow( view_ids, model, res_id, domain,
00236 view_type, window, context, mode, name, autoReload, target )
00237
00238 def windowCreated(self, window, target):
00239 mainWindow.setCentralWidget( window )
00240 window.setParent( mainWindow )
00241 window.show()
00242
00243 Api.instance = KooApi()
00244
00245 mainWindow.showFullScreen()
00246
00247
00248
00249
00250 if Settings.value('koo.pos_mode'):
00251 import Koo.Pos
00252 app.installEventFilter( Koo.Pos.PosEventFilter(mainWindow) )
00253
00254 if Settings.value('koo.enter_as_tab'):
00255 from Koo.Common import EnterEventFilter
00256 app.installEventFilter( EnterEventFilter.EnterEventFilter(mainWindow) )
00257
00258 from Koo.Common import ArrowsEventFilter
00259 app.installEventFilter( ArrowsEventFilter.ArrowsEventFilter(mainWindow) )
00260
00261 from Koo.Common import WhatsThisEventFilter
00262 app.installEventFilter( WhatsThisEventFilter.WhatsThisEventFilter(mainWindow) )
00263
00264 app.installEventFilter( KeyPressEventFilter(mainWindow) )
00265
00266
00267 if not Settings.value( 'login.url'):
00268 sys.exit( "Error: No connection parameters given." )
00269 if not Settings.value( 'login.db'):
00270 sys.exit( "Error: No database given." )
00271
00272 Rpc.session.login( Settings.value('login.url'), Settings.value('login.db') )
00273
00274 if not Rpc.session.logged():
00275 sys.exit( "Error: Invalid credentials." )
00276
00277 id = Rpc.session.execute('/object', 'execute', 'res.users', 'read', [Rpc.session.uid], ['action_id','name'], Rpc.session.context)
00278
00279
00280
00281 menuId = id[0]['action_id'][0]
00282
00283 Api.instance.execute(menuId)
00284
00285 app.exec_()
00286