1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
33
from options import options
42
# Upgrade this number to force the client to ask the survey
46
def _search_file(file, dir='path.share'):
48
lambda x: os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), x),
49
lambda x: os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'pixmaps', x),
50
lambda x: os.path.join(options.options[dir],x),
58
terp_path = _search_file
59
terp_path_pixmaps = lambda x: _search_file(x, 'path.pixmaps')
61
OPENERP_ICON = gtk.gdk.pixbuf_new_from_file(
62
terp_path_pixmaps('openerp-icon.png'))
64
def selection(title, values, alwaysask=False, parent=None):
65
if not values or len(values)==0:
67
elif len(values)==1 and (not alwaysask):
68
key = values.keys()[0]
69
return (key, values[key])
71
xml = glade.XML(terp_path("openerp.glade"), "win_selection", gettext.textdomain())
72
win = xml.get_widget('win_selection')
74
parent = service.LocalService('gui.main').window
75
win.set_icon(OPENERP_ICON)
76
win.set_transient_for(parent)
78
label = xml.get_widget('win_sel_title')
82
list = xml.get_widget('win_sel_tree')
83
list.get_selection().set_mode('single')
84
cell = gtk.CellRendererText()
85
column = gtk.TreeViewColumn("Widget", cell, text=0)
86
list.append_column(column)
87
list.set_search_column(0)
88
model = gtk.ListStore(gobject.TYPE_STRING)
95
list.connect('row-activated', lambda x,y,z: win.response(gtk.RESPONSE_OK) or True)
102
if response == gtk.RESPONSE_OK:
103
sel = list.get_selection().get_selected()
107
res = model.get_value(iter, 0)
108
res = (res, values[res])
119
class upload_data_thread(threading.Thread):
120
def __init__(self, email, data, type, supportid):
121
self.args = [('email',email),('type',type),('supportid',supportid),('data',data)]
122
super(upload_data_thread,self).__init__()
126
args = urllib.urlencode(self.args)
127
fp = urllib.urlopen('http://www.openerp.com/scripts/survey.php', args)
133
def upload_data(email, data, type='SURVEY', supportid=''):
134
a = upload_data_thread(email, data, type, supportid)
139
if options.options['survey.position']==SURVEY_VERSION:
142
widnames = ('country','role','industry','employee','hear','system','opensource')
143
winglade = glade.XML(common.terp_path("openerp.glade"), "dia_survey", gettext.textdomain())
144
win = winglade.get_widget('dia_survey')
145
parent = service.LocalService('gui.main').window
146
win.set_transient_for(parent)
147
win.set_icon(OPENERP_ICON)
148
for widname in widnames:
149
wid = winglade.get_widget('combo_'+widname)
150
wid.child.set_text('(choose one)')
151
wid.child.set_editable(False)
153
if res==gtk.RESPONSE_OK:
154
email = winglade.get_widget('entry_email').get_text()
155
company = winglade.get_widget('entry_company').get_text()
156
result = "\ncompany: "+str(company)
157
for widname in widnames:
158
wid = winglade.get_widget('combo_'+widname)
159
result += "\n"+widname+": "+wid.child.get_text()
160
result += "\nplan_use: "+str(winglade.get_widget('check_use').get_active())
161
result += "\nplan_sell: "+str(winglade.get_widget('check_sell').get_active())
163
buffer = winglade.get_widget('textview_comment').get_buffer()
164
iter_start = buffer.get_start_iter()
165
iter_end = buffer.get_end_iter()
166
result += "\nnote: "+buffer.get_text(iter_start,iter_end,False)
169
upload_data(email, result, type='SURVEY '+str(SURVEY_VERSION))
170
options.options['survey.position']=SURVEY_VERSION
172
common.message(_('Thank you for the feedback !\nYour comments have been sent to OpenERP.\nYou should now start by creating a new database or\nconnecting to an existing server through the "File" menu.'))
176
common.message(_('Thank you for testing OpenERP !\nYou should now start by creating a new database or\nconnecting to an existing server through the "File" menu.'))
180
def file_selection(title, filename='', parent=None,
181
action=gtk.FILE_CHOOSER_ACTION_OPEN, preview=True, multi=False, filters=None):
182
if action == gtk.FILE_CHOOSER_ACTION_OPEN:
183
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
184
gtk.STOCK_OPEN,gtk.RESPONSE_OK)
186
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
187
gtk.STOCK_SAVE, gtk.RESPONSE_OK)
188
win = gtk.FileChooserDialog(title, None, action, buttons)
190
parent = service.LocalService('gui.main').window
191
win.set_transient_for(parent)
192
win.set_icon(OPENERP_ICON)
193
win.set_current_folder(options.options['client.default_path'])
194
win.set_select_multiple(multi)
195
win.set_default_response(gtk.RESPONSE_OK)
196
if filters is not None:
197
for filter in filters:
198
win.add_filter(filter)
200
win.set_current_name(filename)
202
def update_preview_cb(win, img):
203
filename = win.get_preview_filename()
205
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, 128, 128)
206
img.set_from_pixbuf(pixbuf)
210
win.set_preview_widget_active(have_preview)
214
img_preview = gtk.Image()
215
win.set_preview_widget(img_preview)
216
win.connect('update-preview', update_preview_cb, img_preview)
219
if button!=gtk.RESPONSE_OK:
223
filepath = win.get_filename()
225
filepath = filepath.decode('utf-8')
227
options.options['client.default_path'] = os.path.dirname(filepath)
234
filenames = win.get_filenames()
236
filenames = [x.decode('utf-8') for x in filenames]
238
options.options['client.default_path'] = os.path.dirname(filenames[0])
247
wid_list = ['email_entry','id_entry','name_entry','phone_entry','company_entry','error_details','explanation_textview','remark_textview']
248
required_wid = ['email_entry', 'name_entry', 'company_name', 'id_entry']
249
support_id = options['support.support_id']
250
recipient = options['support.recipient']
252
sur = glade.XML(terp_path("openerp.glade"), "dia_support",gettext.textdomain())
253
win = sur.get_widget('dia_support')
254
parent = service.LocalService('gui.main').window
255
win.set_transient_for(parent)
256
win.set_icon(OPENERP_ICON)
258
sur.get_widget('id_entry1').set_text(support_id)
261
if response == gtk.RESPONSE_OK:
262
fromaddr = sur.get_widget('email_entry1').get_text()
263
id_contract = sur.get_widget('id_entry1').get_text()
264
name = sur.get_widget('name_entry1').get_text()
265
phone = sur.get_widget('phone_entry1').get_text()
266
company = sur.get_widget('company_entry1').get_text()
268
urgency = sur.get_widget('urgency_combo1').get_active_text()
270
buffer = sur.get_widget('explanation_textview1').get_buffer()
271
explanation = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
273
buffer = sur.get_widget('remark_textview').get_buffer()
274
remarks = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
276
content = name +"(%s, %s, %s)"%(id_contract, company, phone) +" has reported the following bug:\n"+ explanation + "\nremarks:\n" + remarks
278
if upload_data(fromaddr, content, 'support', id_contract):
279
common.message(_('Support request sent !'))
285
def error(title, message, details='', parent=None):
286
log = logging.getLogger('common.message')
287
log.error('MSG %s: %s' % (str(message),details))
289
wid_list = ['email_entry','id_entry','name_entry','phone_entry','company_entry','error_details','explanation_textview','remarks_textview']
290
required_wid = ['email_entry', 'name_entry', 'company_name', 'id_entry']
291
colors = {'invalid':'#ffdddd', 'readonly':'grey', 'required':'#ddddff', 'normal':'white'}
293
support_id = options['support.support_id']
294
recipient = options['support.recipient']
296
sur = glade.XML(terp_path("openerp.glade"), "win_error",gettext.textdomain())
297
win = sur.get_widget('win_error')
299
parent=service.LocalService('gui.main').window
300
win.set_transient_for(parent)
301
win.set_icon(OPENERP_ICON)
302
sur.get_widget('error_title').set_text(str(title))
303
sur.get_widget('error_info').set_text(str(message))
304
buf = gtk.TextBuffer()
305
buf.set_text(unicode(details,'latin1').encode('utf-8'))
306
sur.get_widget('error_details').set_buffer(buf)
308
sur.get_widget('id_entry').set_text(support_id)
313
fromaddr = sur.get_widget('email_entry').get_text()
314
id_contract = sur.get_widget('id_entry').get_text()
315
name = sur.get_widget('name_entry').get_text()
316
phone = sur.get_widget('phone_entry').get_text()
317
company = sur.get_widget('company_entry').get_text()
319
urgency = sur.get_widget('urgency_combo').get_active_text()
321
buffer = sur.get_widget('error_details').get_buffer()
322
traceback = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
324
buffer = sur.get_widget('explanation_textview').get_buffer()
325
explanation = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
327
buffer = sur.get_widget('remarks_textview').get_buffer()
328
remarks = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
330
content = "(%s, %s, %s)"%(id_contract, company, phone) +" has reported the following bug:\n"+ explanation + "\nremarks: " + remarks + "\nThe traceback is:\n" + traceback
332
if upload_data(fromaddr, content, 'error', id_contract):
333
common.message(_('Support request sent !'))
336
sur.signal_connect('on_button_send_clicked', send)
337
sur.signal_connect('on_closebutton_clicked', lambda x : win.destroy())
344
def message(msg, type=gtk.MESSAGE_INFO, parent=None):
346
parent=service.LocalService('gui.main').window
347
dialog = gtk.MessageDialog(parent,
348
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
349
type, gtk.BUTTONS_OK,
351
dialog.set_icon(OPENERP_ICON)
358
return s.replace('&','&').replace('<','<').replace('>','>')
360
def message_box(title, msg, parent=None):
361
dia = glade.XML(terp_path("openerp.glade"), "dia_message_box",gettext.textdomain())
362
win = dia.get_widget('dia_message_box')
363
l = dia.get_widget('msg_title')
366
buffer = dia.get_widget('msg_tv').get_buffer()
367
iter_start = buffer.get_start_iter()
368
buffer.insert(iter_start, msg)
371
parent=service.LocalService('gui.main').window
372
win.set_transient_for(parent)
373
win.set_icon(OPENERP_ICON)
381
def warning(msg, title='', parent=None):
383
parent=service.LocalService('gui.main').window
384
dialog = gtk.MessageDialog(parent, gtk.DIALOG_DESTROY_WITH_PARENT,
385
gtk.MESSAGE_WARNING, gtk.BUTTONS_OK)
386
dialog.set_icon(OPENERP_ICON)
387
dialog.set_markup('<b>%s</b>\n\n%s' % (to_xml(title),to_xml(msg)))
394
def sur(msg, parent=None):
396
parent=service.LocalService('gui.main').window
397
sur = glade.XML(terp_path("openerp.glade"), "win_sur",gettext.textdomain())
398
win = sur.get_widget('win_sur')
399
win.set_transient_for(parent)
401
l = sur.get_widget('lab_question')
405
parent=service.LocalService('gui.main').window
406
win.set_transient_for(parent)
407
win.set_icon(OPENERP_ICON)
412
return response == gtk.RESPONSE_OK
414
def sur_3b(msg, parent=None):
415
sur = glade.XML(terp_path("openerp.glade"), "win_quest_3b",gettext.textdomain())
416
win = sur.get_widget('win_quest_3b')
417
l = sur.get_widget('label')
421
parent=service.LocalService('gui.main').window
422
win.set_transient_for(parent)
423
win.set_icon(OPENERP_ICON)
428
if response == gtk.RESPONSE_YES:
430
elif response == gtk.RESPONSE_NO:
432
elif response == gtk.RESPONSE_CANCEL:
438
theme = options['client.theme']
439
if theme and (theme <> 'none'):
440
fname = os.path.join("themes", theme, "gtkrc")
441
if not os.path.isfile(fname):
442
common.warning('File not found: '+fname+'\nSet theme to none in ~/.openerprc', 'Error setting theme')
444
gtk.rc_parse("themes/"+theme+"/gtkrc")
447
def ask(question, parent=None):
448
dia = glade.XML(terp_path('openerp.glade'), 'win_quest', gettext.textdomain())
449
win = dia.get_widget('win_quest')
450
label = dia.get_widget('label1')
451
label.set_text(question)
452
entry = dia.get_widget('entry')
455
parent=service.LocalService('gui.main').window
456
win.set_transient_for(parent)
457
win.set_icon(OPENERP_ICON)
462
if response == gtk.RESPONSE_CANCEL:
465
return entry.get_text()
467
def concurrency(resource, id, context, parent=None):
468
dia = glade.XML(common.terp_path("openerp.glade"),'dialog_concurrency_exception',gettext.textdomain())
469
win = dia.get_widget('dialog_concurrency_exception')
472
parent=service.LocalService('gui.main').window
473
win.set_transient_for(parent)
474
win.set_icon(OPENERP_ICON)
480
if res == gtk.RESPONSE_OK:
482
if res == gtk.RESPONSE_APPLY:
483
obj = service.LocalService('gui.window')
484
obj.create(False, resource, id, [], 'form', None, context,'form,tree')
487
def open_file(value, parent):
489
if options['client.filetype']:
490
if isinstance(options['client.filetype'], str):
491
filetype = eval(options['client.filetype'])
493
filetype = options['client.filetype']
494
root, ext = os.path.splitext(value)
496
if ext[1:] in filetype:
497
cmd = filetype[ext[1:]] % (value)
499
cmd = file_selection(_('Open with...'),
503
filetype[ext[1:]] = cmd
504
options['client.filetype'] = filetype
512
prog, args = cmd.split(' ', 1)
513
args = [os.path.basename(prog)] + args.split(' ')
515
os.execvp(prog, args)
527
'readonly':'#eeebe7',
528
'required':'#d2d2ff',
534
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: