def OnClicked(self, id): server = win32gui.GetDlgItemText(self.window.hwnd, self.other_ids[0]) try: port = int(win32gui.GetDlgItemText(self.window.hwnd, self.other_ids[1])) except ValueError, e: win32ui.MessageBox("Port should be an integer", "Error", flag_excl) return
def CreateContact(btnProcessor,*args): b = check() if not b: return partner = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[4]) combo = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[4]) sel = win32gui.SendMessage(combo, win32con.CB_GETCURSEL) name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) email = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1]) office_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2]) mobile_no = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[3]) if not name: win32ui.MessageBox("Please enter name.", "Create Contact", flag_stop) return res = {'name':ustr(name), 'email':ustr(email), 'phone':ustr(office_no), 'mobile':ustr(mobile_no)} try: id = NewConn.CreateContact(sel, str(res)) msg="New contact created for partner '%s'."%partner except Exception,e: msg="Contact not created \n\n" + getMessage(e) win32ui.MessageBox(msg, "Create Contact", flag_error) return
def AddNewObject(btnProcessor,*args): #Check if server running or user logged in b = check() if not b: return #Check if title or object not specified obj_title = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) obj_name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1]) if not obj_title: win32ui.MessageBox("No Title specified", "", flag_excl) return if not obj_name: win32ui.MessageBox("No object specified", "", flag_excl) return #Check if object does not exist in the database or it already exist in the list try: all_obj_list = NewConn.GetAllObjects() curr_obj_list = [obj[1] for obj in NewConn.GetObjList()] curr_title_list = [obj[0] for obj in NewConn.GetObjList()] if obj_name not in all_obj_list: win32ui.MessageBox("No such object exists", "Object Settings", flag_excl) return elif obj_name in curr_obj_list: win32ui.MessageBox("Object already in the list", "Object Settings", flag_info) return elif obj_title in curr_title_list: win32ui.MessageBox("Title already in the list. Please give different title", "Object Settings", flag_excl) return #extract image path and load the image image_path='' image_path = os.path.join(btnProcessor.window.manager.application_directory, "dialogs\\resources\\openerp_logo1.bmp") path=win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2]) if path: image_path = path load_bmp_flags=win32con.LR_LOADFROMFILE | win32con.LR_LOADTRANSPARENT try: hicon = win32gui.LoadImage(0, image_path,win32con.IMAGE_BITMAP, 40, 40, load_bmp_flags) except Exception,e: msg=getMessage(e) hicon=None win32ui.MessageBox(msg, "Load Image", flag_error) #Add the object in the list win32gui.ImageList_Add(il,hicon,0) cnt = win32gui.ImageList_GetImageCount(il) hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[3]) num_items = win32gui.SendMessage(hwndList, commctrl.LVM_GETITEMCOUNT) item = LVITEM(text=obj_title, iImage=cnt-2, iItem = num_items) new_index = win32gui.SendMessage(hwndList, commctrl.LVM_INSERTITEM, 0, item.toparam()) win32gui.SendMessage(hwndList, commctrl.LVM_SETIMAGELIST, commctrl.LVSIL_SMALL, il) item = LVITEM(text=obj_name, iItem = new_index, iSubItem = 1) win32gui.SendMessage(hwndList, commctrl.LVM_SETITEM, 0, item.toparam()) NewConn.InsertObj(obj_title,obj_name,image_path)
def SearchObjectsForText(btnProcessor,*args): #Check if server running or user logged in b = check() if not b: return search_txt = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) if not search_txt: win32ui.MessageBox("Enter text to search for", "", flag_info) return # Get titles from list obj_titles=[] for ch in hwndChk_list: id = ch[0] hwnd = ch[1] chk = win32gui.SendMessage(hwnd, win32con.BM_GETCHECK) if chk: txt = win32gui.GetDlgItemText(btnProcessor.window.hwnd,id) obj_titles.append(txt) # Prepare list of objects to search for the seach_keyword obj_list = btnProcessor.window.manager.config['objects'] search_list = [] try: all_obj_list = NewConn.GetAllObjects() for title in obj_titles: objname = [obj[1] for obj in obj_list if obj[0] == title] if objname: assert len(objname) == 1 if objname[0] in all_obj_list: search_list.append(objname[0]) else: win32ui.MessageBox("Module %s (%s) not installed. Please install it." \ %(title,objname[0]), "", flag_excl) return # Get the records by searching the objects in search_list for the search_keyword as objects_with_match global objects_with_match list_hwnd = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[1]) if search_list: objects_with_match = NewConn.GetObjectItems(search_list, search_txt) if not objects_with_match: win32ui.MessageBox("No matching records found in checked objects", "", flag_info) else: win32ui.MessageBox("No object selected", "", flag_info) objects_with_match=[] # Display the objects_with_match records in list setList(list_hwnd) except Exception,e: msg=getMessage(e) win32ui.MessageBox(msg, "", flag_error)
def TestConnection(btnProcessor,*args): server = NewConn.getitem('_server') port = NewConn.getitem('_port') NewConn.GetDBList() if str(NewConn.getitem('_running')) == 'False': btnProcessor.window.LoadAllControls() win32ui.MessageBox("No server running on host "+ server+" at port "+str(port), "Server Connection", flag_excl) return try: dbname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, 7000) if not dbname: win32ui.MessageBox("Please enter database name", "", flag_excl) return except Exception,e: dbname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) if not dbname: win32ui.MessageBox("No database found on host "+ server+" at port "+str(port), "Database Connection", flag_excl) return uname = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[1]) pwd = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[2]) if not uname: win32ui.MessageBox("Enter Username", "", flag_excl) return if not pwd: win32ui.MessageBox("Enter Password", "", flag_excl) return #Establish Connection try: uid = NewConn.login(dbname, uname, pwd) if uid: msg = "Connection Successful" NewConn.setitem('_login', 'True') NewConn.setitem('_uname', uname) NewConn.setitem('_pwd', pwd) NewConn.setitem('_uid', uid) flag = flag_info if not NewConn.IsCRMInstalled(): msg+= '\n\n'+" 'CRM' module is not installed. So CRM cases cannot be created." NewConn.setitem('_iscrm', False) else: try: list = NewConn.GetCSList() NewConn.setitem('_iscrm', True) except Exception,e: msg+= '\n\n'+"CRM cases cannot be created.\n\n" + getMessage(e) NewConn.setitem('_iscrm', False) else:
def UpdateControl_FromValue(self): combo = self.GetControl() conn = self.func() list = conn.GetDBList() db = conn.getitem('_dbname') if list == -1: hinst = win32gui.dllhandle parent = self.window.hwnd dwStyle = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_TABSTOP | win32con.WS_BORDER | \ win32con.ES_AUTOHSCROLL | win32con.FF_ROMAN | win32con.FW_EXTRALIGHT hwndImg = win32gui.CreateWindow("EDIT", db, dwStyle, 67, 80, 180, 20, parent, 7000, 0, None) self.active_control_id = 7000 win32gui.ShowWindow(combo, False) else: try: txtbx = win32gui.GetDlgItem(self.window.hwnd, 7000) win32gui.DestroyWindow(txtbx) except Exception, e: print "Exception : %s" % str(e) pass win32gui.ShowWindow(combo, True) win32gui.SendMessage(combo, win32con.CB_RESETCONTENT, 0, 0) for item in list: win32gui.SendMessage(combo, win32con.CB_ADDSTRING, 0, str(item)) sel = win32gui.SendMessage(combo, win32con.CB_SELECTSTRING, 0, db) dbb = win32gui.GetDlgItemText(self.window.hwnd, 2004) if sel == -1: win32gui.SendMessage(combo, win32con.CB_SETCURSEL, 0, 0) self.active_control_id = self.control_id
def OnCommand(self, wparam, lparam): code = win32api.HIWORD(wparam) id = win32api.LOWORD(wparam) if code == win32con.BN_CLICKED: text=win32gui.GetDlgItemText(self.window.hwnd, self.control_id) conn = self.func() conn.setitem('protocol', text) p=conn.getitem('protocol')
def SetAllText(txtProcessor,*args): # Set values for url, uname, pwd from config file url = NewConn.getitem('_uri') tbox = txtProcessor.GetControl() win32gui.SendMessage(tbox, win32con.WM_SETTEXT, 0, str(url)) k=win32gui.GetDlgItemText(txtProcessor.window.hwnd, txtProcessor.control_id) uname = NewConn.getitem('_uname') tbox = txtProcessor.GetControl(txtProcessor.other_ids[0]) win32gui.SendMessage(tbox, win32con.WM_SETTEXT, 0, str(uname))
def desktop_name_dlgproc(hwnd,msg,wparam,lparam): """ Handles messages from the desktop name dialog box """ if msg in (win32con.WM_CLOSE,win32con.WM_DESTROY): win32gui.DestroyWindow(hwnd) elif msg == win32con.WM_COMMAND: if wparam == win32con.IDOK: desktop_name=win32gui.GetDlgItemText(hwnd, 72) print 'new desktop name: ',desktop_name win32gui.DestroyWindow(hwnd) create_desktop(desktop_name) elif wparam == win32con.IDCANCEL: win32gui.DestroyWindow(hwnd)
def CreatePartner(btnProcessor,*args): #Check if server running or user logged in b = check() if not b: return partner_name = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) if not partner_name: win32ui.MessageBox("Please enter Partner name.", "Create Partner", flag_excl) return res = {'name':ustr(partner_name)} try: id = NewConn.CreatePartner(str(res)) except Exception,e: msg="Partner not created \n\n" + getMessage(e) win32ui.MessageBox(msg, "Create Partner", flag_error) return
def CreateCase(btnProcessor,*args): try: #Check if server running or user logged in b = check() if not b: return if NewConn.getitem('_iscrm'): # Get the selected mail ex = btnProcessor.window.manager.outlook.ActiveExplorer() assert ex.Selection.Count == 1 mail = ex.Selection.Item(1) section = win32gui.GetDlgItemText(btnProcessor.window.hwnd, btnProcessor.other_ids[0]) if not section: win32ui.MessageBox("CRM Case could not be created. No CRM Sections found. Please configure database first.", "Create Case", flag_excl) return hwndList = win32gui.GetDlgItem(btnProcessor.window.hwnd, btnProcessor.other_ids[1]) partner_ids=[] r = GetSelectedItems(hwndList) for rec in r: if rec[0] == 'res.partner': partner_ids.append(rec[1]) #Create new case try: with_attachments=True if mail.Attachments.Count > 0: msg="The mail contains attachments. Do you want to create case with attachments?" r=win32ui.MessageBox(msg, "Create Case", win32con.MB_YESNOCANCEL | win32con.MB_ICONQUESTION) if r == 2: return elif r == 7: with_attachments=False NewConn.CreateCase(section, mail, partner_ids, with_attachments) msg="New case created." flag=flag_info except Exception,e: msg="CRM Case not created \n\n"+getMessage(e) flag=flag_error win32ui.MessageBox(msg, "Create Case", flag) return else:
def UpdateValue_FromControl(self): db = win32gui.GetDlgItemText(self.window.hwnd, self.active_control_id) conn = self.func() if conn.getitem('_dbname') != db: conn.setitem('_dbname', db) conn.setitem('_login', 'False')
def set_name_email(dialogProcessor,*args): global name global email name = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[0]) email = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[1])
def set_search_text(dialogProcessor,*args): global search_text search_text = win32gui.GetDlgItemText(dialogProcessor.window.hwnd, dialogProcessor.other_ids[0]) return