1
from processors import *
2
from opt_processors import *
6
from dialogs import ShowDialog, MakePropertyPage#, ShowWizard
14
import win32gui_struct
20
except NameError: # enumerate new in 2.3
22
return [(i, seq[i]) for i in xrange(len(seq))]
24
BIF_NEWDIALOGSTYLE = 0x00000040
25
BIF_NONEWFOLDERBUTTON = 0x0000200
26
CSIDL_COMMONMYPICTURES = 0x00000036
28
class _WIN32MASKEDSTRUCT:
29
def __init__(self, **kw):
31
for name, fmt, default, mask in self._struct_items_:
32
self.__dict__[name] = None
37
for name, val in kw.iteritems():
38
if name not in self.__dict__:
39
raise ValueError("LVITEM structures do not have an item '%s'" % (name,))
40
self.__dict__[name] = val
42
def __setattr__(self, attr, val):
43
if not attr.startswith("_") and attr not in self.__dict__:
44
raise AttributeError(attr)
45
self.__dict__[attr] = val
53
for name, fmt, default, this_mask in self._struct_items_:
54
if this_mask is not None and self.__dict__.get(name) is not None:
57
for name, fmt, default, this_mask in self._struct_items_:
58
val = self.__dict__[name]
65
# Note this demo still works with byte strings. An
66
# alternate strategy would be to use unicode natively
67
# and use the 'W' version of the messages - eg,
70
if isinstance(val, unicode):
71
val = val.encode("mbcs")
72
str_buf = array.array("b", val)
73
vals.append(str_buf.buffer_info()[0])
75
self._buffs.append(str_buf) # keep alive during the call.
81
return struct.pack(*(full_fmt,) + tuple(vals))
84
# NOTE: See the win32gui_struct module for an alternative way of dealing
85
# with these structures
86
class LVITEM(_WIN32MASKEDSTRUCT):
88
("mask", "I", 0, None),
89
("iItem", "i", 0, None),
90
("iSubItem", "i", 0, None),
91
("state", "I", 0, commctrl.LVIF_STATE),
92
("stateMask", "I", 0, None),
93
("text", "z", None, commctrl.LVIF_TEXT),
94
("iImage", "i", 0, commctrl.LVIF_IMAGE),
95
("lParam", "i", 0, commctrl.LVIF_PARAM),
96
("iIdent", "i", 0, None),
97
("cchTextMax", "i", 0, 255),
98
("pszText", "i", 0, None),
99
("flags", "i", 0, None),
102
class LVCOLUMN(_WIN32MASKEDSTRUCT):
104
("mask", "I", 0, None),
105
("fmt", "i", 0, commctrl.LVCF_FMT),
106
("cx", "i", 0, commctrl.LVCF_WIDTH),
107
("text", "z", None, commctrl.LVCF_TEXT),
108
("iSubItem", "i", 0, commctrl.LVCF_SUBITEM),
109
("iImage", "i", 0, commctrl.LVCF_IMAGE),
110
("iOrder", "i", 0, commctrl.LVCF_ORDER),
114
flag_stop=win32con.MB_ICONSTOP
117
flag_error=win32con.MB_ICONERROR
120
flag_info=win32con.MB_ICONINFORMATION
123
flag_excl=win32con.MB_ICONEXCLAMATION
126
NewConn=addin.GetConn()
128
## Retrieves current XMLRPC connection
132
global objects_with_match
133
objects_with_match=[]
139
search_text='search_text'
147
server = NewConn._server
150
if not NewConn._running:
151
win32ui.MessageBox("No server running on host "+ server+" at port "+str(port), "Server Connection", flag_excl)
153
if not NewConn._login:
154
win32ui.MessageBox("Please login to the database first", "Database Connection", flag_excl)
159
def resetConnAttribs(window):
160
config = window.manager.LoadConfig()
161
NewConn._server = config['server']
162
NewConn._port = config['port']
163
NewConn._uri = "http://" + config['server'] + ":" + str(config['port'])
164
NewConn._obj_list = config['objects']
165
NewConn._dbname = config['database']
166
NewConn._uname = config['uname']
167
NewConn._pwd = config['pwd']
168
NewConn._login = config['login']
171
def setConnAttribs(server, port, manager):
172
uri = 'http://' + server + ":" + str(port)
173
NewConn.__init__(server,port,uri)
175
manager.config = manager.LoadConfig()
176
NewConn._obj_list = manager.config['objects']
177
NewConn._dbname = manager.config['database']
178
NewConn._uname = manager.config['uname']
179
NewConn._pwd = manager.config['pwd']
180
NewConn._login = manager.config['login']
183
def getConnAttributes(manager):
184
manager.config['server'] = NewConn._server
185
manager.config['port'] = NewConn._port
186
manager.config['objects'] = NewConn._obj_list
187
manager.config['database'] = NewConn._dbname
188
manager.config['uname'] = NewConn._uname
189
manager.config['pwd'] = NewConn._pwd
190
manager.config['login'] = NewConn._login
194
print "Exception %s: %s"%(type(e),str(e))
196
if type(e) == pywintypes.com_error:
197
msg="Access to the mail Denied"
198
elif type(e) == xmlrpclib.Fault:
199
msg = str(e.faultCode) or e.faultString or e.message or str(e)
201
if hasattr(e, 'faultCode') and e.faultCode:
202
msg = str(e.faultCode)
203
elif hasattr(e, 'faultString') and e.faultString:
205
elif hasattr(e, 'message') and e.message:
209
class OKButtonProcessor(ButtonProcessor):
210
def __init__(self, window, control_ids):
211
self.mngr = window.manager
212
ControlProcessor.__init__(self, window, control_ids)
214
def OnClicked(self, id):
215
server = win32gui.GetDlgItemText(self.window.hwnd, self.other_ids[0])
217
port = int(win32gui.GetDlgItemText(self.window.hwnd, self.other_ids[1]))
218
except ValueError, e:
219
print "Exception %s: %s"%str(e)
220
win32ui.MessageBox("Port should be an integer", "Error", flag_excl)
224
win32ui.MessageBox(msg, "Error", flag_excl)
226
setConnAttribs(server, port, self.mngr)
227
if NewConn._running == False:
228
msg = "No server running on host '%s' at port '%d'. Press ignore to still continue with this configuration?"%(server,port)
229
r=win32ui.MessageBox(msg, "Server Connection", win32con.MB_ABORTRETRYIGNORE | win32con.MB_ICONQUESTION)
231
resetConnAttribs(self.window)
236
setConnAttribs(server, port, self.mngr)
237
win32gui.EndDialog(self.window.hwnd, id)
239
class DoneButtonProcessor(ButtonProcessor):
240
def OnClicked(self, id):
241
getConnAttributes(self.window.manager)
242
self.window.manager.SaveConfig()
243
win32gui.EndDialog(self.window.hwnd, id)
245
class MessageProcessor(ControlProcessor):
247
text = "This Outlook Plugin for OpenERP has been developed by TinyERP \n\n \
248
For more information, please visit our website \n \
249
http://www.openerp.com \n\n \
251
sales@tinyerp.com \n\n \
252
2001-TODAY Tiny sprl. All rights reserved. \n"
253
win32gui.SendMessage(self.GetControl(), win32con.WM_SETTEXT, 0, text)
255
def GetPopupHelpText(self, cid):
256
return "Displays details on this plugin"
258
class TabProcessor(ControlProcessor):
259
def __init__(self, window, control_ids, page_ids):
260
ControlProcessor.__init__(self, window, control_ids)
261
self.page_ids = page_ids.split()
265
self.currentPage = None
266
self.currentPageIndex = -1
267
self.currentPageHwnd = None
268
for index, page_id in enumerate(self.page_ids):
269
template = self.window.manager.dialog_parser.dialogs[page_id]
270
self.addPage(index, page_id, template[0][0])
271
server = self.window.manager.config['server']
272
port = self.window.manager.config['port']
273
setConnAttribs(server, port, self.window.manager)
277
if self.currentPageHwnd is not None:
278
if not self.currentPage.SaveAllControls():
279
win32gui.SendMessage(self.GetControl(), commctrl.TCM_SETCURSEL, self.currentPageIndex,0)
283
def OnNotify(self, nmhdr, wparam, lparam):
284
selChangedCode = 5177342
286
if code==selChangedCode:
287
index = win32gui.SendMessage(self.GetControl(), commctrl.TCM_GETCURSEL, 0,0)
288
if index!=self.currentPageIndex:
289
self.switchToPage(index)
291
def switchToPage(self, index):
292
if self.currentPageHwnd is not None:
293
if not self.currentPage.SaveAllControls():
294
win32gui.SendMessage(self.GetControl(), commctrl.TCM_SETCURSEL, self.currentPageIndex,0)
296
win32gui.DestroyWindow(self.currentPageHwnd)
297
self.currentPage = MakePropertyPage(self.GetControl(), self.window.manager, self.window.config, self.pages[index])
298
self.currentPageHwnd = self.currentPage.CreateWindow()
299
self.currentPageIndex = index
302
def addPage(self, item, idName, label):
304
lbuf = win32gui.PyMakeBuffer(len(label)+1)
305
address,l = win32gui.PyGetBufferAddressAndLen(lbuf)
306
win32gui.PySetString(address, label)
308
buf = struct.pack(format,
309
commctrl.TCIF_TEXT, # mask
317
item = win32gui.SendMessage(self.GetControl(),
318
commctrl.TCM_INSERTITEM,
321
self.pages[item] = idName
323
class DialogCommand(ButtonProcessor):
324
def __init__(self, window, control_ids, idd, func=None, args=()):
328
ButtonProcessor.__init__(self, window, control_ids)
330
def OnClicked(self, id):
333
args = (self, ) + self.args
335
parent = self.window.hwnd
336
self.window.SaveAllControls()
337
ShowDialog(parent, self.window.manager, self.window.config, self.idd)
338
self.window.LoadAllControls()
340
def GetPopupHelpText(self, id):
341
dd = self.window.manager.dialog_parser.dialogs[self.idd]
342
return "Displays the %s dialog" % dd.caption
343
def ReloadAllControls(btnProcessor,*args):
344
server = NewConn._server
346
btnProcessor.window.LoadAllControls()
347
if not NewConn._running:
348
win32ui.MessageBox("No server running on host "+ server+" at port "+str(port), "Server Connection", flag_excl)
350
def TestConnection(btnProcessor,*args):
351
server = NewConn._server
354
if not NewConn._running:
355
btnProcessor.window.LoadAllControls()
356
win32ui.MessageBox("No server running on host "+ server+" at port "+str(port), "Server Connection", flag_excl)
359
dbname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, 7000)
361
win32ui.MessageBox("Please enter database name", "", flag_excl)
364
print "Exception %s: %s"%(type(e),str(e))
365
dbname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
367
win32ui.MessageBox("No database found on host "+ server+" at port "+str(port), "Database Connection", flag_excl)
370
uname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
371
pwd = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2])
374
win32ui.MessageBox("Enter Username", "", flag_excl)
377
win32ui.MessageBox("Enter Password", "", flag_excl)
380
#Establish Connection
382
uid = NewConn.login(dbname, uname, pwd)
384
msg = "Connection Successful"
385
NewConn._login = True
386
NewConn._uname = uname
390
if not NewConn.IsCRMInstalled():
391
msg+= '\n\n'+" 'CRM' module is not installed. So CRM cases cannot be created."
392
NewConn._iscrm = False
395
list = NewConn.GetCSList()
396
NewConn._iscrm = True
398
msg+= '\n\n'+"CRM cases cannot be created.\n\n" + getMessage(e)
399
NewConn._iscrm = False
401
msg = "Connection Failed. Please check Username or Password"
403
NewConn._login = False
405
msg = "Connection could not be made.\n\n" + getMessage(e)
407
win32ui.MessageBox(msg, "Database Connection", flag_excl)
410
def BrowseCallbackProc(hwnd, msg, lp, data):
411
from win32com.shell import shell, shellcon
412
if msg== shellcon.BFFM_INITIALIZED:
413
win32gui.SendMessage(hwnd, shellcon.BFFM_SETSELECTION, 1, data)
414
win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0)
415
elif msg == shellcon.BFFM_SELCHANGED:
416
# Set the status text of the
417
# For this message, 'lp' is the address of the PIDL.
418
pidl = shell.AddressAsPIDL(lp)
420
path = shell.SHGetPathFromIDList(pidl)
421
if os.path.isdir(path):
422
win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0)
424
ext = path.split('.')[-1]
425
if ext not in ['gif', 'bmp', 'jpg', 'tif', 'ico']:
426
win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 0)
429
win32gui.SendMessage(hwnd, shellcon.BFFM_ENABLEOK, 0, 1)
431
# No path for this PIDL
434
def GetImagePath(btnProcessor,*args):
435
from win32com.shell import shell, shellcon
436
ulFlags = shellcon.BIF_BROWSEINCLUDEFILES | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON
437
pidl, display_name, image_list=shell.SHBrowseForFolder(btnProcessor.window.hwnd, # parent HWND
439
"Get the image path", # title
441
BrowseCallbackProc, # callback function
442
os.getcwd() # 'data' param for the callback
444
if (pidl, display_name, image_list) == (None, None, None):
447
path = shell.SHGetPathFromIDList (pidl)
448
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0], path)
450
def AddNewObject(btnProcessor,*args):
451
#Check if server running or user logged in
456
#Check if title or object not specified
457
obj_title = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
458
obj_name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
460
win32ui.MessageBox("No Title specified", "", flag_excl)
463
win32ui.MessageBox("No object specified", "", flag_excl)
466
#Check if object does not exist in the database or it already exist in the list
468
all_obj_list = NewConn.GetAllObjects()
469
curr_obj_list = [obj[1] for obj in NewConn.GetObjList()]
470
curr_title_list = [obj[0] for obj in NewConn.GetObjList()]
471
if obj_name not in all_obj_list:
472
win32ui.MessageBox("No such object exists", "Object Settings", flag_excl)
474
elif obj_name in curr_obj_list:
475
win32ui.MessageBox("Object already in the list", "Object Settings", flag_info)
477
elif obj_title in curr_title_list:
478
win32ui.MessageBox("Title already in the list. Please give different title", "Object Settings", flag_excl)
481
#extract image path and load the image
483
image_path = os.path.join(btnProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp")
484
path=win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2])
487
load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT
489
hicon = win32gui.LoadImage(0, image_path,win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags)
493
win32ui.MessageBox(msg, "Load Image", flag_error)
495
#Add the object in the list
496
win32gui.ImageList_Add(il,hicon,0)
497
cnt = win32gui.ImageList_GetImageCount(il)
499
hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[3])
500
num_items = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMCOUNT)
502
item = LVITEM(text=obj_title, iImage=cnt-2, iItem = num_items)
503
new_index = win32gui.SendMessage(hwndList, commctrl.LVM_INSERTITEM, 0, item.toparam())
504
win32gui.SendMessage(hwndList, commctrl.LVM_SETIMAGELIST, commctrl.LVSIL_SMALL, il)
505
item = LVITEM(text=obj_name, iItem = new_index, iSubItem = 1)
506
win32gui.SendMessage(hwndList, commctrl.LVM_SETITEM, 0, item.toparam())
508
NewConn.InsertObj(obj_title,obj_name,image_path)
510
msg = "Object not added\n\n" + getMessage(e)
511
win32ui.MessageBox(msg,"",flag_excl)
514
#Empty all the text controls
515
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0], '')
516
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1], '')
517
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2], '')
519
def DeleteSelectedObjects(btnProcessor,*args):
520
#Check if server running or user logged in
525
#Delete selected items
526
hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
527
sel_count = win32gui.SendMessage(hwndList, commctrl.LVM_GETSELECTEDCOUNT)
528
for i in range(0,sel_count):
529
sel = win32gui.SendMessage(hwndList, commctrl.LVM_GETNEXTITEM, -1, commctrl.LVNI_SELECTED)
530
buf,extra = win32gui_struct.EmptyLVITEM(1, 0)
531
r = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMTEXT, sel, buf)
534
nombre = n.tostring()
535
sel_text = nombre[0:r]
536
s = win32gui.SendMessage(hwndList, commctrl.LVM_DELETEITEM, sel)
538
NewConn.DeleteObject(sel_text)
540
msg = "Object '%s' not deleted\n\n"%sel_text + getMessage(e)
541
win32ui.MessageBox(msg,"",flag_excl)
543
def GetMail(processor):
544
ex = processor.window.manager.outlook.ActiveExplorer()
545
assert ex.Selection.Count == 1
546
mail = ex.Selection.Item(1)
549
#get selected records from list
550
def GetSelectedItems(hwndList):
552
sel_count = win32gui.SendMessage(hwndList, commctrl.LVM_GETSELECTEDCOUNT)
554
for i in range(0,sel_count):
555
sel = win32gui.SendMessage(hwndList, commctrl.LVM_GETNEXTITEM, sel, commctrl.LVNI_SELECTED)
556
buf,extra = win32gui_struct.EmptyLVITEM(1, 0)
557
size = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMTEXT, sel, buf)
560
nombre = n.tostring()
561
sel_text = nombre[0:size]
562
for item in objects_with_match:
563
if item[2] == sel_text:
567
def MakeAttachment(btnProcessor,*args):
568
#Check if server running or user logged in
573
ex = btnProcessor.window.manager.outlook.ActiveExplorer()
574
assert ex.Selection.Count == 1
575
mail = ex.Selection.Item(1)
576
mail = GetMail(btnProcessor)
578
#get selected records
579
hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
580
r = GetSelectedItems(hwndList)
582
win32ui.MessageBox("No records selected", "Make Attachment", flag_info)
586
NewConn.ArchiveToOpenERP(r,mail)
587
msg="Mail archived to OpenERP."
590
msg = "Attachment not created \n\n" + getMessage(e)
592
win32ui.MessageBox(msg, "Make Attachment", flag)
596
def CreateCase(btnProcessor,*args):
597
#Check if server running or user logged in
603
# Get the selected mail
604
ex = btnProcessor.window.manager.outlook.ActiveExplorer()
605
assert ex.Selection.Count == 1
606
mail = ex.Selection.Item(1)
607
section = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
610
win32ui.MessageBox("CRM Case could not be created. No CRM Sections found. Please configure database first.", "Create Case", flag_excl)
613
hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
615
r = GetSelectedItems(hwndList)
617
if rec[0] == 'res.partner':
618
partner_ids.append(rec[1])
622
NewConn.CreateCase(section, mail, partner_ids)
623
msg="New case created."
626
msg="CRM Case not created \n\n"+getMessage(e)
628
win32ui.MessageBox(msg, "Create Case", flag)
631
win32ui.MessageBox("CRM Cases can not be created.", "Create Case", flag_info)
633
def GetSearchText(txtProcessor,*args):
634
#Check if server running or user logged in
639
search_box = txtProcessor.GetControl()
641
if txtProcessor.init_done:
642
win32gui.SendMessage(search_box, win32con.WM_SETTEXT, 0,search_text)
645
# Get the selected mail and set the default value for search_text_control to mail.SenderEmailAddress
646
ex = txtProcessor.window.manager.outlook.ActiveExplorer()
647
assert ex.Selection.Count == 1
648
mail = ex.Selection.Item(1)
650
search_text = str(mail.SenderEmailAddress)
653
win32gui.SendMessage(search_box, win32con.WM_SETTEXT, 0, search_text)
654
txtProcessor.init_done=True
656
def SetNameColumn(listProcessor,*args):
657
hwndList = listProcessor.GetControl()
658
child_ex_style = win32gui.SendMessage(hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
659
child_ex_style |= commctrl.LVS_EX_FULLROWSELECT
660
win32gui.SendMessage(hwndList, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, child_ex_style)
664
mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | \
665
commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM
667
lvc.fmt = commctrl.LVCFMT_LEFT
671
win32gui.SendMessage(hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
672
listProcessor.init_done = True
674
def setList(list_hwnd):
675
# Set default list of objects
676
win32gui.SendMessage(list_hwnd, commctrl.LVM_DELETEALLITEMS)
677
for obj in objects_with_match:
678
num_items = win32gui.SendMessage(list_hwnd, commctrl.LVM_GETITEMCOUNT)
679
item = LVITEM(text=obj[2],iItem = num_items)
680
win32gui.SendMessage(list_hwnd, commctrl.LVM_INSERTITEM, 0, item.toparam())
682
def SearchObjectsForText(btnProcessor,*args):
683
#Check if server running or user logged in
688
search_txt = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
690
win32ui.MessageBox("Enter text to search for", "", flag_info)
692
# Get titles from list
694
for ch in hwndChk_list:
697
chk = win32gui.SendMessage(hwnd, win32con.BM_GETCHECK)
699
txt = win32gui.GetDlgItemText(btnProcessor.window.hwnd,id)
700
obj_titles.append(txt)
702
# Prepare list of objects to search for the seach_keyword
703
obj_list = btnProcessor.window.manager.config['objects']
706
all_obj_list = NewConn.GetAllObjects()
707
for title in obj_titles:
708
objname = [obj[1] for obj in obj_list if obj[0] == title]
710
assert len(objname) == 1
711
if objname[0] in all_obj_list:
712
search_list.append(objname[0])
714
win32ui.MessageBox("Module %s (%s) not installed. Please install it." \
715
%(title,objname[0]), "", flag_excl)
718
# Get the records by searching the objects in search_list for the search_keyword as objects_with_match
719
global objects_with_match
720
list_hwnd = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
722
objects_with_match = NewConn.GetObjectItems(search_list, search_txt)
723
if not objects_with_match:
724
win32ui.MessageBox("No matching records found in checked objects", "", flag_info)
726
win32ui.MessageBox("No object selected", "", flag_info)
727
objects_with_match=[]
728
# Display the objects_with_match records in list
732
win32ui.MessageBox(msg, "", flag_error)
734
def CreateContact(btnProcessor,*args):
739
partner = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[4])
740
combo = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[4])
741
sel = win32gui.SendMessage(combo, win32con.CB_GETCURSEL)
743
name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
744
email = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1])
745
office_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2])
746
mobile_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[3])
749
win32ui.MessageBox("Please enter name.", "Create Contact", flag_stop)
751
res = {'name':name, 'email':email, 'phone':office_no, 'mobile':mobile_no}
753
id = NewConn.CreateContact(sel, res)
754
msg="New contact created for partner '%s'."%partner
756
msg="Contact not created \n\n" + getMessage(e)
757
win32ui.MessageBox(msg, "Create Contact", flag_error)
760
win32ui.MessageBox(msg, "Create Contact", flag_info)
761
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0], '')
762
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1], '')
763
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2], '')
764
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[3], '')
766
def SetAllText(txtProcessor,*args):
767
# Set values for url, uname, pwd from config file
769
tbox = txtProcessor.GetControl()
770
win32gui.SendMessage(tbox, win32con.WM_SETTEXT, 0, url)
772
uname = NewConn._uname
773
tbox = txtProcessor.GetControl(txtProcessor.other_ids[0])
774
win32gui.SendMessage(tbox, win32con.WM_SETTEXT, 0, uname)
776
def SetDefaultList(listProcessor,*args):
777
hwndList = listProcessor.GetControl()
779
# set full row select style
780
child_ex_style = win32gui.SendMessage(hwndList, commctrl.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
781
child_ex_style |= commctrl.LVS_EX_FULLROWSELECT
782
win32gui.SendMessage(hwndList, commctrl.LVM_SETEXTENDEDLISTVIEWSTYLE, 0, child_ex_style)
786
mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | \
787
commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM
789
lvc.fmt = commctrl.LVCFMT_LEFT
791
lvc.text = "Object Name"
793
win32gui.SendMessage(hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
797
win32gui.SendMessage(hwndList, commctrl.LVM_INSERTCOLUMN, 0, lvc.toparam())
801
il = win32gui.ImageList_Create(
802
win32api.GetSystemMetrics(win32con.SM_CXSMICON),
803
win32api.GetSystemMetrics(win32con.SM_CYSMICON),
804
commctrl.ILC_COLOR32 | commctrl.ILC_MASK,
808
win32gui.SendMessage(hwndList, commctrl.LVM_SETIMAGELIST,\
809
commctrl.LVSIL_SMALL, il)
810
# Set objects from config
811
objs = NewConn._obj_list
812
load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT
814
image_path = os.path.join(listProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp")
819
hicon = win32gui.LoadImage(0, image_path,win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags)
821
msg = "Problem loading the image \n\n" + getMessage(e)
823
win32ui.MessageBox(msg, "Load Image", flag_error)
825
#Add the object in the list
826
win32gui.ImageList_Add(il,hicon,0)
827
cnt = win32gui.ImageList_GetImageCount(il)
828
num_items = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMCOUNT)
829
item = LVITEM(text=obj[0],iImage=cnt-2, iItem = num_items)
830
new_index = win32gui.SendMessage(hwndList, commctrl.LVM_INSERTITEM, 0, item.toparam())
831
item = LVITEM(text=obj[1], iItem = new_index, iSubItem = 1)
832
win32gui.SendMessage(hwndList, commctrl.LVM_SETITEM, 0, item.toparam())
834
def SetDefaultContact(txtProcessor,*args):
835
txt_name = txtProcessor.GetControl()
836
txt_email = txtProcessor.GetControl(txtProcessor.other_ids[0])
840
if txtProcessor.init_done:
841
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.control_id,name)
842
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[0],email)
846
mail = GetMail(txtProcessor)
847
name = mail.SenderName
848
email = mail.SenderEmailAddress
852
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.control_id,name)
853
win32gui.SetDlgItemText(txtProcessor.window.hwnd, txtProcessor.other_ids[0],email)
854
txtProcessor.init_done = True
856
# Set objects from config
857
def setCheckList(groupProcessor,*args):
858
child_style = win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP
859
hinst = win32gui.dllhandle
860
objs = groupProcessor.window.manager.config['objects']
866
load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT
867
if groupProcessor.init_done:
871
groupProcessor.init_done = True
873
hwndImg = win32gui.CreateWindowEx(0, "STATIC","",
874
win32con.SS_CENTERIMAGE | win32con.SS_REALSIZEIMAGE | win32con.SS_BITMAP | win32con.WS_CHILD | win32con.WS_VISIBLE,
876
groupProcessor.window.hwnd,
881
image_path = os.path.join(groupProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp")
885
hicon = win32gui.LoadImage(0, image_path, win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags)
887
msg="Problem loading the image \n\n" + getMessage(e)
889
win32ui.MessageBox(msg, "Load Image", flag_error)
891
win32gui.SendMessage(hwndImg, win32con.STM_SETIMAGE, win32con.IMAGE_BITMAP, hicon);
895
hwndChk = win32gui.CreateWindowEx(
896
0,"BUTTON",obj[0],win32con.WS_VISIBLE | win32con.WS_CHILD | \
897
win32con.BS_AUTOCHECKBOX | win32con.WS_TABSTOP | win32con.BST_CHECKED, \
898
left, top, 130,20,groupProcessor.window.hwnd,id1,hinst,None
900
if obj[1] in ['res.partner','res.partner.address']:
901
win32gui.SendMessage(hwndChk , win32con.BM_SETCHECK, 1, 0);
902
hwndChk_list.append((id1,hwndChk))
908
win32gui.UpdateWindow(hwndImg)
915
def CreatePartner(btnProcessor,*args):
916
#Check if server running or user logged in
921
partner_name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0])
923
win32ui.MessageBox("Please enter Partner name.", "Create Partner", flag_excl)
925
res = {'name':partner_name}
927
id = NewConn.CreatePartner(res)
929
msg="Partner not created \n\n" + getMessage(e)
930
win32ui.MessageBox(msg, "Create Partner", flag_error)
933
win32ui.MessageBox("New Partner '%s' created."%partner_name, "Create Partner", flag_info)
934
win32gui.EndDialog(btnProcessor.window.hwnd, btnProcessor.id)
936
win32ui.MessageBox("Partner '%s' already Exists."%partner_name, "Create Partner", flag_info)
937
win32gui.SetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0],'')
939
def set_search_text(dialogProcessor,*args):
941
search_text = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[0])
944
def set_name_email(dialogProcessor,*args):
947
name = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[0])
948
email = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[1])
952
(CancelButtonProcessor, "IDCANCEL", resetConnAttribs, ()),
953
(TabProcessor, "IDC_TAB IDC_LIST",
954
"""IDD_GENERAL IDD_OBJECT_SETTINGS IDD_ABOUT"""),
955
(DoneButtonProcessor, "ID_DONE"),
959
(DBComboProcessor, "ID_DB_DROPDOWNLIST", GetConn, ()),
960
(TextProcessor, "ID_SERVER_PORT ID_USERNAME ID_PASSWORD", SetAllText, ()),
961
(CommandButtonProcessor, "ID_BUT_TESTCONNECTION ID_DB_DROPDOWNLIST ID_USERNAME \
962
ID_PASSWORD", TestConnection, ()),
963
(CommandButtonProcessor, "IDC_RELOAD", ReloadAllControls, ()),
964
(DialogCommand, "IDC_BUT_SET_SERVER_PORT", "IDD_SERVER_PORT_DIALOG"),
967
"IDD_OBJECT_SETTINGS" : (
968
(CommandButtonProcessor, "IDC_BUT_LOAD_IMAGE IDC_IMAGE_PATH", GetImagePath, ()),
969
(CommandButtonProcessor, "IDC_BUT_SAVE_OBJECT IDC_OBJECT_TITLE IDC_OBJECT_NAME \
970
IDC_IMAGE_PATH IDC_LIST", AddNewObject, ()),
971
(CommandButtonProcessor, "IDC_BUT_DEL_OBJECT IDC_LIST", DeleteSelectedObjects, ()),
972
(ListBoxProcessor, "IDC_LIST", SetDefaultList, ())
976
(ImageProcessor, "IDB_OPENERPLOGO"),
977
(MessageProcessor, "IDC_ABOUT"),
980
"IDD_SERVER_PORT_DIALOG" : (
981
(CloseButtonProcessor, "IDCANCEL"),
982
(OKButtonProcessor, "IDOK ID_SERVER ID_PORT"),
986
(CommandButtonProcessor, "ID_SEARCH ID_SEARCH_TEXT IDC_NAME_LIST", SearchObjectsForText,()),
987
(GroupProcessor, "IDC_STATIC_GROUP", setCheckList, ()),
988
(CSComboProcessor, "ID_ATT_METHOD_DROPDOWNLIST", GetConn,()),
989
(TextProcessor, "ID_SEARCH_TEXT", GetSearchText, ()),
990
(DialogCommand, "ID_CREATE_CONTACT ID_SEARCH_TEXT", "IDD_NEW_CONTACT_DIALOG", set_search_text, ()),
991
(CloseButtonProcessor, "IDCANCEL"),
992
(CommandButtonProcessor, "ID_MAKE_ATTACHMENT IDC_NAME_LIST", MakeAttachment, ()),
993
(CommandButtonProcessor, "ID_CREATE_CASE ID_ATT_METHOD_DROPDOWNLIST IDC_NAME_LIST", CreateCase, ()),
994
(ListBoxProcessor, "IDC_NAME_LIST", SetNameColumn, ())
997
"IDD_NEW_CONTACT_DIALOG" : (
998
(PartnersComboProcessor, "ID_PARTNER_DROPDOWNLIST", GetConn, ()),
999
(CloseButtonProcessor, "IDCANCEL"),
1000
(CommandButtonProcessor, "ID_CONTACT_SAVE_BUTTON ID_CONTACT_NAME_TEXT ID_CONTACT_EMAIL_TEXT ID_CONTACT_OFFICE_TEXT ID_CONTACT_MOBILE_TEXT ID_PARTNER_DROPDOWNLIST", CreateContact, ()),
1001
(TextProcessor, "ID_CONTACT_NAME_TEXT ID_CONTACT_EMAIL_TEXT", SetDefaultContact, ()),
1002
(DialogCommand, "ID_NEW_PARTNER_BUTTON ID_CONTACT_NAME_TEXT ID_CONTACT_EMAIL_TEXT", "IDD_NEW_PARTNER_DIALOG", set_name_email, ()),
1005
"IDD_NEW_PARTNER_DIALOG" : (
1006
(CloseButtonProcessor, "IDCANCEL"),
1007
(CommandButtonProcessor, "ID_SAVE_PARTNER_BUTTON ID_PARTNER_NAME_TEXT", CreatePartner, ()),