Changeset b3e8629 in sasview for src/sas/qtgui/Utilities
- Timestamp:
- Nov 9, 2017 8:41:54 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- cee5c78
- Parents:
- 749b715
- git-author:
- Piotr Rozyczko <rozyczko@…> (10/26/17 03:13:05)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (11/09/17 08:41:54)
- Location:
- src/sas/qtgui/Utilities
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Utilities/CategoryInstaller.py
r125c4be rb3e8629 103 103 master_category_dict[category].append(\ 104 104 (model, model_enabled_dict[model])) 105 return OrderedDict(sorted( master_category_dict.items(), key=lambda t: t[0]))105 return OrderedDict(sorted(list(master_category_dict.items()), key=lambda t: t[0])) 106 106 107 107 @staticmethod … … 126 126 """ 127 127 _model_dict = { model.name: model for model in model_list} 128 _model_list = _model_dict.keys()128 _model_list = list(_model_dict.keys()) 129 129 130 130 serialized_file = None … … 143 143 add_list = _model_list 144 144 del_name = False 145 for cat in master_category_dict.keys():145 for cat in list(master_category_dict.keys()): 146 146 for ind in range(len(master_category_dict[cat])): 147 147 model_name, enabled = master_category_dict[cat][ind] … … 152 152 model_enabled_dict.pop(model_name) 153 153 except: 154 logging.error("CategoryInstaller: %s", sys.exc_ value)154 logging.error("CategoryInstaller: %s", sys.exc_info()[1]) 155 155 else: 156 156 add_list.remove(model_name) -
src/sas/qtgui/Utilities/ConnectionProxy.py
rdc5ef15 rb3e8629 1 1 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 import urllib 23 import urllib.request, urllib.error, urllib.parse 4 4 import sys 5 5 import json … … 33 33 if sys.platform == 'win32': 34 34 try: 35 import _winreg as winreg # used from python 2.0-2.635 import winreg as winreg # used from python 2.0-2.6 36 36 except: 37 37 import winreg # used from python 2.7 onwards … … 45 45 this_name, this_val, this_type = winreg.EnumValue(net, i) 46 46 subkeys[this_name] = this_val 47 if 'AutoConfigURL' in subkeys.keys() and len(subkeys['AutoConfigURL']) > 0:47 if 'AutoConfigURL' in list(subkeys.keys()) and len(subkeys['AutoConfigURL']) > 0: 48 48 pac_files.append(subkeys['AutoConfigURL']) 49 49 elif sys.platform == 'darwin': … … 53 53 networks = sys_prefs['NetworkServices'] 54 54 # loop through each possible network (e.g. Ethernet, Airport...) 55 for network in networks.items():55 for network in list(networks.items()): 56 56 # the first part is a long identifier 57 57 net_key, network = network 58 if 'ProxyAutoConfigURLString' in network['Proxies'].keys():58 if 'ProxyAutoConfigURLString' in list(network['Proxies'].keys()): 59 59 pac_files.append( 60 60 network['Proxies']['ProxyAutoConfigURLString']) … … 73 73 logging.debug('Trying pac file (%s)...' % this_pac_url) 74 74 try: 75 response = urllib 2.urlopen(75 response = urllib.request.urlopen( 76 76 this_pac_url, timeout=self.timeout) 77 77 logging.debug('Succeeded (%s)...' % this_pac_url) … … 101 101 # information is retrieved from the OS X System Configuration 102 102 # Framework. 103 proxy = urllib 2.ProxyHandler()103 proxy = urllib.request.ProxyHandler() 104 104 else: 105 105 # If proxies is given, it must be a dictionary mapping protocol names to 106 106 # URLs of proxies. 107 proxy = urllib 2.ProxyHandler(proxy_dic)108 opener = urllib 2.build_opener(proxy)109 urllib 2.install_opener(opener)107 proxy = urllib.request.ProxyHandler(proxy_dic) 108 opener = urllib.request.build_opener(proxy) 109 urllib.request.install_opener(opener) 110 110 111 111 def connect(self): … … 114 114 @return: response object from urllib2.urlopen 115 115 ''' 116 req = urllib 2.Request(self.url)116 req = urllib.request.Request(self.url) 117 117 response = None 118 118 try: 119 119 logging.debug("Trying Direct connection to %s..."%self.url) 120 response = urllib 2.urlopen(req, timeout=self.timeout)121 except Exception ,e:120 response = urllib.request.urlopen(req, timeout=self.timeout) 121 except Exception as e: 122 122 logging.debug("Failed!") 123 123 logging.debug(e) … … 125 125 logging.debug("Trying to use system proxy if it exists...") 126 126 self._set_proxy() 127 response = urllib 2.urlopen(req, timeout=self.timeout)128 except Exception ,e:127 response = urllib.request.urlopen(req, timeout=self.timeout) 128 except Exception as e: 129 129 logging.debug("Failed!") 130 130 logging.debug(e) … … 135 135 logging.debug("Trying to use the proxy %s found in proxy.pac configuration"%proxy) 136 136 self._set_proxy(proxy) 137 response = urllib 2.urlopen(req, timeout=self.timeout)138 except Exception ,e:137 response = urllib.request.urlopen(req, timeout=self.timeout) 138 except Exception as e: 139 139 logging.debug("Failed!") 140 140 logging.debug(e) … … 151 151 response = c.connect() 152 152 if response is not None: 153 print 50 * '-'153 print(50 * '-') 154 154 content = json.loads(response.read().strip()) 155 155 pprint(content) -
src/sas/qtgui/Utilities/GuiUtils.py
- Property mode changed from 100644 to 100755
r88e1f57 rb3e8629 9 9 import warnings 10 10 import webbrowser 11 import url parse11 import urllib.parse 12 12 13 13 warnings.simplefilter("ignore") … … 86 86 #logging.error("Error loading %s/%s: %s" % (path, confg_file, sys.exc_value)) 87 87 except ValueError: 88 print "Value error"88 print("Value error") 89 89 pass 90 90 finally: … … 242 242 """ 243 243 assert isinstance(item, QtGui.QStandardItem) 244 assert isinstance(update_data, QtCore.QVariant) 245 py_update_data = update_data.toPyObject() 244 #assert isinstance(update_data, QtCore.QVariant) 245 #py_update_data = update_data.toPyObject() 246 py_update_data = update_data 246 247 247 248 # Check if data with the same ID is already present … … 249 250 plot_item = item.child(index) 250 251 if plot_item.isCheckable(): 251 plot_data = plot_item.child(0).data() .toPyObject()252 plot_data = plot_item.child(0).data() #.toPyObject() 252 253 if plot_data.id is not None and plot_data.id == py_update_data.id: 253 254 # replace data section in item … … 270 271 Adds QVariant 'update_data' to that row. 271 272 """ 272 assert isinstance(update_data, QtCore.QVariant) 273 py_update_data = update_data.toPyObject() 273 #assert isinstance(update_data, QtCore.QVariant) 274 #py_update_data = update_data.toPyObject() 275 py_update_data = update_data 274 276 275 277 checkbox_item = QtGui.QStandardItem() … … 309 311 object_item = QtGui.QStandardItem() 310 312 object_item.setText(name) 311 object_item.setData(QtCore.QVariant(update_data)) 313 #object_item.setData(QtCore.QVariant(update_data)) 314 object_item.setData(update_data) 312 315 313 316 # Append the new row to the main item … … 319 322 """ 320 323 assert isinstance(model_item, QtGui.QStandardItemModel) 321 assert isinstance(filename, basestring)324 assert isinstance(filename, str) 322 325 323 326 # Iterate over model looking for named items 324 item = list(filter(lambda i: str(i.text()) == filename, 325 [model_item.item(index) for index in range(model_item.rowCount())])) 327 item = list([i for i in [model_item.item(index) for index in range(model_item.rowCount())] if str(i.text()) == filename]) 326 328 return item[0] if len(item)>0 else None 327 329 … … 331 333 """ 332 334 assert isinstance(model_item, QtGui.QStandardItemModel) 333 assert isinstance(filename, basestring)335 assert isinstance(filename, str) 334 336 335 337 plot_data = [] … … 339 341 if str(item.text()) == filename: 340 342 # TODO: assure item type is correct (either data1/2D or Plotter) 341 plot_data.append(item.child(0).data() .toPyObject())343 plot_data.append(item.child(0).data()) #.toPyObject()) 342 344 # Going 1 level deeper only 343 345 for index_2 in range(item.rowCount()): … … 345 347 if item_2 and item_2.isCheckable(): 346 348 # TODO: assure item type is correct (either data1/2D or Plotter) 347 plot_data.append(item_2.child(0).data() .toPyObject())349 plot_data.append(item_2.child(0).data()) #.toPyObject()) 348 350 349 351 return plot_data … … 361 363 if item.isCheckable() and item.checkState() == QtCore.Qt.Checked: 362 364 # TODO: assure item type is correct (either data1/2D or Plotter) 363 plot_data.append((item, item.child(0).data() .toPyObject()))365 plot_data.append((item, item.child(0).data())) #.toPyObject())) 364 366 # Going 1 level deeper only 365 367 for index_2 in range(item.rowCount()): … … 367 369 if item_2 and item_2.isCheckable() and item_2.checkState() == QtCore.Qt.Checked: 368 370 # TODO: assure item type is correct (either data1/2D or Plotter) 369 plot_data.append((item_2, item_2.child(0).data() .toPyObject()))371 plot_data.append((item_2, item_2.child(0).data())) #.toPyObject())) 370 372 371 373 return plot_data … … 419 421 Check the URL first, though. 420 422 """ 421 parsed_url = url parse.urlparse(url)423 parsed_url = urllib.parse.urlparse(url) 422 424 if parsed_url.scheme: 423 425 webbrowser.open(url) 424 426 else: 425 427 msg = "Attempt at opening an invalid URL" 426 raise AttributeError , msg428 raise AttributeError(msg) 427 429 428 430 def retrieveData1d(data): … … 433 435 if not isinstance(data, Data1D): 434 436 msg = "Incorrect type passed to retrieveData1d" 435 raise AttributeError , msg437 raise AttributeError(msg) 436 438 try: 437 439 xmin = min(data.x) … … 441 443 data.filename 442 444 #logging.error(msg) 443 raise ValueError , msg445 raise ValueError(msg) 444 446 445 447 text = data.__str__() … … 485 487 if not isinstance(data, Data2D): 486 488 msg = "Incorrect type passed to retrieveData2d" 487 raise AttributeError , msg489 raise AttributeError(msg) 488 490 489 491 text = data.__str__() … … 499 501 dy_val = 0.0 500 502 len_data = len(data.qx_data) 501 for index in xrange(0, len_data):503 for index in range(0, len_data): 502 504 x_val = data.qx_data[index] 503 505 y_val = data.qy_data[index] … … 756 758 The assumption - data stored in SasView standard, in child 0 757 759 """ 758 return item.child(0).data() .toPyObject()760 return item.child(0).data() #.toPyObject() 759 761 760 762 def formatNumber(value, high=False): -
src/sas/qtgui/Utilities/LocalConfig.py
- Property mode changed from 100644 to 100755
rdc5ef15 rb3e8629 139 139 """ 140 140 if __EVT_DEBUG__: 141 print "%g: %s" % (time.clock(), message)141 print("%g: %s" % (time.clock(), message)) 142 142 143 143 if __EVT_DEBUG_2_FILE__: -
src/sas/qtgui/Utilities/ObjectLibrary.py
r61a92d4 rb3e8629 9 9 10 10 def deleteObjectByRef(obj): 11 for name, object in this._objects.ite ritems():11 for name, object in this._objects.items(): 12 12 if object == obj: 13 13 del this._objects[name] … … 22 22 23 23 def listObjects(): 24 return this._objects.keys()24 return list(this._objects.keys()) 25 25 26 26 -
src/sas/qtgui/Utilities/SasviewLogger.py
- Property mode changed from 100644 to 100755
r83eb5208 rb3e8629 19 19 def write(self, msg): 20 20 if(not self.signalsBlocked()): 21 self.messageWritten.emit( unicode(msg))21 self.messageWritten.emit(str(msg)) 22 22 23 23 @staticmethod
Note: See TracChangeset
for help on using the changeset viewer.