def preFill(self): old_rc = getResourceFolder() regfile = os.path.join(old_rc, ".registration") if os.path.exists(regfile): form_dict = pickle.load(open(regfile, 'rb')) if form_dict.has_key("First_Name"): self.e_First_Name.insert(0, form_dict['First_Name']) if form_dict.has_key("Last_Name"): self.e_Last_Name.insert(0, form_dict['Last_Name']) if form_dict.has_key("Email"): self.e_Email.insert(0, form_dict['Email']) if form_dict.has_key("Institution"): self.e_Institution.insert(0, form_dict['Institution']) if form_dict.has_key("Institution_Type"): self.e_Institution_Type.setvalue(form_dict['Institution_Type']) if form_dict.has_key("Position"): self.e_Position.insert(0, form_dict['Position']) if form_dict.has_key("Department"): self.e_Department.insert(0, form_dict['Department']) if form_dict.has_key("Address"): self.e_Address.insert(0, form_dict['Address']) if form_dict.has_key("City"): self.e_City.insert(0, form_dict['City']) if form_dict.has_key("State"): self.e_State.insert(0, form_dict['State']) if form_dict.has_key("PostalCode"): self.e_PostalCode.insert(0, form_dict['PostalCode']) if form_dict.has_key("Country"): self.e_Country.insert(0, form_dict['Country']) if form_dict.has_key("Phone"): self.e_Phone.insert(0, form_dict['Phone']) if form_dict.has_key("Fax"): self.e_Fax.insert(0, form_dict['Fax'])
def Update(self): regfile = None old_rc = getResourceFolder() rcWithVersion = getResourceFolderWithVersion() regfile = os.path.join(old_rc, ".registration") if os.path.exists(old_rc + os.sep + ".registration"): regfile = old_rc + os.sep + ".registration" else: dirlist = os.listdir(old_rc) for item in dirlist: tmpRegFile = old_rc+os.sep+item+os.sep + ".registration" if os.path.exists(tmpRegFile): regfile = tmpRegFile break regDict = pickle.load(open(regfile)) regDict['Version'] = Version form_dict = {} form_dict['UserID'] = regDict['UserID'] form_dict['Version'] = regDict['Version'] import httplib, urllib params = urllib.urlencode(form_dict) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"} conn = httplib.HTTPConnection("www.scripps.edu:80") conn.request("POST", "/cgi-bin/sanner/update_mgltools_version.py", params, headers) response = conn.getresponse() if response.status == 200: reg = open(lRessourceFolder + os.sep + ".registration", 'w') pickle.dump(regDict,reg) reg.close() conn.close()
def Update(self): regfile = None old_rc = getResourceFolder() rcWithVersion = getResourceFolderWithVersion() regfile = os.path.join(old_rc, ".registration") if os.path.exists(old_rc + os.sep + ".registration"): regfile = old_rc + os.sep + ".registration" else: dirlist = os.listdir(old_rc) for item in dirlist: tmpRegFile = old_rc + os.sep + item + os.sep + ".registration" if os.path.exists(tmpRegFile): regfile = tmpRegFile break regDict = pickle.load(open(regfile)) regDict['Version'] = Version form_dict = {} form_dict['UserID'] = regDict['UserID'] form_dict['Version'] = regDict['Version'] import httplib, urllib params = urllib.urlencode(form_dict) headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } conn = httplib.HTTPConnection("www.scripps.edu:80") conn.request("POST", "/cgi-bin/sanner/update_mgltools_version.py", params, headers) response = conn.getresponse() if response.status == 200: reg = open(lRessourceFolder + os.sep + ".registration", 'w') pickle.dump(regDict, reg) reg.close() conn.close()
def __init__(self, master=None, title = 'Chooser', commands = None, immediate=0, exitFunction=None, colorsFile=None, colorsName=None): self.exitFunc = exitFunction self.mapping = {} self.currentTag = None if colorsFile is None or colorsName is None: path = getResourceFolder() if not path: path = __import__('mglutil').__path__ if not os.path.exists(os.path.join(path,'defaultColors.py')): import shutil shutil.copy(os.path.join(__import__('mglutil').__path__[0],'gui/BasicWidgets/Tk/defaultColors.py'), os.path.join(path,'defaultColors.py')) self.customFilename = os.path.join(path,'defaultColors.py') self.colorsName = 'defaultColor' else: self.customFilename = colorsFile self.colorsName = colorsName Chooser.__init__(self, master=master, title=title, commands = commands, immediate=immediate, exitFunction=exitFunction) try: self.master.protocol('WM_DELETE_WINDOW', self.exit) except: pass
def register(self, ): self.dictToSend = {} for i, k in enumerate(order): dk = k if i <= 5: dk = dk.replace("*", "") dk = dk.replace(" ", "_") self.dictToSend[dk] = str(self.form_dict[k]).strip() #print (dk,self.dictToSend[dk]) self.dictToSend.update(self.sys_dict) self.dictToSend['hostname'] = self.form_dict['hostname'] self.dictToSend['3DHost'] = self.form_dict['3DHost'] # for k in self.dictToSend: # print k, self.dictToSend[k] params = urllib.urlencode(self.dictToSend) #print (params) #self.label_message.configure(text = 'Please Wait', fg = 'Red') headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } # conn = httplib.HTTPConnection("www.scripps.edu:80") conn = httplib.HTTPConnection("mgldev.scripps.edu:80") try: # conn.request("POST", "/cgi-bin/sanner/register_mgltools.py", params, headers) conn.request("POST", "/cgi-bin/register_mgltools.py", params, headers) response = conn.getresponse() except: # from traceback import print_exc # print_exc() print("fail to connect") return False if response.status == 200: # getResourceFolder reg_file = os.path.join(getResourceFolder(), '.registration') # print (reg_file) UserID = response.read().decode("utf8") # print (UserID) if UserID: self.form_dict['UserID'] = UserID file = open(reg_file, 'wb') pickle.dump(self.form_dict, file) file.close() c_reg_file = os.path.join(getResourceFolderWithVersion(), '.registration') shutil.copy(reg_file, c_reg_file) else: print("Registration failed to create User.") return False else: print("Unable to connect to Registration Database") return False conn.close() return True
def __new__(cls, master=None, title='Chooser', commands=None, immediate=0, exitFunction=None): #the following code was added to avoid having multiple copies of ColorChoosers global colorChoosersDict if title in colorChoosersDict: try: colorChoosersDict[title].master.destroy() except: pass self = object.__new__(cls) self.exitFunc = exitFunction self.mapping = {} self.currentTag = None self.rcPath = getResourceFolder() self.customColorsPath = os.path.join(self.rcPath, 'customColors') if os.path.exists(self.customColorsPath): customColors = open(self.customColorsPath).read().strip() customCols = customColors.split() self.colors[48:48 + len(customCols)] = customCols Chooser.__init__(self, master=master, title=title, commands=commands, immediate=immediate, exitFunction=exitFunction) if self.ownmaster: ## create dismiss button if exitFunction: cb = exitFunction else: cb = self.master.destroy self.dismissb = tkinter.Button(self.master, text='DISMISS', command=cb) self.dismissb.pack(side='bottom', expand=1, fill='x') try: self.master.protocol('WM_DELETE_WINDOW', self.exit) except: pass colorChoosersDict[title] = self return self
def register(self,): self.dictToSend={} for i,k in enumerate(order) : dk = k if i <=5 : dk = dk.replace("*","") dk = dk.replace(" ","_") self.dictToSend[dk] = str(self.form_dict[k]).strip() #print (dk,self.dictToSend[dk]) self.dictToSend.update(self.sys_dict) self.dictToSend['hostname'] = self.form_dict['hostname'] self.dictToSend['3DHost'] = self.form_dict['3DHost'] # for k in self.dictToSend: # print k, self.dictToSend[k] params = urllib.urlencode(self.dictToSend) #print (params) #self.label_message.configure(text = 'Please Wait', fg = 'Red') headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} # conn = httplib.HTTPConnection("www.scripps.edu:80") conn = httplib.HTTPConnection("mgldev.scripps.edu:80") try: # conn.request("POST", "/cgi-bin/sanner/register_mgltools.py", params, headers) conn.request("POST", "/cgi-bin/register_mgltools.py", params, headers) response = conn.getresponse() except : # from traceback import print_exc # print_exc() print ("fail to connect") return False if response.status == 200: # getResourceFolder reg_file = os.path.join(getResourceFolder(), '.registration') # print (reg_file) UserID = response.read().decode("utf8") # print (UserID) if UserID: self.form_dict['UserID'] = UserID file = open(reg_file,'wb') pickle.dump(self.form_dict, file) file.close() c_reg_file = os.path.join(getResourceFolderWithVersion(), '.registration') shutil.copy(reg_file, c_reg_file) else: print ("Registration failed to create User.") return False else: print ("Unable to connect to Registration Database" ) return False conn.close() return True
def __init__(self, resourceFolder=None, fileName='setting'): UserDict.__init__(self) self.dirty = 0 # used to remember that something changed if not resourceFolder: resourceFolder = getResourceFolder() self.resourceFile = os.path.join(resourceFolder, fileName) self.defaults = {} self.settings = {} if os.path.exists(self.resourceFile): try: pkl_file = open(self.resourceFile) self.settings = pickle.load(pkl_file) pkl_file.close() except Exception, inst: print inst, "Error in ", __file__
def preFill(self): old_rc = getResourceFolder() regfile = os.path.join(old_rc, ".registration") if os.path.exists(regfile): try : form_dict = pickle.load(open(regfile, 'rb')) except : return print(form_dict) for i,k in enumerate(order) : dk = k if i <=5 : if dk not in form_dict : dk = dk.replace("*","") dk = dk.replace(" ","_") self.form_dict[k] = str(form_dict[dk]).strip()
def preFill(self): old_rc = getResourceFolder() regfile = os.path.join(old_rc, ".registration") if os.path.exists(regfile): try: form_dict = pickle.load(open(regfile, 'rb')) except: return print(form_dict) for i, k in enumerate(order): dk = k if i <= 5: if dk not in form_dict: dk = dk.replace("*", "") dk = dk.replace(" ", "_") self.form_dict[k] = str(form_dict[dk]).strip()
def doit(self): if self.root is None: self.root = Tkinter.Toplevel() self.root.withdraw() # the vision font must be decided in vision or _visionrc, not here anymore # if 'changeFont' in self.vf.commands.keys(): # currentFont = self.vf.changeFont.getCurrentFont() # self.ed = VisualProgramingEnvironment( # master=self.root, font=currentFont, withShell=0) # else: self.ed = VisualProgramingEnvironment(master=self.root, withShell=0) self.root.protocol("WM_DELETE_WINDOW", self.hide) if getResourceFolder() is None: self.ed.loadLibModule('Vision.StandardNodes') else: self.ed.sourceFile(resourceFile='_visionrc') self.ed.updateFastLibs() filemenu = self.ed.menuButtons['File'].menu filemenu.entryconfig(filemenu.index('Quit'), command=self.hide) # let Vision know which PMV instance runs it self.ed.vf = self.vf # add handle to Pmv library instance from Pmv.VisionInterface.PmvNodes import pmvlib self.lib = pmvlib # initialize the API between PMV and Vision self.vf.visionAPI.setEditor(self.ed) self.vf.visionAPI.setLibrary(self.lib) # add Pmv library to Vision self.ed.addLibraryInstance(pmvlib, 'Pmv.VisionInterface.PmvNodes', 'pmvlib') # add Standard library to Vision from Vision.StandardNodes import stdlib self.ed.addLibraryInstance(stdlib, 'Vision.StandardNodes', 'stdlib') # add MolKit library to Vision if needed if len(self.vf.Mols): from MolKit.VisionInterface.MolKitNodes import molkitlib self.ed.addLibraryInstance( molkitlib, 'MolKit.VisionInterface.MolKitNodes', 'molkitlib') # add molecule nodes to Pmv library if molecules were loaded in # Pmv before Vision was started for obj, name, kw in self.vf.visionAPI.objects: self.vf.visionAPI.addNodeToLibrary(obj, name, kw) # is ARTK running? if so, we need to add the library and nodes if hasattr(self.vf, 'art') and self.vf.art.visionAPI is not None: visionAPI = self.vf.art.visionAPI visionAPI.setEditor(self.ed) from ARViewer.VisionInterface.ARNodes import artlib visionAPI.setLibrary(artlib) visionAPI.ed.addLibraryInstance( artlib, 'ARTK.VisionInterface.ARNodes', 'artlib') # add nodes to ARTK library for obj, name, kw in visionAPI.objects: visionAPI.addNodeToLibrary(obj, name, kw) # and add link to ARViewer self.ed.art = self.vf.art elif self.vf.GUI.toolbarCheckbuttons['Vision']['Variable'].get( ) == 0 and self.root: self.root.withdraw() elif self.vf.GUI.toolbarCheckbuttons['Vision']['Variable'].get( ) == 1 and self.root: self.root.deiconify() ################################################################## # FIXME: # Workaround: currently, Vision would crash on some Windows2000 and SGI # when running multi-threaded. We turn MT off by default ################################################################## #if sys.platform == 'win32' or sys.platform == 'irix646': self.ed.configure(withThreads=0)
class Register_User: """Opens TopLevel Dialog for User Registration""" def __init__(self, version=None): self.version = version master = Tkinter.Toplevel() self.master = master font = self.master.option_get('font', '*') self.master.option_add('*font', "Times 12 bold") x = self.master.winfo_screenwidth() / 6 y = self.master.winfo_screenheight() / 6 geometry = '+%d+%d' % (x, y) self.master.geometry(geometry) #self.master.config(font="Helvetica 10 bold italic") master.title("MGLTools Registration Form") Tkinter.Label(master, text="MGLTools Registration Form").\ grid(row=0,columnspan=5) text = """This data will be kept confidential and will not be made available to any third party.""" Tkinter.Label(master, text=text).grid(row=1, columnspan=5) Tkinter.Label(master, text="Fields in Red are Required",fg="Red" ).\ grid(row=2,columnspan=5) Tkinter.Label(master, text="First Name", fg='Red').grid(row=3, sticky='W') Tkinter.Label(master, text="Last Name", fg='Red').grid(row=4, sticky='W') Tkinter.Label(master, text="Email", fg='Red').grid(row=5, sticky='W') Tkinter.Label(master, text="Institution", fg='Red').grid(row=6, sticky='W') Tkinter.Label(master, text="Institution Type", fg='Red').grid(row=7, sticky='W') Tkinter.Label(master, text="Position").grid(row=8, sticky='W') Tkinter.Label( master, text="Department", ).grid(row=9, sticky='W') Tkinter.Label(master, text=" ").grid(row=6, column=2) #placeholder Tkinter.Label(master, text="Address").grid(row=3, column=3, sticky='W') Tkinter.Label(master, text="City").grid(row=4, column=3, sticky='W') Tkinter.Label(master, text="State").grid(row=5, column=3, sticky='W') Tkinter.Label(master, text="PostalCode").grid(row=6, column=3, sticky='W') Tkinter.Label(master, text="Country").grid(row=7, column=3, sticky='W') Tkinter.Label(master, text="Phone").grid(row=8, column=3, sticky='W') Tkinter.Label(master, text="Fax").grid(row=9, column=3, sticky='W') self.e_First_Name = Tkinter.Entry(master, bg="White") self.e_Last_Name = Tkinter.Entry(master, bg="White") self.e_Email = Tkinter.Entry(master, bg="White") self.e_Institution = Tkinter.Entry(master, bg="White") self.e_Institution_Type = Pmw.OptionMenu( master, items=['Academic', 'Government', 'Commercial'], menubutton_width=16) self.e_Position = Tkinter.Entry(master, bg="White") self.e_Department = Tkinter.Entry(master, bg="White") self.e_Address = Tkinter.Entry(master, bg="White") self.e_City = Tkinter.Entry(master, bg="White") self.e_State = Tkinter.Entry(master, bg="White") self.e_PostalCode = Tkinter.Entry(master, bg="White") self.e_Country = Tkinter.Entry(master, bg="White") self.e_Phone = Tkinter.Entry(master, bg="White") self.e_Fax = Tkinter.Entry(master, bg="White") self.e_First_Name.grid(row=3, column=1) self.e_Last_Name.grid(row=4, column=1) self.e_Email.grid(row=5, column=1) self.e_Institution.grid(row=6, column=1) self.e_Institution_Type.grid(row=7, column=1) self.e_Position.grid(row=8, column=1) self.e_Department.grid(row=9, column=1) self.e_Address.grid(row=3, column=4) self.e_City.grid(row=4, column=4) self.e_State.grid(row=5, column=4) self.e_PostalCode.grid(row=6, column=4) self.e_Country.grid(row=7, column=4) self.e_Phone.grid(row=8, column=4) self.e_Fax.grid(row=9, column=4) mgl_group = Tkinter.LabelFrame( master, text="Which of the " + "following program(s) are you planning to use?", labelanchor='n') mgl_group.grid(row=11, columnspan=8, sticky='WESN', pady=5) label_message = Tkinter.Label(mgl_group, text="Check all that apply") label_message.grid(row=12, columnspan=5) self.adt_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(mgl_group, text="AutoDockTools ", variable=self.adt_var) checkbutton.grid(row=13, column=0) self.pmv_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(mgl_group, text="PMV ", variable=self.pmv_var) checkbutton.grid(row=13, column=2) self.vision_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(mgl_group, text="Vision ", variable=self.vision_var) checkbutton.grid(row=13, column=4) self.DejaVu_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(mgl_group, text="DejaVu", variable=self.DejaVu_var) checkbutton.grid(row=13, column=5) bin_source = Tkinter.LabelFrame(master, text="Did you install MGLTools " + "from Binary and/or Source?", labelanchor='n') bin_source.grid(row=14, columnspan=8, sticky='WESN', pady=5) self.bin_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(bin_source, text="Binary ", variable=self.bin_var) checkbutton.grid(row=15, column=0) self.source_var = Tkinter.IntVar() checkbutton = Tkinter.Checkbutton(bin_source, text="Source ", variable=self.source_var) checkbutton.grid(row=15, column=2) self.label_message = Tkinter.Label(master, text="") self.label_message.grid(row=16, columnspan=5) #placeholder self.regButton = Tkinter.Button(master, text='Register', command=self.Register) self.regButton.grid(row=17, column=1, columnspan=2) Tkinter.Button(master, text='Cancel', command=self.Cancel).grid(row=17, column=3, columnspan=2, pady=2) self.master.option_add('*font', font) self.preFill() def Register(self): self.regButton.configure(state='disabled') form_dict = {} First_Name = self.e_First_Name.get() First_Name = First_Name.strip() if not First_Name: self.label_message.configure(text='First Name is missing', fg='Red') self.e_First_Name.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_First_Name.configure(bg='White') self.label_message.configure(text='') form_dict['First_Name'] = First_Name Last_Name = self.e_Last_Name.get() Last_Name = Last_Name.strip() if not Last_Name: self.label_message.configure(text='Last Name is missing', fg='Red') self.e_Last_Name.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Last_Name.configure(bg='White') self.label_message.configure(text='') form_dict['Last_Name'] = Last_Name Email = self.e_Email.get() Email = Email.strip() if not Email or Email.find('@') == -1: self.label_message.configure( text='Please provide a valid Email address', fg='Red') self.e_Email.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Email.configure(bg='White') self.label_message.configure(text='') form_dict['Email'] = Email Institution = self.e_Institution.get() Institution = Institution.strip() if not Institution: self.label_message.configure(text='Institution is missing', fg='Red') self.e_Institution.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Institution.configure(bg='White') self.label_message.configure(text='') form_dict['Institution'] = Institution Institution_Type = self.e_Institution_Type.getvalue() if Institution_Type not in ['Academic', 'Government', 'Commercial']: self.label_message.configure(text='Institution Type should be\ Academic,Government or Commercial', fg='Red') self.regButton.configure(state='normal') return else: self.label_message.configure(text='') form_dict['Institution_Type'] = Institution_Type Position = self.e_Position.get() Position = Position.strip() if not Position: Position = ' ' form_dict['Position'] = Position Department = self.e_Department.get() Department = Department.strip() form_dict['Department'] = Department Address = self.e_Address.get() Address = Address.strip() form_dict['Address'] = Address City = self.e_City.get() City = City.strip() form_dict['City'] = City State = self.e_State.get() State = State.strip() form_dict['State'] = State PostalCode = self.e_PostalCode.get() PostalCode = PostalCode.strip() form_dict['PostalCode'] = PostalCode Country = self.e_Country.get() Country = Country.strip() form_dict['Country'] = Country Phone = self.e_Phone.get() Phone = Phone.strip() form_dict['Phone'] = Phone Fax = self.e_Fax.get() Fax = Fax.strip() form_dict['Fax'] = Fax planning_to_use = '' if self.adt_var.get(): planning_to_use = 'ADT' if self.pmv_var.get(): planning_to_use += ',PMV' if self.vision_var.get(): planning_to_use += ',Vision' if self.DejaVu_var.get(): planning_to_use += ',DejaVu' form_dict['PlanningToUse'] = planning_to_use build_from = '' if self.bin_var.get(): build_from = 'Binary' if self.source_var.get(): build_from += ',Source' form_dict['BuildFrom'] = build_from self.label_message.configure(text='Submitting the Registration Form') form_dict['version'] = self.version.split('(')[0] os_name = os.name form_dict['os_name'] = os_name sys_platfrom = sys.platform form_dict['sys_platfrom'] = sys_platfrom sys_version = sys.version form_dict['sys_version'] = sys_version.replace('\n', '') try: hostname = gethostname() form_dict['hostname'] = hostname except: form_dict['hostname'] = "problem" params = urllib.urlencode(form_dict) self.label_message.configure(text='Please Wait', fg='Red') headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } conn = httplib.HTTPConnection("www.scripps.edu:80") try: conn.request("POST", "/cgi-bin/sanner/register_mgltools.py", params, headers) response = conn.getresponse() except Exception, inst: from traceback import print_exc print_exc() return self.master.update() if response.status == 200: getResourceFolder reg_file = os.path.join(getResourceFolder(), '.registration') UserID = response.read() if UserID: form_dict['UserID'] = UserID file = open(reg_file, 'w') pickle.dump(form_dict, file) file.close() c_reg_file = os.path.join(getResourceFolderWithVersion(), '.registration') shutil.copy(reg_file, c_reg_file) else: tkMessageBox.showerror("ERROR", "Registration failed.") self.regButton.configure(state='normal') return else: tkMessageBox.showerror( "ERROR", "Unable to connect to Registration Database" + "\nPlease try again") self.regButton.configure(state='normal') return conn.close() self.Cancel() tkMessageBox.showinfo("Thank You", "Thank you for registering MGLTools!")
def Register(self): self.regButton.configure(state='disabled') form_dict = {} First_Name = self.e_First_Name.get() First_Name = First_Name.strip() if not First_Name: self.label_message.configure(text='First Name is missing', fg='Red') self.e_First_Name.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_First_Name.configure(bg='White') self.label_message.configure(text='') form_dict['First_Name'] = First_Name Last_Name = self.e_Last_Name.get() Last_Name = Last_Name.strip() if not Last_Name: self.label_message.configure(text='Last Name is missing', fg='Red') self.e_Last_Name.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Last_Name.configure(bg='White') self.label_message.configure(text='') form_dict['Last_Name'] = Last_Name Email = self.e_Email.get() Email = Email.strip() if not Email or Email.find('@') == -1: self.label_message.configure( text='Please provide a valid Email address', fg='Red') self.e_Email.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Email.configure(bg='White') self.label_message.configure(text='') form_dict['Email'] = Email Institution = self.e_Institution.get() Institution = Institution.strip() if not Institution: self.label_message.configure(text='Institution is missing', fg='Red') self.e_Institution.configure(bg='Red') self.regButton.configure(state='normal') return else: self.e_Institution.configure(bg='White') self.label_message.configure(text='') form_dict['Institution'] = Institution Institution_Type = self.e_Institution_Type.getvalue() if Institution_Type not in ['Academic', 'Government', 'Commercial']: self.label_message.configure(text='Institution Type should be\ Academic,Government or Commercial', fg='Red') self.regButton.configure(state='normal') return else: self.label_message.configure(text='') form_dict['Institution_Type'] = Institution_Type Position = self.e_Position.get() Position = Position.strip() if not Position: Position = ' ' form_dict['Position'] = Position Department = self.e_Department.get() Department = Department.strip() form_dict['Department'] = Department Address = self.e_Address.get() Address = Address.strip() form_dict['Address'] = Address City = self.e_City.get() City = City.strip() form_dict['City'] = City State = self.e_State.get() State = State.strip() form_dict['State'] = State PostalCode = self.e_PostalCode.get() PostalCode = PostalCode.strip() form_dict['PostalCode'] = PostalCode Country = self.e_Country.get() Country = Country.strip() form_dict['Country'] = Country Phone = self.e_Phone.get() Phone = Phone.strip() form_dict['Phone'] = Phone Fax = self.e_Fax.get() Fax = Fax.strip() form_dict['Fax'] = Fax planning_to_use = '' if self.adt_var.get(): planning_to_use = 'ADT' if self.pmv_var.get(): planning_to_use += ',PMV' if self.vision_var.get(): planning_to_use += ',Vision' if self.DejaVu_var.get(): planning_to_use += ',DejaVu' form_dict['PlanningToUse'] = planning_to_use build_from = '' if self.bin_var.get(): build_from = 'Binary' if self.source_var.get(): build_from += ',Source' form_dict['BuildFrom'] = build_from self.label_message.configure(text='Submitting the Registration Form') form_dict['version'] = self.version.split('(')[0] os_name = os.name form_dict['os_name'] = os_name sys_platfrom = sys.platform form_dict['sys_platfrom'] = sys_platfrom sys_version = sys.version form_dict['sys_version'] = sys_version.replace('\n', '') try: hostname = gethostname() form_dict['hostname'] = hostname except: form_dict['hostname'] = "problem" params = urllib.urlencode(form_dict) self.label_message.configure(text='Please Wait', fg='Red') headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain" } # conn = httplib.HTTPConnection("www.scripps.edu:80") conn = httplib.HTTPConnection("mgldev.scripps.edu:80") #print conn # try: # conn.request("POST", "/cgi-bin/sanner/register_mgltools.py", params, headers) conn.request("POST", "/cgi-bin/register_mgltools.py", params, headers) response = conn.getresponse() # print response.status # except Exception, inst: # from traceback import print_exc # print "problem connecting registration" # print_exc() # return self.master.update() if response.status == 200: # getResourceFolder reg_file = os.path.join(getResourceFolder(), '.registration') UserID = response.read().decode("utf8") # print "response",response.read(),UserID if UserID: form_dict['UserID'] = UserID file = open(reg_file, 'w') pickle.dump(form_dict, file) file.close() c_reg_file = os.path.join(getResourceFolderWithVersion(), '.registration') shutil.copy(reg_file, c_reg_file) else: tkMessageBox.showerror("ERROR", "Registration failed.") self.regButton.configure(state='normal') return else: tkMessageBox.showerror( "ERROR", "Unable to connect to Registration Database" + "\nPlease try again") self.regButton.configure(state='normal') return conn.close() self.Cancel() tkMessageBox.showinfo("Thank You", "Thank you for registering MGLTools!")
def runCADD(*argv, **kw): """The main function for running CADD listOfDemandedOuts = runCADD('--noSplash', '--runAndExit', 'Network0_net.py', ins=[('myeval', 'command', 4),], outs=[('myeval', 'result'),] ) ins: list of tuples, each tuple being (node name, input port name, value) the input ports must have a widget. outs: list of tuples, each tuple being (node name, output port name) listOfDemandedOuts: list of values in the output ports listed in outs """ ################################################################## # Parse options ################################################################## if type(argv) is tuple: if len(argv) == 0: argv = None elif len(argv) == 1: argv = argv[0] if type(argv) is not list: argv = [argv] else: argv = list(argv) if kw.has_key("ownInterpreter"): ownInterpreter = kw["ownInterpreter"] else: if argv is None: argv = ['CADD/bin/runCADD.py'] ownInterpreter = False elif argv[0].endswith('runCADD.py') is False: argv.insert(0, 'CADD/bin/runCADD.py') ownInterpreter = False else: ownInterpreter = True help_msg = """usage: %s <options> <filenames> Files filenames ending in "net.py" will be laoded as networks in vision. Other files will be executed as Python scripts in which "ed" refers to the VisualProgrammingEnvironment instance. -h or --help : print this message -s or --noSplash : doesn't show the CADD splash screen (works only if registered) -t or --noTerminal : vision provides its own shell (under menu 'Edit') instead of the terminal --resourceFolder foldername : stores resource file under .name (defaults to .mgltools) -p or --ipython : create an ipython shell instead of a python shell -r or --run : run the networks on the command line -e or --runAndExit : run the networks and exit port values can be passed on the command line (but not to macros): Network_net.py nodeName:portName:value """ % sys.argv[0] try: optlist, args = getopt.getopt(argv[1:], 'hirestp', [ 'help', 'interactive', 'noTerminal', 'noSplash', 'resourceFolder=', 'run', 'runAndExit', 'ipython' ]) except: print "Unknown option!" print help_msg return interactive = 1 noSplash = False runNetwork = False once = False ipython = False for opt in optlist: if opt[0] in ('-h', '--help'): print help_msg return elif opt[0] in ('-i', '--interactive'): warnings.warn( '-i (interactive) is default mode, use --noTerminal to disable it', stacklevel=3) elif opt[0] in ('-t', '--noTerminal'): interactive = 0 elif opt[0] in ( '-s', '--noSplash', ): noSplash = True elif opt[0] in ('--resourceFolder', ): setResourceFolder(opt[1]) elif opt[0] in ('-r', '--run'): runNetwork = True elif opt[0] in ('-e', '--runAndExit'): runNetwork = True once = True elif opt[0] in ('-p', '--ipython'): ipython = True from Support.path import path_text, release_path print 'Run CADD from ', __path__[0] if globals().has_key('ed') is False: root = createRoot() #root.withdraw() ################################################################## # Splash Screen ################################################################## if noSplash is False: splash, about = createSplash() lSplashVisibleTimeStart = time.clock() ################################################################## # Start CADD ################################################################## ed = createCADD(root, interactive) globals()['ed'] = ed ################################################################## # Workaround: currently, Vision would crash on some Windows2000 and SGI # when running multi-threaded. We turn MT off for those platforms ################################################################## if os.name == 'nt' or sys.platform == 'irix646': ed.configure(withThreads=0) ################################################################## # Source Resource File (if available) ################################################################## if getResourceFolder() is None: ed.loadLibModule('Vision.StandardNodes') else: ed.sourceFile(resourceFile='_caddrc') # complete vpe menu with additionnal fastLibs if hasattr(ed, 'updateFastLibs'): ed.updateFastLibs() ################################################################## # Make sure splash is visible long enough before removing it ################################################################## if noSplash is False: lSplashVisibleTimeEnd = time.clock() while lSplashVisibleTimeEnd - lSplashVisibleTimeStart < 2: lSplashVisibleTimeEnd = time.clock() splash.finish() ################################################################## # Make vision visible #(before the network loads, so the additional windows will load on top) ################################################################## if once is False: root.deiconify() else: ed = globals()['ed'] root = ed.master root.master.master.deiconify() ################################################################## # Load network(s) if specified at startup ################################################################## lResults = [] if len(args): ed.root.update( ) # make sure the canvas is shown b4 loading any network lArgIndex = 0 while lArgIndex < len(args): if args[lArgIndex][-6:] == 'net.py': ed.loadNetwork(args[lArgIndex], ins=kw.get('ins')) lNodePortValues = [] lArgIndex += 1 while lArgIndex < len(args) and args[lArgIndex][-3:] != '.py': lNodePortValues.append(args[lArgIndex]) lArgIndex += 1 ed.currentNetwork.setNodePortValues(lNodePortValues) if runNetwork: ed.softrunCurrentNet_cb() elif args[lArgIndex][-3:] == '.py': execfile(netName) lArgIndex += 1 else: lArgIndex += 1 # lets obtain the asked outs values outs = kw.get('outs') if outs is not None: for lOut in outs: lOutFound = False for lNodes in ed.currentNetwork.nodes: if lNodes.name == lOut[0]: if lOutFound is True: warnings.warn("found several nodes %s" % lOut[0]) lOuputPort = lNodes.outputPortByName.get(lOut[1]) if lOuputPort is None: warnings.warn("node %s doesn't have port %s" % (lOut[0], lOut[1])) else: lResults.append(lOuputPort.data) lOutFound = True if lOutFound is False: warnings.warn("can't find node %s" % lOut[0]) if once is True: ed.root.quit() ed.root.destroy() globals().pop('ed') return lResults ################################################################## # Set the Python Shell ################################################################## elif ownInterpreter is True: if interactive: sys.stdin = sys.__stdin__ sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ mod = __import__('__main__') if ipython is True: try: # create IPython shell from IPython.Shell import _select_shell sh = _select_shell([])(argv=[], user_ns=mod.__dict__) sh.mainloop() except: import code try: # hack to really exit code.interact code.interact('CADD Interactive Shell', local=mod.__dict__) except: pass else: import code try: # hack to really exit code.interact code.interact('CADD Interactive Shell', local=mod.__dict__) except: pass else: ed.master.mainloop() else: return lResults
def runVision(*argv, **kw): """The main function for running Vision listOfDemandedOuts = runVision('--noSplash', '--runAndExit', 'Network0_net.py', ins=[('myeval', 'command', 4),], outs=[('myeval', 'result'),] ) ins: list of tuples, each tuple being (node name, input port name, value) the input ports must have a widget. outs: list of tuples, each tuple being (node name, output port name) listOfDemandedOuts: list of values in the output ports listed in outs """ ################################################################## # Parse options ################################################################## if type(argv) is tuple: if len(argv) == 0: argv = None elif len(argv) == 1: argv = argv[0] if type(argv) is not list: argv = [argv] else: argv = list(argv) if kw.has_key("ownInterpreter"): ownInterpreter = kw["ownInterpreter"] else: if argv is None: argv = ['Vision/bin/runVision.py'] ownInterpreter = False elif argv[0].endswith('runVision.py') is False: argv.insert(0,'Vision/bin/runVision.py') ownInterpreter = False else: ownInterpreter = True help_msg = """usage: %s <options> <filenames> Files filenames ending in "net.py" will be laoded as networks in vision. Other files will be executed as Python scripts in which "ed" refers to the VisualProgrammingEnvironment instance. -h or --help : print this message -s or --noSplash : doesn't show the Vision splash screen (works only if registered) -t or --noTerminal : vision provides its own shell (under menu 'Edit') instead of the terminal --resourceFolder foldername : stores resource file under .name (defaults to .mgltools) -p or --ipython : create an ipython shell instead of a python shell -r or --run : run the networks on the command line -e or --runAndExit : run the networks and exit port values can be passed on the command line (but not to macros): Network_net.py nodeName:portName:value """ % sys.argv[0] try: optlist, args = getopt.getopt(argv[1:], 'hirestp', [ 'help', 'interactive', 'noTerminal', 'noSplash', 'resourceFolder=', 'run', 'runAndExit','ipython'] ) except: print "Unknown option!" print help_msg return interactive = 1 noSplash = False runNetwork = False once = False ipython = False for opt in optlist: if opt[0] in ('-h', '--help'): print help_msg return elif opt[0] in ('-i', '--interactive'): warnings.warn('-i (interactive) is default mode, use --noTerminal to disable it', stacklevel=3) elif opt[0] in ('-t', '--noTerminal'): interactive = 0 elif opt[0] in ('-s', '--noSplash',): noSplash = True elif opt[0] in ('--resourceFolder',): setResourceFolder(opt[1]) elif opt[0] in ('-r', '--run'): runNetwork = True elif opt[0] in ('-e', '--runAndExit'): runNetwork = True once = True elif opt[0] in ('-p', '--ipython'): ipython = True from Support.path import path_text, release_path print 'Run Vision from ', __path__[0] if globals().has_key('ed') is False: root = createRoot() #root.withdraw() ################################################################## # Splash Screen ################################################################## if noSplash is False: splash, about = createSplash() lSplashVisibleTimeStart = time.clock() ################################################################## # Start Vision ################################################################## ed = createVision(root, interactive) globals()['ed'] = ed ################################################################## # Workaround: currently, Vision would crash on some Windows2000 and SGI # when running multi-threaded. We turn MT off for those platforms ################################################################## if os.name == 'nt' or sys.platform == 'irix646': ed.configure(withThreads=0) ################################################################## # Source Resource File (if available) ################################################################## if getResourceFolder() is None: ed.loadLibModule('Vision.StandardNodes') else: ed.sourceFile(resourceFile='_visionrc') # complete vpe menu with additionnal fastLibs if hasattr(ed, 'updateFastLibs'): ed.updateFastLibs() ################################################################## # Make sure splash is visible long enough before removing it ################################################################## if noSplash is False: lSplashVisibleTimeEnd = time.clock() while lSplashVisibleTimeEnd - lSplashVisibleTimeStart < 2: lSplashVisibleTimeEnd = time.clock() splash.finish() ################################################################## # Make vision visible #(before the network loads, so the additional windows will load on top) ################################################################## if once is False: root.deiconify() else: ed = globals()['ed'] root = ed.master root.master.master.deiconify() ################################################################## # Load network(s) if specified at startup ################################################################## lResults = [] if len(args): ed.root.update() # make sure the canvas is shown b4 loading any network lArgIndex = 0 while lArgIndex < len(args): if args[lArgIndex][-6:]=='net.py': ed.loadNetwork(args[lArgIndex], ins=kw.get('ins')) lNodePortValues = [] lArgIndex += 1 while lArgIndex < len(args) and args[lArgIndex][-3:]!='.py': lNodePortValues.append(args[lArgIndex]) lArgIndex += 1 ed.currentNetwork.setNodePortValues(lNodePortValues) if runNetwork: ed.softrunCurrentNet_cb() elif args[lArgIndex][-3:]=='.py': execfile(netName) lArgIndex += 1 else: lArgIndex += 1 # lets obtain the asked outs values outs=kw.get('outs') if outs is not None: for lOut in outs: lOutFound = False for lNodes in ed.currentNetwork.nodes: if lNodes.name == lOut[0]: if lOutFound is True: warnings.warn("found several nodes %s"%lOut[0] ) lOuputPort = lNodes.outputPortByName.get(lOut[1]) if lOuputPort is None: warnings.warn("node %s doesn't have port %s"%(lOut[0],lOut[1]) ) else: lResults.append(lOuputPort.data) lOutFound = True if lOutFound is False: warnings.warn("can't find node %s"%lOut[0] ) if once is True: ed.root.quit() ed.root.destroy() globals().pop('ed') return lResults ################################################################## # Set the Python Shell ################################################################## elif ownInterpreter is True: if interactive: sys.stdin = sys.__stdin__ sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ mod = __import__('__main__') if ipython is True: try: # create IPython shell from IPython.Shell import _select_shell sh = _select_shell([])(argv=[], user_ns=mod.__dict__) sh.mainloop() except: import code try: # hack to really exit code.interact code.interact( 'Vision Interactive Shell', local=mod.__dict__) except: pass else: import code try: # hack to really exit code.interact code.interact( 'Vision Interactive Shell', local=mod.__dict__) except: pass else: ed.master.mainloop() else: return lResults
def buildFormDescr(self, formName): if not formName == 'BugReport': return email = Tkinter.StringVar() try:#get email from .registration old_rc = getResourceFolder() regfile = os.path.join(old_rc, ".registration") if os.path.exists(regfile): form_dict = pickle.load(open(regfile, 'rb')) if form_dict.has_key("Email"): email.set(form_dict['Email']) except: pass idf = InputFormDescr(title='Bug Report') idf.append({'name':'shortdesclabel', 'widgetType':Tkinter.Label, 'wcfg':{'text':'Summary (one line description)', }, 'gridcfg':{'sticky':'nw','columnspan':3}}) idf.append({'name':'shortdescadd', 'widgetType':Pmw.ScrolledText, #'parent':'SHORTDESCGROUP', 'label_text':'Summary', 'labelpos':'n', 'text_padx':20, 'text_pady':2, 'wcfg':{}, 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) idf.append({'name':'desclabel', 'widgetType':Tkinter.Label, 'wcfg':{'text':'Description', }, 'gridcfg':{'sticky':'nw','columnspan':3}}) idf.append({'name':'descadd', 'widgetType':Pmw.ScrolledText, #'parent':'DESCGROUP', 'labelpos':'n', 'label_text':'Description', 'defaultValue':"""Please provide steps to reproduce the bug and any other information that would help us in fixing this bug.""", 'wcfg':{}, 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) idf.append({'name':'PMVLOGGROUP', 'widgetType':Pmw.Group, # 'labelpos':'n', 'container':{'PMVLOGGROUP':"w.interior()"}, 'wcfg':{'tag_text':'Check to attach Pmv Log','tag_pyclass':Tkinter.Checkbutton,'tag_variable':Tkinter.IntVar(),'tag_command':self.showpmvlog_cb}, 'collapsedsize':0, 'gridcfg':{'sticky':'wnse', 'columnspan':3}}) idf.append({'name':'pmvlogtext', 'widgetType':Pmw.ScrolledText, 'tag_text':"PmvLog", 'parent':'PMVLOGGROUP', 'wcfg':{}, 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) idf.append({'name':'PDBFILEGROUP', 'widgetType':Pmw.Group, 'container':{'PDBFILEGROUP':"w.interior()"}, 'wcfg':{'tag_text':'Attach Files'}, 'collapsedsize':0, 'gridcfg':{'sticky':'wnse', 'columnspan':3}}) idf.append({'name':'pdbfileadd', 'widgetType':Pmw.ScrolledListBox, 'parent':'PDBFILEGROUP', 'wcfg':{}, 'listbox_height':1, 'gridcfg':{'sticky':'wesn','columnspan':3,'row':1,'column':0} }) idf.append({'name':'DeleteSelected', 'widgetType':Tkinter.Button, 'defaultValue':0, 'parent':'PDBFILEGROUP', 'wcfg':{'text':'Delete Selected Files', 'width':38, 'state':'disabled', 'command':self.delete_selected_cb, }, 'gridcfg':{'sticky':'nw','row':2,'column':0,'columnspan':2}}) idf.append({'name':'AttachMore', 'widgetType':Tkinter.Button, 'defaultValue':0, 'parent':'PDBFILEGROUP', 'wcfg':{'text':'Attach File ..', 'width':37, 'command':self.attachmore_cb, }, 'gridcfg':{'sticky':'ne','row':2,'column':1,'columnspan':2,}}) idf.append({'name':'emailentrylab', 'widgetType':Tkinter.Label, 'wcfg':{'text':"Email Address (optional). Used to notify important updates about this bug.\n"+ "Please register your email at http://mgldev.scripps.edu/bugs before using this form." }, 'gridcfg':{'sticky':'nw', 'columnspan':3}}) idf.append({'name':'emailentry', 'widgetType':Tkinter.Entry, 'wcfg':{'textvariable':email }, 'gridcfg':{'sticky':'wesn', 'columnspan':3}}) idf.append({'name':'uploadbutton', 'widgetType':Tkinter.Button, 'defaultValue':0, 'wcfg':{'text':'Submit Bug Report', 'width':37, 'command':self.show_upload_page, }, 'gridcfg':{'sticky':'nw','columnspan':2,'row':9,'column':0,}}) idf.append({'name':'dismiss', 'widgetType':Tkinter.Button, 'wcfg':{'text':'DISMISS', 'width':38, 'command':self.dismiss_cb, }, 'gridcfg':{'sticky':'ne','columnspan':2,'row':9,'column':1,}}) return idf
def doit(self): if self.root is None: self.root = Tkinter.Toplevel() self.root.withdraw() # the vision font must be decided in vision or _visionrc, not here anymore # if 'changeFont' in self.vf.commands.keys(): # currentFont = self.vf.changeFont.getCurrentFont() # self.ed = VisualProgramingEnvironment( # master=self.root, font=currentFont, withShell=0) # else: self.ed = VisualProgramingEnvironment(master=self.root, withShell=0) self.root.protocol("WM_DELETE_WINDOW", self.hide) if getResourceFolder() is None: self.ed.loadLibModule('Vision.StandardNodes') else: self.ed.sourceFile(resourceFile='_visionrc') self.ed.updateFastLibs() filemenu = self.ed.menuButtons['File'].menu filemenu.entryconfig(filemenu.index('Quit'),command = self.hide) # let Vision know which PMV instance runs it self.ed.vf = self.vf # add handle to Pmv library instance from Pmv.VisionInterface.PmvNodes import pmvlib self.lib = pmvlib # initialize the API between PMV and Vision self.vf.visionAPI.setEditor(self.ed) self.vf.visionAPI.setLibrary(self.lib) # add Pmv library to Vision self.ed.addLibraryInstance(pmvlib, 'Pmv.VisionInterface.PmvNodes', 'pmvlib') # add Standard library to Vision from Vision.StandardNodes import stdlib self.ed.addLibraryInstance(stdlib, 'Vision.StandardNodes', 'stdlib') # add MolKit library to Vision if needed if len(self.vf.Mols): from MolKit.VisionInterface.MolKitNodes import molkitlib self.ed.addLibraryInstance( molkitlib, 'MolKit.VisionInterface.MolKitNodes', 'molkitlib') # add molecule nodes to Pmv library if molecules were loaded in # Pmv before Vision was started for obj, name, kw in self.vf.visionAPI.objects: self.vf.visionAPI.addNodeToLibrary(obj, name, kw) # is ARTK running? if so, we need to add the library and nodes if hasattr(self.vf, 'art') and self.vf.art.visionAPI is not None: visionAPI = self.vf.art.visionAPI visionAPI.setEditor(self.ed) from ARViewer.VisionInterface.ARNodes import artlib visionAPI.setLibrary(artlib) visionAPI.ed.addLibraryInstance( artlib, 'ARTK.VisionInterface.ARNodes', 'artlib') # add nodes to ARTK library for obj, name, kw in visionAPI.objects: visionAPI.addNodeToLibrary(obj, name, kw) # and add link to ARViewer self.ed.art = self.vf.art elif self.vf.GUI.toolbarCheckbuttons['Vision']['Variable'].get() == 0 and self.root: self.root.withdraw() elif self.vf.GUI.toolbarCheckbuttons['Vision']['Variable'].get() == 1 and self.root: self.root.deiconify() ################################################################## # FIXME: # Workaround: currently, Vision would crash on some Windows2000 and SGI # when running multi-threaded. We turn MT off by default ################################################################## #if sys.platform == 'win32' or sys.platform == 'irix646': self.ed.configure(withThreads=0)