Skip to content

Commit

Permalink
change loop widget to a QWidget and nest into an ordinary QDockWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Mar 16, 2012
1 parent 87de911 commit d7bf908
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 331 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@

PLUGINNAME = loopvisiblelayers

PY_FILES = loopvisiblelayers.py loopvisiblelayersdock.py __init__.py
PY_FILES = loopvisiblelayers.py loopvisiblelayerswidget.py __init__.py

EXTRAS = icon.png icons/* metadata.txt README

#UI_FILES = ui_loopvisiblelayers.py ui_loopvisiblelayersdock.py
UI_FILES = ui_loopvisiblelayersdock.py
UI_FILES = ui_loopvisiblelayerswidget.py

RESOURCE_FILES = resources_rc.py

Expand Down
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The Controls are Play/Pause, Stop, Next.
============================================================
TODO

- change config path
- fix nested group handling - nested groups are added to loop list unnecessarily
- use one-shot timers instead of programmed one
- create rendering/canvas cache for each loop, instead of rendering each time
Expand Down
84 changes: 25 additions & 59 deletions loopvisiblelayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,97 +25,63 @@
# Initialize Qt resources from file resources.py
import resources_rc
# Import the code for the dialog
from loopvisiblelayersdock import LoopVisibleLayersDock
from loopvisiblelayerswidget import LoopVisibleLayersWidget

class LoopVisibleLayers:

def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
self.loopWidget = None
self.dockWidget = None

def initGui(self):
# Create action that will start plugin configuration
print('initGui')
self.action = QAction(QIcon(':/plugins/loopvisiblelayers/icon.png'), \
'Loop Visible Layers', self.iface.mainWindow())
# connect the action to the run method
# connect the action
QObject.connect(self.action, SIGNAL('triggered()'), self.showHideDock)

# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
#self.iface.addPluginToMenu('Loop Visible Layers', self.action)

# show dock
self.showDock()

# create the loop widget
self.loopWidget = LoopVisibleLayersWidget(self.iface)
self.restoreTimerDelay()
settings = QSettings()
if not settings.value('/Qgis/enable_render_caching').toBool():
self.loopWidget.setStatus( 'Enable render caching to improve performance' )

# create and show the dock
self.dockWidget = QDockWidget('Loop Visible Layers', self.iface.mainWindow() )
self.dockWidget.setObjectName('Loop Visible Layers')
self.dockWidget.setWidget(self.loopWidget)
QObject.connect(self.dockWidget, SIGNAL('topLevelChanged ( bool )'), self.resizeDock)
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockWidget)

def showHideDock(self):
if not self.dockWidget.isVisible():
self.showDock()
self.dockWidget.setVisible( True )
else:
self.dockWidget.setVisible( False )

# run method that performs all the real work
def showDock(self):
# create and show the dock
self.dockWidget = LoopVisibleLayersDock(self.iface.mainWindow(), self.iface)
self.restoreDockLocation()
self.restoreTimerDelay()

settings = QSettings()
if not settings.value('/Qgis/enable_render_caching').toBool():
self.dockWidget.setStatus( 'Enable render caching to improve performance' )

self.iface.addDockWidget(self.dockWidget.getLocation(), self.dockWidget)
# show the dialog
#dlg.show()

#resize dock to minimum size if it is floating
def resizeDock(self, topLevel):
if topLevel:
self.dockWidget.resize( self.dockWidget.minimumSize() )

def unload(self):
# Remove the plugin menu item and icon
#self.iface.removePluginMenu('Loop Visible Layers',self.action)
self.iface.removeToolBarIcon(self.action)
#remove the dock
self.saveTimerDelay()
self.saveDockLocation()
self.dockWidget.close()
self.dockWidget.actionClose()


def saveDockLocation(self):
settings = QSettings()
#code from dockable mirror map
floating = self.dockWidget.isFloating()

if floating:
nFloating = 1
position = '%s %s' % (self.dockWidget.pos().x(), self.dockWidget.pos().y())
else:
nFloating = 0
position = u'%s' % self.dockWidget.getLocation()

settings.setValue( '/PythonPlugins/LoopVisibleLayers/floating', floating )
settings.setValue( '/PythonPlugins/LoopVisibleLayers/position', QString(position) )
#size = '%s %s' % (dockwidget.size().width(), dockwidget.size().height())
#QgsProject.instance().writeEntry( 'DockableMirrorMap', '/mirror%s/size' % i, QString(size) )

def restoreDockLocation(self):
settings = QSettings()

floating = settings.value('/PythonPlugins/LoopVisibleLayers/floating').toBool()
self.dockWidget.setFloating( floating )
if not floating:
position = settings.value( '/PythonPlugins/LoopVisibleLayers/position' ).toString()
if position is None or position=='':
position = Qt.LeftDockWidgetArea
else:
#position = int(position.split(' ')[0])
position = int(position)
#position = Qt.LeftDockWidgetArea
self.dockWidget.setLocation( position )
self.loopWidget.actionClose()

def saveTimerDelay(self):
timerDelay = self.dockWidget.getTimerDelay()
timerDelay = self.loopWidget.getTimerDelay()
settings = QSettings()
timerDelayStr = settings.value('/PythonPlugins/LoopVisibleLayers/delay')
if ( timerDelayStr.toFloat()[0] != timerDelay ):
Expand All @@ -132,4 +98,4 @@ def restoreTimerDelay(self):
if timerDelay <= 0:
timerDelay = 1.0

self.dockWidget.setTimerDelay( timerDelay )
self.loopWidget.setTimerDelay( timerDelay )
19 changes: 6 additions & 13 deletions loopvisiblelayersdock.py → loopvisiblelayerswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
from qgis.core import *
from qgis.gui import *

from ui_loopvisiblelayersdock import Ui_LoopVisibleLayersDock as Ui_Widget
from ui_loopvisiblelayerswidget import Ui_LoopVisibleLayersWidget as Ui_Widget

try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s

# create the dock
class LoopVisibleLayersDock(QtGui.QDockWidget, Ui_Widget):
def __init__(self, parent, iface):
# create the widget
class LoopVisibleLayersWidget(QtGui.QWidget, Ui_Widget):
def __init__(self, iface):

QtGui.QDockWidget.__init__(self, parent)
QtGui.QWidget.__init__(self)
# Set up the user interface from Designer.
self.setupUi(self)

Expand All @@ -48,7 +48,6 @@ def __init__(self, parent, iface):
self.groupRels = None
self.bakLayerIds = None
self.count = 0
self.location = Qt.LeftDockWidgetArea
self.freeze = True
self.updateCount = 0
self.signalsLegendIface = False # are the new legendInterface() signals available?
Expand All @@ -74,7 +73,6 @@ def __init__(self, parent, iface):
self.setStatus( '' ) #invisible by default

# signals/slots
QObject.connect(self, SIGNAL('dockLocationChanged(Qt::DockWidgetArea)'), self.setLocation)
QObject.connect(self, SIGNAL('topLevelChanged(bool)'), self.resizeMin)
QObject.connect(self.btnStart, SIGNAL('clicked()'), self.actionStartPause)
QObject.connect(self.btnForward, SIGNAL('clicked()'), self.actionForward)
Expand All @@ -97,6 +95,7 @@ def __init__(self, parent, iface):
QObject.connect( self.iface.legendInterface(), SIGNAL( 'itemRemoved()' ), self.checkGroupsChangedLegendIface )
QObject.connect( self.iface.legendInterface(), SIGNAL( 'groupRelationsChanged()' ), self.checkGroupsChangedLegendIface )
QObject.connect( self.iface.mapCanvas(), SIGNAL( 'stateChanged( int )' ), self.checkGroupsChanged )
#should we disconnect when unload?

#update groups on init
self.checkGroupsChanged()
Expand Down Expand Up @@ -372,12 +371,6 @@ def getTimerDelay(self):
def setTimerDelay(self,timerDelay):
self.spinDelay.setValue( timerDelay )

def getLocation(self):
return self.location

def setLocation(self, location):
self.location = location

# minimize widget
def resizeMin(self):
if self.isFloating():
Expand Down
Loading

0 comments on commit d7bf908

Please sign in to comment.