mirror of https://github.com/vitalif/phantomjs
Stop using globals() on scrollPosition()
parent
9469a0d343
commit
403572b633
|
@ -389,6 +389,27 @@ class WebPage(QObject):
|
|||
def libraryPath(self, dirPath):
|
||||
self.m_libraryPath = dirPath
|
||||
|
||||
@pyqtProperty('QVariantMap')
|
||||
def scrollPosition(self):
|
||||
scroll = self.m_webPage.scrollPosition
|
||||
result = {
|
||||
'left': scroll.x(),
|
||||
'top': scroll.y()
|
||||
}
|
||||
return result
|
||||
|
||||
@scrollPosition.setter
|
||||
def scrollPosition(self, size):
|
||||
positions = {'left': 0, 'top': 0}
|
||||
for item in positions:
|
||||
try:
|
||||
positions[item] = int(size[item])
|
||||
if positions[item] < 0:
|
||||
positions[item] = 0
|
||||
except KeyError:
|
||||
positions[item] = self.m_webPage.scrollPosition[item]
|
||||
self.m_webPage.scrollPosition = QPoint(positions['left'], positions['top'])
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def uploadFile(self, selector, fileName):
|
||||
el = self.m_mainFrame.findFirstElement(selector)
|
||||
|
@ -426,25 +447,4 @@ class WebPage(QObject):
|
|||
|
||||
self.m_webPage.setViewportSize(QSize(sizes['width'], sizes['height']))
|
||||
|
||||
@pyqtProperty('QVariantMap')
|
||||
def scrollPosition(self):
|
||||
scroll = self.m_webPage.scrollPosition
|
||||
result = {
|
||||
'left': scroll.x(),
|
||||
'top': scroll.y()
|
||||
}
|
||||
return result
|
||||
|
||||
@scrollPosition.setter
|
||||
def scrollPosition(self, size):
|
||||
names = ('left', 'top')
|
||||
for item in names:
|
||||
try:
|
||||
globals()[item] = int(size[item])
|
||||
if globals()[item] < 0:
|
||||
globals()[item] = 0
|
||||
except KeyError:
|
||||
globals()[item] = getattr(self.m_webPage.scrollPosition, item)()
|
||||
self.m_webPage.scrollPosition = QPoint(left, top)
|
||||
|
||||
do_action('WebPage')
|
||||
|
|
Loading…
Reference in New Issue