Ejemplo n.º 1
0
class Window (QMainWindow):

	def __init__ (self, app):
		QMainWindow.__init__ (self)
		self.resize (800, 600)
		
		self.app = app
		
		self.setWindowTitle ("QRearrangeableLayout - Test")
		
		self.list1 = QListWidget ()
		self.list1.addItem (QListWidgetItem ("List1"))
		self.list2 = QListWidget ()
		self.list2.addItem (QListWidgetItem ("List2"))
		for i in range (0,10):
			self.list1.addItem (QListWidgetItem ("Another item"))
			self.list2.addItem (QListWidgetItem ("Another item"))
		
		self.central = QRearrangeableLayout (self.app, self)
		self.central.setRearrangeable (True)
		self.setCentralWidget (self.central)
		
		self.mainhbox = QHBoxLayout ()
		self.central.setLayout (self.mainhbox)
		
		self.hbox = QSplitter (Qt.Horizontal)
		self.hbox.addWidget (self.list1)
		self.hbox.addWidget (self.list2)
		
		self.mainhbox.addWidget (self.hbox)
	def unregisterWidget (self, nameOrWidget):
		if isinstance (nameOrWidget, str):
			QRearrangeableLayout.removeWidget (self.widgets [nameOrWidget])
			del self.widgets [nameOrWidget]
			return
		elif isinstance (nameOrWidget, QWidget):
			name = [n for n, w in self.widgets.iteritems () if v == nameOrWidget][0]
			self.unregisterWidget (name)
			return
		raise KeyError ("No such widget: " + repr (nameOrWidget))
Ejemplo n.º 3
0
	def __init__ (self, app):
		QMainWindow.__init__ (self)
		self.app = app

		self.innerName = ""
		
		self.setWindowTitle ("MP")

		self.setWindowState (Qt.WindowMaximized)
		
		#self.resize (800, 600)
		
		self.menuBar ().addMenu (_("&File")).addAction (_("Rearrange window contents")).triggered.connect (lambda:self.layoutOuter.setRearrangeable (not self.layoutOuter.rearrangeable ()))
		
		self.toolbar = self.addToolBar ("blub")
		self.toolbar.addAction (QIcon ("images/play.png"), _("Play")).triggered.connect (self.app.playpause)
		self.toolbar.addAction (QIcon ("images/skip.png"), _("Skip")).triggered.connect (self.app.skip)
		
		self.setupPlayingWidget ()
		self.toolbar.addWidget (self.playingWidget).setVisible (True)

		self.mainbox = QVBoxLayout ()
		self.central = QWidget ()
		self.central.setLayout (self.mainbox)
		self.setCentralWidget (self.central)

		self.layoutOuter = QRearrangeableLayout (app)
		self.layoutOuterBox = QHBoxLayout ()
		self.layoutOuterBox.setContentsMargins (QMargins (0, 0, 0, 0))
		self.layoutOuter.setLayout (self.layoutOuterBox)
		self.mainbox.addWidget (self.layoutOuter)

		self.layoutInner = QRearrangeableLayout (app)
		self.layoutInnerBox = QHBoxLayout ()
		self.layoutInnerBox.setContentsMargins (QMargins (0, 0, 0, 0))
		self.layoutInner.setLayout (self.layoutInnerBox)
		#self.layoutOuterBox.addWidget (self.layoutInner)

		# Navigation widget
		#self.navigation = Navigation.Navigation (self.app)

		# Loader
		self.loaderOuter = QRearrangeableLayoutLoader (self.layoutOuter)
		self.loaderInner = QRearrangeableLayoutLoader (self.layoutInner)

		self.loaderOuter.registerWidget ("innerLayout", self.layoutInner)

		self.show ()
Ejemplo n.º 4
0
class MainWindow (QMainWindow):
	
	def __init__ (self, app):
		QMainWindow.__init__ (self)
		self.app = app

		self.innerName = ""
		
		self.setWindowTitle ("MP")

		self.setWindowState (Qt.WindowMaximized)
		
		#self.resize (800, 600)
		
		self.menuBar ().addMenu (_("&File")).addAction (_("Rearrange window contents")).triggered.connect (lambda:self.layoutOuter.setRearrangeable (not self.layoutOuter.rearrangeable ()))
		
		self.toolbar = self.addToolBar ("blub")
		self.toolbar.addAction (QIcon ("images/play.png"), _("Play")).triggered.connect (self.app.playpause)
		self.toolbar.addAction (QIcon ("images/skip.png"), _("Skip")).triggered.connect (self.app.skip)
		
		self.setupPlayingWidget ()
		self.toolbar.addWidget (self.playingWidget).setVisible (True)

		self.mainbox = QVBoxLayout ()
		self.central = QWidget ()
		self.central.setLayout (self.mainbox)
		self.setCentralWidget (self.central)

		self.layoutOuter = QRearrangeableLayout (app)
		self.layoutOuterBox = QHBoxLayout ()
		self.layoutOuterBox.setContentsMargins (QMargins (0, 0, 0, 0))
		self.layoutOuter.setLayout (self.layoutOuterBox)
		self.mainbox.addWidget (self.layoutOuter)

		self.layoutInner = QRearrangeableLayout (app)
		self.layoutInnerBox = QHBoxLayout ()
		self.layoutInnerBox.setContentsMargins (QMargins (0, 0, 0, 0))
		self.layoutInner.setLayout (self.layoutInnerBox)
		#self.layoutOuterBox.addWidget (self.layoutInner)

		# Navigation widget
		#self.navigation = Navigation.Navigation (self.app)

		# Loader
		self.loaderOuter = QRearrangeableLayoutLoader (self.layoutOuter)
		self.loaderInner = QRearrangeableLayoutLoader (self.layoutInner)

		self.loaderOuter.registerWidget ("innerLayout", self.layoutInner)

		self.show ()


	def load (self):
		self.loaderOuter.load (os.getenv ("HOME") + '/.mp/layoutOuter.xml')


	def closeEvent (self, event):
		if self.innerName != "":
			self.loaderInner.save (os.getenv ("HOME") + '/.mp/layouts/' + self.innerName + '.xml')
		self.loaderOuter.save (os.getenv ("HOME") + '/.mp/layoutOuter.xml')


	def setInnerLayout (self, name, initialCreate):

		if name == self.innerName:
			return

		# save old layout
		if self.innerName != "":
			self.loaderInner.save (os.getenv ("HOME") + '/.mp/layouts/' + self.innerName + '.xml')

		try:
			self.loaderInner.load (os.getenv ("HOME") + '/.mp/layouts/' + name + '.xml')
		except (IOError):
			widget = initialCreate ()

			self.layoutInner.layout ().removeItem (self.layoutInner.layout ().itemAt (0))
			self.layoutInner.layout ().addWidget (widget)

		self.innerName = name


	def setupPlayingWidget (self):
		
		self.playingWidget = QLabel (_("Stopped"))
		self.playingWidget.setMargin (5)
		
		self.app.trackChanged.connect (self.updatePlayingWidget)
	
	def updatePlayingWidget (self, track):
		
		if track == None:
			text = _("Stopped")
		else:
			text = _("Currently playing:") + " " + track
		
		self.playingWidget.setText (text)

	"""