def createMenus(self): self.fileMenu = QtGui.QMenu(tr("&File"),self) self.fileMenu.addAction(self.openAct) self.fileMenu.addAction(self.printAct) self.fileMenu.addSeparator() self.viewMenu = QtGui.QMenu(tr("&View"),self) self.viewMenu.addAction(self.zoomInAct) self.viewMenu.addAction(self.zoomOutAct) self.viewMenu.addAction(self.normalSizeAct) self.viewMenu.addSeparator() self.viewMenu.addAction(self.fitToImageAct) self.viewMenu.addAction(self.fitToWindowAct) self.helpMenu = QtGui.QMenu(tr("&Help"),self) self.helpMenu.addAction(self.aboutAct) self.menuBar().addMenu(self.fileMenu) self.menuBar().addMenu(self.viewMenu) self.menuBar().addMenu(self.helpMenu) if isinstance(self.parent,QtGui.QApplication): self.fileMenu.addAction(self.exitAct) self.helpMenu.addAction(self.aboutQtAct) elif isinstance(self.parent,QtGui.QDialog): self.fileMenu.addAction(self.acceptAct) self.fileMenu.addAction(self.rejectAct)
def __init__(self,windowname,size=(800,600),pos=(0,0),bdsize=(0,0)): """Constructs the GUI. The GUI has a central canvas for drawing, a menubar and a toolbar on top, and a statusbar at the bottom. """ pf.debug('Creating Main Window',pf.DEBUG.GUI) self.on_exit = [] QtGui.QMainWindow.__init__(self) self.fullscreen = False self.setWindowTitle(windowname) # add widgets to the main window # The status bar pf.debug('Creating Status Bar',pf.DEBUG.GUI) self.statusbar = self.statusBar() #self.statusbar.setSizePolicy(QtGui.QSizePolicy.Minimum,QtGui.QSizePolicy.Minimum) #self.statusbar.setFixedHeight(32) #self.statusbar.setContentsMargins(0,0,0,0) #widgets.addEffect(self.statusbar,color=(255,0,0)) self.curproj = widgets.ButtonBox('Project:',[('None',fileMenu.openExistingProject)]) self.curfile = widgets.ButtonBox('',[('Script:',toggleAppScript),('None',fileMenu.openScript)]) self.curdir = widgets.ButtonBox('Cwd:',[('None',draw.askDirname)]) self.canPlay = False self.canEdit = False # The menu bar pf.debug('Creating Menu Bar',pf.DEBUG.GUI) self.menu = menu.MenuBar('TopMenu') self.setMenuBar(self.menu) # The toolbar pf.debug('Creating ToolBar',pf.DEBUG.GUI) self.toolbar = self.addToolBar('Top ToolBar') self.editor = None # Create a box for the central widget self.box = QtGui.QWidget() self.setCentralWidget(self.box) self.boxlayout = QtGui.QVBoxLayout() self.boxlayout.setContentsMargins(*pf.cfg['gui/boxmargins']) self.box.setLayout(self.boxlayout) #self.box.setFrameStyle(qt.QFrame.Sunken | qt.QFrame.Panel) #self.box.setLineWidth(2) # Create a splitter self.splitter = QtGui.QSplitter() self.boxlayout.addWidget(self.splitter) self.splitter.setOrientation(QtCore.Qt.Vertical) self.splitter.show() # self.central is the central widget of the main window # self.viewports is its layout, containing multiple viewports pf.debug('Creating Central Widget',pf.DEBUG.GUI) self.central = QtGui.QWidget() self.central.autoFillBackground() #self.central.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Sunken) self.central.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding,QtGui.QSizePolicy.MinimumExpanding) self.central.resize(*pf.cfg['gui/size']) self.viewports = viewport.MultiCanvas(parent=self.central) self.centralgrid = QtGui.QGridLayout() self.centralgrid.addLayout(self.viewports,0,0) self.central.setLayout(self.centralgrid) # Create the message board self.board = Board() #self.board.setPlainText(pf.Version+' started') # Put everything together self.splitter.addWidget(self.central) self.splitter.addWidget(self.board) #self.splitter.setSizes([(800,200),(800,600)]) self.box.setLayout(self.boxlayout) # Create the top menu pf.debug('Creating Menus',pf.DEBUG.GUI) menudata = menu.createMenuData() self.menu.insertItems(menudata) # ... and the toolbar self.actions = toolbar.addActionButtons(self.toolbar) # timeout button toolbar.addTimeoutButton(self.toolbar) self.menu.show() # Define Toolbars pf.debug('Creating Toolbars',pf.DEBUG.GUI) self.camerabar = self.updateToolBar('camerabar','Camera ToolBar') self.modebar = self.updateToolBar('modebar','RenderMode ToolBar') self.viewbar = self.updateToolBar('viewbar','Views ToolBar') self.toolbars = [self.camerabar, self.modebar, self.viewbar] ############### CAMERA menu and toolbar ############# if self.camerabar: toolbar.addCameraButtons(self.camerabar) toolbar.addPerspectiveButton(self.camerabar) ############### RENDERMODE menu and toolbar ############# modes = [ 'wireframe', 'smooth', 'smoothwire', 'flat', 'flatwire' ] if pf.cfg['gui/modemenu']: mmenu = QtGui.QMenu('Render Mode') else: mmenu = None #menutext = '&' + name.capitalize() self.modebtns = menu.ActionList( modes,guifunc.renderMode,menu=mmenu,toolbar=self.modebar) # Add the toggle type buttons if self.modebar: toolbar.addTransparencyButton(self.modebar) if self.modebar and pf.cfg['gui/lightbutton']: toolbar.addLightButton(self.modebar) if self.modebar and pf.cfg['gui/normalsbutton']: toolbar.addNormalsButton(self.modebar) if self.modebar and pf.cfg['gui/shrinkbutton']: toolbar.addShrinkButton(self.modebar) if mmenu: # insert the mode menu in the viewport menu pmenu = self.menu.item('viewport') pmenu.insertMenu(pmenu.item('background color'),mmenu) ############### VIEWS menu ################ if pf.cfg['gui/viewmenu']: if pf.cfg['gui/viewmenu'] == 'main': parent = self.menu before = 'help' else: parent = self.menu.item('camera') before = parent.item('---') self.viewsMenu = menu.Menu('&Views',parent=parent,before=before) else: self.viewsMenu = None defviews = pf.cfg['gui/defviews'] views = [ v[0] for v in defviews ] viewicons = [ v[1] for v in defviews ] self.viewbtns = menu.ActionList( views,self.setView, menu=self.viewsMenu, toolbar=self.viewbar, icons = viewicons ) ## TESTING SAVE CURRENT VIEW ## self.saved_views = {} self.saved_views_name = utils.NameSequence('View') if self.viewsMenu: name = self.saved_views_name.next() self.menu.item('camera').addAction('Save View',self.saveView) # Restore previous pos/size pf.debug('Restore size/pos',pf.DEBUG.GUI) self.resize(*size) self.move(*pos) self.board.resize(*bdsize) pf.debug('Set Curdir',pf.DEBUG.GUI) self.setcurdir() # redirect standard/error output if option set # # TODO: we should redirect it to a buffer and # wait until GUI shown, then show in board # else show on stdout/err #self.board.redirect(pf.cfg['gui/redirect']) if pf.options.debuglevel: s = sizeReport(self,'DEBUG: Main:') + \ sizeReport(self.central,'DEBUG: Canvas:') + \ sizeReport(self.board,'DEBUG: Board:') pf.debug(s,pf.DEBUG.GUI) # Drawing lock self.drawwait = pf.cfg['draw/wait'] self.drawlock = drawlock.DrawLock() # Materials and Lights database self.materials = canvas.createMaterials() ## for m in self.materials: ## print self.materials[m] # Modeless child dialogs self.doc_dialog = None pf.debug('Done initializing GUI',pf.DEBUG.GUI) # Set up signal/slot connections self.signals = signals.Signals() self.signals.FULLSCREEN.connect(self.fullScreen) # Set up hot keys: hitting the key will emit the corresponding signal self.hotkey = { QtCore.Qt.Key_F2: self.signals.SAVE, QtCore.Qt.Key_F5: self.signals.FULLSCREEN, }