Skip to content

Commit

Permalink
Merge pull request #15 from ales-erjavec/pyqt-modernize
Browse files Browse the repository at this point in the history
PyQt modernize
  • Loading branch information
kernc committed Oct 14, 2016
2 parents 9886403 + 3026bb3 commit 9f15272
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
38 changes: 18 additions & 20 deletions orangecontrib/network/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,12 @@ class SNAP(object):

def __init__(self):
self.network_list = []
self.http = None
self._netmanager = None
self._reply = None

def parse_snap(self, error, done_callback, progress_callback=None):
if not error:
#self.last_total = self.http.bytesAvailable()
#if self.last_total <= 0:
# self.last_total = 24763

src = str(self.http.readAll())
src = bytes(self._reply.readAll()).decode("utf-8")
snap_parser = SNAPParser()
snap_parser.feed(src)

Expand Down Expand Up @@ -220,20 +217,21 @@ def get_network_list(self, done_callback=None, progress_callback=None):
self.network_list = snap_parser.networks
return self.network_list
else:
import PyQt4.QtNetwork
from PyQt4.QtCore import QObject, SIGNAL

self.http = PyQt4.QtNetwork.QHttp()

QObject.connect(self.http, SIGNAL('done(bool)'), lambda error,\
done_callback=done_callback, progress_callback=progress_callback: \
self.parse_snap(error, done_callback, progress_callback))

if progress_callback is not None:
QObject.connect(self.http, SIGNAL('dataReadProgress(int,int)'), progress_callback)

self.http.setHost('snap.stanford.edu')
self.http.get('/data/index.html')
from PyQt4.QtNetwork import \
QNetworkAccessManager, QNetworkRequest, QNetworkReply
from PyQt4.QtCore import QUrl
self._netmanager = QNetworkAccessManager()
request = QNetworkRequest(
QUrl("http://snap.stanford.edu/data/index.html"))
self._reply = reply = self._netmanager.get(request)

@reply.finished.connect
def onfinished():
error = self._reply.error() != QNetworkReply.NoError
self.parse_snap(error, done_callback, progress_callback)
self._reply.close()

reply.downloadProgress.connect(progress_callback)

def get_network(self, id):
"""Find and return the network by name. If no network is found, return
Expand Down
5 changes: 2 additions & 3 deletions orangecontrib/network/widgets/OWNxAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __init__(self):
self.graphIndices = gui.createTabPage(self.tabs, "Graph-level indices")
self.nodeIndices = gui.createTabPage(self.tabs, "Node-level indices")
self.tabs.setCurrentIndex(self.tab_index)
self.connect(self.tabs, SIGNAL("currentChanged(int)"), lambda index: setattr(self, 'tab_index', index))
self.tabs.currentChanged.connect(lambda index: setattr(self, 'tab_index', index))

for name, default, label, type, algorithm in self.methods:
if type == NODELEVEL:
Expand Down Expand Up @@ -279,8 +279,7 @@ def add_job(self, method):

#if type == NODELEVEL:
job = WorkerThread(self, name, label, type, algorithm)
self.connect(job, SIGNAL("terminated()"), lambda j=job: self.job_terminated(j))
self.connect(job, SIGNAL("finished()"), lambda j=job: self.job_finished(j))
job.finished.connect(lambda j=job: self.job_finished(j))
self.job_queue.insert(0, job)
setattr(self, "lbl_" + job.name, " waiting")

Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/network/widgets/OWNxFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self):
self.data_index = 0

#GUI
self.controlArea.layout().setMargin(4)
self.controlArea.layout().setContentsMargins(4, 4, 4, 4)
self.box = gui.widgetBox(self.controlArea, box="Graph File", orientation="vertical")
hb = gui.widgetBox(self.box, orientation="horizontal")
self.filecombo = gui.comboBox(hb, self, "net_index", callback=self.selectNetFile)
Expand Down
7 changes: 4 additions & 3 deletions orangecontrib/network/widgets/OWNxSNAP.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import os.path
import itertools

from PyQt4.QtGui import *
from PyQt4.QtGui import QPixmap
from PyQt4.QtGui import QLabel, QScrollArea, QLayout, QAbstractItemView

import Orange.data
import orangecontrib.network as network
Expand Down Expand Up @@ -53,7 +54,6 @@ def __init__(self):
self.setMinimumSize(960, 600)

def add_tables(self, networks):
from PyQt4.QtCore import SIGNAL
self.networks = networks
self.tables = []

Expand All @@ -74,7 +74,8 @@ def add_tables(self, networks):
table.verticalHeader().hide()
table.setSelectionMode(QAbstractItemView.SingleSelection)
table.setSelectionBehavior(QAbstractItemView.SelectRows)
self.connect(table, SIGNAL('itemSelectionChanged()'), lambda table=table: self.select_network(table))
table.itemSelectionChanged.connect(
lambda table=table: self.select_network(table))

for i, net in enumerate(network_group):
lbl = QLabel("<a href='"+ net.link +"'>" + net.name + "</a>")
Expand Down
2 changes: 1 addition & 1 deletion orangecontrib/network/widgets/graphview.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def wheelEvent(self, event):
if event.orientation() != Qt.Vertical: return
self.scaleView(2**(event.delta() / 240))
def scaleView(self, factor):
magnitude = self.matrix().scale(factor, factor).mapRect(QRectF(0, 0, 1, 1)).width()
magnitude = self.transform().scale(factor, factor).mapRect(QRectF(0, 0, 1, 1)).width()
if 0.2 < magnitude < 30:
self.scale(factor, factor)
# Reposition nodes' labela and edges, both of which are node-dependend
Expand Down

0 comments on commit 9f15272

Please sign in to comment.