def __onOpenProject(self): if gSettings.contains('currentproject') and QMessageBox.warning(self, 'Changing project', 'Any unsaved changes will be lost. Continue?', QMessageBox.Yes | QMessageBox.No) == QMessageBox.No: return currentPath = os.getcwd() if gSettings.contains('currentproject'): project = str(gSettings.value('currentproject')) if fileutil.exists(project): currentPath = os.path.dirname(project) res = QFileDialog.getOpenFileName(self, 'Open project', currentPath, 'Project files (*%s)' % PROJ_EXT) if not res: return self.__openProject(res)
def __init__(self, shotManager, timer, overlays=None): """ :type overlays: Overlays """ # We found that not setting a version in Ubunto didn't work # so out of laziness we try to set a very high version # and Qt will fall back to highest available. glFormat = QGLFormat() glFormat.setVersion(4, 1) glFormat.setProfile(QGLFormat.CoreProfile) super(SceneView, self).__init__() self._timer = timer self._animator = shotManager self.__overlays = overlays self._scene = None self._size = 1, 1 self._previewRes = None, None, 1.0 if gSettings.contains('GLViewScale'): self._previewRes = None, None, float( gSettings.value('GLViewScale')) self._cameraInput = None self.setFocusPolicy(Qt.StrongFocus) self._textures = {} self._prevTime = time.time()
def __onNewProject(self): if gSettings.contains('currentproject') and QMessageBox.warning(self, 'Creating new project', 'Any unsaved changes will be lost. Continue?', QMessageBox.Yes | QMessageBox.No) == QMessageBox.No: return currentPath = os.getcwd() if gSettings.contains('currentproject'): project = str(gSettings.value('currentproject')) if fileutil.exists(project): currentPath = os.path.dirname(project) res = QFileDialog.getSaveFileName(self, 'Create new project', currentPath, 'Project folder') if not res: return shutil.copytree(DEFAULT_PROJECT, res, ignore=lambda p, f: [] if os.path.basename(p).lower() == 'Scenes' else [n for n in f if os.path.splitext(n)[-1].lower() in IGNORED_EXTENSIONS]) projectFile = os.path.join(res, os.path.basename(res) + PROJ_EXT) fileutil.create(projectFile) self.__openProject(projectFile)
def __initializeProject(self): if gSettings.contains('currentproject'): project = str(gSettings.value('currentproject')) if fileutil.exists(project): self.__openProject(project) return project = [x for x in list(os.listdir(os.getcwd())) if x.endswith(PROJ_EXT)] if project: self.__openProject(os.path.join(os.getcwd(), project[0])) return
def __init__(self, shotManager, timer, overlays=None): """ :type overlays: Overlays """ super(SceneView, self).__init__() self._timer = timer self._animator = shotManager self.__overlays = overlays self._scene = None self._size = 1, 1 self._previewRes = None, None, 1.0 if gSettings.contains('GLViewScale'): self._previewRes = None, None, float(gSettings.value('GLViewScale')) self._cameraInput = None self.setFocusPolicy(Qt.StrongFocus) self._textures = {} self._prevTime = time.time()
def __init__(self, shotManager, timer, overlays=None): """ :type overlays: Overlays """ # We found that not setting a version in Ubunto didn't work glFormat = QGLFormat() glFormat.setVersion(4, 1) glFormat.setProfile(QGLFormat.CoreProfile) glFormat.setDefaultFormat(glFormat); super(SceneView, self).__init__() self._timer = timer self._animator = shotManager self.__overlays = overlays self._scene = None self._size = 1, 1 self._previewRes = None, None, 1.0 if gSettings.contains('GLViewScale'): self._previewRes = None, None, float(gSettings.value('GLViewScale')) self._cameraInput = None self.setFocusPolicy(Qt.StrongFocus) self._textures = {} self._prevTime = time.time()
def __init__(self): super(App, self).__init__(gSettings) self.setAnimated(False) if datetime.datetime.month == '12': self.setWindowIcon(icons.get('Candy Cane')) else: self.setWindowIcon(icons.get('SqrMelon')) self.setWindowTitle('SqrMelon') self.setDockNestingEnabled(True) self.__menuBar = QMenuBar() self.setMenuBar(self.__menuBar) self.__dockWidgetMenu = QMenu('Components') self.__statusBar = QStatusBar() self.setStatusBar(self.__statusBar) self._timer = Timer() self.__shotsManager = ShotManager() self.__shotsManager.viewShotAction.connect(self.__onViewShot) self.__graphEditor = CurveEditor(self._timer) self.__shotsManager.currentChanged.connect(self.__graphEditor.setShot) self.__overlays = Overlays() self.__sceneView = SceneView(self.__shotsManager, self._timer, self.__overlays) self.__overlays.changed.connect(self.__sceneView.repaint) self._timer.timeChanged.connect(self.__setCurrentShot) self.__shotsManager.shotPinned.connect(self.__setCurrentShot) self.__shotsManager.shotsEnabled.connect(self.__setCurrentShot) self.__shotsManager.shotsDisabled.connect(self.__setCurrentShot) self.setCentralWidget(None) cameraView = Camera(self.__shotsManager, self.__graphEditor, self._timer) cameraView.cameraChanged.connect(self.__sceneView.repaint) self.__graphEditor.requestPositionKey.connect(cameraView.forwardPositionKey) self.__graphEditor.requestRotationKey.connect(cameraView.forwardRotationKey) self.__sceneView.setCamera(cameraView) self.__projectMenu = self.__menuBar.addMenu('&Project') self.__projectMenu.addAction('&New').triggered.connect(self.__onNewProject) self.__projectMenu.addAction('&Open').triggered.connect(self.__onOpenProject) save = self.__projectMenu.addAction('&Save') save.setShortcut(QKeySequence.Save) save.setShortcutContext(Qt.ApplicationShortcut) save.triggered.connect(self.__onCtrlS) self.__sceneList = SceneList() self.__shotsManager.findSceneRequest.connect(self.__sceneList.selectSceneWithName) self.__sceneList.requestCreateShot.connect(self.__shotsManager.createShot) self.__sceneList.setEnabled(False) self.__sceneList.setShotsManager(self.__shotsManager) self.__profiler = Profiler() self.timeSlider = TimeSlider(self._timer, self.__shotsManager) self.__shotsManager.shotChanged.connect(self.timeSlider.repaint) self._addDockWidget(self.__sceneList, where=Qt.TopDockWidgetArea) self._addDockWidget(self.__shotsManager, where=Qt.TopDockWidgetArea) viewDock = self._addDockWidget(self.__sceneView, '3D View', where=Qt.TopDockWidgetArea) logDock = self._addDockWidget(PyDebugLog.create(), 'Python log', where=Qt.TopDockWidgetArea) self.tabifyDockWidget(logDock, viewDock) self._addDockWidget(self.timeSlider, where=Qt.LeftDockWidgetArea) cameraDock = self._addDockWidget(cameraView, where=Qt.LeftDockWidgetArea) overlayDock = self._addDockWidget(self.__overlays, 'Overlays', Qt.LeftDockWidgetArea) self.tabifyDockWidget(overlayDock, cameraDock) self._addDockWidget(self.__graphEditor, where=Qt.BottomDockWidgetArea) self._addDockWidget(self.__profiler, where=Qt.BottomDockWidgetArea, direction=Qt.Vertical) self.__initializeProject() undoStack, cameraUndoStack = self.__graphEditor.undoStacks() undo = undoStack.createUndoAction(self, '&Undo') undo.setShortcut(QKeySequence.Undo) undo.setShortcutContext(Qt.ApplicationShortcut) redo = undoStack.createRedoAction(self, '&Redo') redo.setShortcuts(QKeySequence.Redo) redo.setShortcutContext(Qt.ApplicationShortcut) camUndo = cameraUndoStack.createUndoAction(self, 'Undo') camUndo.setShortcuts(QKeySequence('[')) camUndo.setShortcutContext(Qt.ApplicationShortcut) camRedo = cameraUndoStack.createRedoAction(self, 'Redo') camRedo.setShortcuts(QKeySequence(']')) camRedo.setShortcutContext(Qt.ApplicationShortcut) camKey = QAction('&Key camera', self) camKey.setShortcuts(QKeySequence(Qt.Key_K)) camKey.setShortcutContext(Qt.ApplicationShortcut) camKey.triggered.connect(cameraView.insertKey) camToggle = QAction('&Toggle camera control', self) camToggle.setShortcuts(QKeySequence(Qt.Key_T)) camToggle.setShortcutContext(Qt.ApplicationShortcut) camToggle.triggered.connect(cameraView.toggle) camCopAnim = QAction('Snap came&ra to animation', self) camCopAnim.setShortcuts(QKeySequence(Qt.Key_R)) camCopAnim.setShortcutContext(Qt.ApplicationShortcut) camCopAnim.triggered.connect(cameraView.copyAnim) self.__editMenu = self.__menuBar.addMenu('Edit') self.__editMenu.addAction(undo) self.__editMenu.addAction(redo) self.__editMenu.addAction(camUndo) self.__editMenu.addAction(camRedo) self.__editMenu.addSeparator() self.__editMenu.addAction(camKey) self.__editMenu.addAction(camToggle) self.__editMenu.addAction(camCopAnim) toolsMenu = self.__menuBar.addMenu('Tools') toolsMenu.addAction('Color Picker').triggered.connect(self.__colorPicker) lock = toolsMenu.addAction('Lock UI') lock.setCheckable(True) lock.toggled.connect(self.__toggleUILock) fs = toolsMenu.addAction('Full screen viewport') fs.setShortcut(Qt.Key_F11) fs.setShortcutContext(Qt.ApplicationShortcut) fs.triggered.connect(self.__fullScreenViewport) self.__previewMenu = toolsMenu.addMenu('Preview resolution') previewRadioGroup = QActionGroup(self) # add action & connect it to the setPreviewRes with right parameters hd = self.__previewMenu.addAction('1080p (HD)') hd.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, 1920, 1080, 1.0)) hd.setCheckable(True) hd.setActionGroup(previewRadioGroup) hdready = self.__previewMenu.addAction('720p') hdready.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, 1280, 720, 1.0)) hdready.setCheckable(True) hdready.setActionGroup(previewRadioGroup) sdready = self.__previewMenu.addAction('480p') sdready.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, 854, 480, 1.0)) sdready.setCheckable(True) sdready.setActionGroup(previewRadioGroup) viewport = self.__previewMenu.addAction('Viewport') viewport.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, None, None, 1.0)) viewport.setCheckable(True) viewport.setActionGroup(previewRadioGroup) half = self.__previewMenu.addAction('1/2 view') half.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, None, None, 0.5)) half.setCheckable(True) half.setActionGroup(previewRadioGroup) quart = self.__previewMenu.addAction('1/4 view') quart.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, None, None, 0.25)) quart.setCheckable(True) quart.setActionGroup(previewRadioGroup) eight = self.__previewMenu.addAction('1/8 view') eight.triggered.connect(functools.partial(self.__sceneView.setPreviewRes, None, None, 0.125)) eight.setCheckable(True) eight.setActionGroup(previewRadioGroup) toolsMenu.addAction('Record').triggered.connect(self.__record) option = viewport if gSettings.contains('GLViewScale'): option = {1.0: viewport, 0.5: half, 0.25: quart, 0.125: eight}[float(gSettings.value('GLViewScale'))] option.setChecked(True) self.__menuBar.addMenu(self.__dockWidgetMenu) self.__menuBar.addAction('About').triggered.connect(self.__aboutDialog) self.__restoreUiLock(lock)