def _open_workspace(self): ''' Open workspace window with selected scans, set workspace to be central widget. ''' if self._source: try: self._workspace = WorkSpace(self._source, self) self._connect_workspace_opened() file_name = self._source.split('/')[-1] self.setWindowTitle(WINDOW_TITLE + ' - ' + file_name) except Exception as ex: print(ex) self.setCentralWidget(self._workspace)
def initUI(self): QToolTip.setFont(QFont('SansSerif', 10)) self.c = Communicate() self.c.closeApp.connect(self.close) self.setWindowTitle('Videomaker') self.setWindowIcon(QIcon('icons/video.png')) self.center() self.workspace = WorkSpace() self.widget = self.workspace.widget self.setCentralWidget(self.widget) self.speedIndexBox = 2 self.createActions() self.showMaximized()
def m_initialize(self, processId=None, rootUri=None, rootPath=None, initializationOptions=None, **_kwargs): log.info('Language server initialized with %s %s %s %s', processId, rootUri, rootPath, initializationOptions) self.workspace = WorkSpace(rootUri, self._endpoint) try: import mypy except ImportError: log.error('Do not install mypy module!') self.workspace.show_message('Mypy is not installed.', lsp.MessageType.Warning) return {'capablilities': None} self.mypyserver = mypy_server.Server(mypy_server.options, mypy_server.DEFAULT_STATUS_FILE) return {"capabilities": self.capablilities()}
PLATFORM = 'Android' IS_REBUILD = True VERSION_NUMBER = '' # 参数判空处理 if VERSION_NUMBER is None: VERSION_NUMBER = '' # current path CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) # InitWorkSpace workdirbase = os.path.dirname(os.path.dirname(CURRENT_PATH)) if not os.path.isdir(workdirbase): os.makedirs(workdirbase) workspace = WorkSpace(workdirbase, BRANCH_NAME) # UnityPath UNITY_PATH = globalvalue_tool.get_value("windows_unity_path") if common.is_macos(): UNITY_PATH = globalvalue_tool.get_value("macos_uinty_path") # Product Update def UpdateProduct(): if VERSION_NUMBER != '': workspace.up_product(VERSION_NUMBER) else: workspace.up_product()
##Check for collision if not self.ws.pointInBounds(newNode.point): continue robot.setState(newNode.point) collider = robot.getCollider() if self.ws.inCollision(collider): continue pathCollider = TrajectoryCollider(trajectory, 1.0) if self.ws.inCollision(pathCollider): continue ##Add new node self.nodes.append(newNode) ##Check goal if self.inGoalRegion(newNode, robot): self.solution = newNode return newNode print('Failed') if __name__ == '__main__': ws = WorkSpace() ws.readObsticles('obsticles1.csv') rrt = RRT(ws, 30, 20) rrt.findPath(np.array([10, 10]), np.array([400, 400]))
get_main_version = sys.argv[3] get_platform = sys.argv[4] get_project_path = sys.argv[5] get_project_name = sys.argv[6] get_package_dir_name = sys.argv[7] get_is_packbase = (sys.argv[8] == 'True') get_is_restart = sys.argv[9] get_is_background = sys.argv[10] print "[updater_pack] Params - SVN_BRANCH: {} SVN_VERSION: {} MAIN_VERSION: {} PLATFORM: {} PROJECT_PATH: {} PROJECT_NAME: {} PACKAGE_DIR_NAME: {} IS_PACKBASE: {} IS_RESTART: {} IS_BACKGRUND: {} ".format( get_svn_branch, get_svn_version, get_main_version, get_platform, get_project_path, get_project_name, get_package_dir_name, get_is_packbase, get_is_restart, get_is_background) # current path CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) # InitWorkSpace workdirbase = os.path.dirname(os.path.dirname(CURRENT_PATH)) if not os.path.isdir(workdirbase): os.makedirs(workdirbase) workspace = WorkSpace(workdirbase, get_svn_branch) update_package_setting = workspace.get_update_package_setting() if not update_package_setting or not update_package_setting.has_key(get_package_dir_name): print('package_dir_name:{} not in package_setting') exit(1) package_setting = update_package_setting[get_package_dir_name] pack(get_svn_branch, get_svn_version, get_main_version, get_platform, get_project_path, get_project_name, package_setting, get_is_packbase, is_restart=get_is_restart, is_bacekground_update=get_is_background)
def initWorkSpace(self): workspace = WorkSpace(self) self.setCentralWidget(workspace) return workspace
class MainWindow(QtWidgets.QMainWindow, FetalMRI_mainwindow.Ui_MainWindow): ''' Main window display of the program. Displays upon startup. User can load directory from this window and open the workspace window. ''' def __init__(self, data_dir_path): QtWidgets.QMainWindow.__init__(self) FetalMRI_mainwindow.Ui_MainWindow.__init__(self) self._workspace = None self._cwd = os.getcwd() # defined in FetalMRI_design.Ui_MainWindow self.setupUi(self) # setup customary design options self.init_ui() # path to directory holding scans # TODO: if this is not empty, then open a workspace self._source = data_dir_path # create local folder for files generated in any session self._local_folder = None def init_ui(self): self.setWindowTitle(WINDOW_TITLE) self.setWindowIcon(QtGui.QIcon(BASE_DIR + 'images/buttons_PNG103.png')) self.showMaximized() # connect buttons self.load_nii_btn.clicked.connect(self._load_source) self.load_dir_btn.clicked.connect(lambda: self._load_source(True)) self._connect_menus() # reset images - backup copies may not exist self.label.setPixmap(QtGui.QPixmap(BASE_DIR + 'images/brain_large.jpg')) self.label_2.setPixmap(QtGui.QPixmap(BASE_DIR + 'images/casmip.png')) def _connect_menus(self): # File menu self.actionOpen_Nifti_File.setShortcut('Ctrl+o') self.actionOpen_Nifti_File.setStatusTip('Open Nii File') self.actionOpen_Nifti_File.triggered.connect(self._load_source) self.actionOpen_Directory.setShortcut('Ctrl+d') self.actionOpen_Directory.setStatusTip('Open directory of dicoms') self.actionOpen_Directory.triggered.connect( lambda: self._load_source(True)) self.actionExit.setShortcut('Ctrl+Q') self.actionExit.setStatusTip('Exit') self.actionExit.triggered.connect(self.close) # Workspace menu self.actionSave_Segmentation.triggered.connect(self._save_segmentation) self.actionOpen_Segmentation.triggered.connect(self._open_segmentation) self.actionSave_All_Segmentation.triggered.connect( self._save_all_segmentations) # View menu self.actionShow_Segmentation.triggered.connect( self._toggle_segmentation) self.actionShow_Scan.triggered.connect(self._toggle_scan) # Help menu self.actionAbout.triggered.connect(self._about_dialog) def _connect_workspace_opened(self): '''Connect all actions that are valid only when workspace has been opened.''' self.actionSave_Points.triggered.connect(self._workspace.save_points) self.actionLoad_Points.triggered.connect(self._workspace.load_points) self.actionSave_Segmentation.setEnabled(True) self.actionOpen_Segmentation.setEnabled(True) self.actionSave_Points.setEnabled(True) self.actionLoad_Points.setEnabled(True) self.actionShow_Segmentation.setEnabled(True) self.actionSave_All_Segmentation.setEnabled(True) self.actionSave_current_scan_ROI.triggered.connect( self._workspace.save_current_scan_numpy_slice) self.actionSave_all_scans_ROI.triggered.connect( self._workspace.save_all_scans_numpy_slices) def _toggle_segmentation(self): '''Display/Hide segmentation from showing in workspace.''' if self._workspace: self._workspace.toggle_segmentation( self.actionShow_Segmentation.isChecked()) def _toggle_scan(self): '''Display/Hide scan from showing in workspace.''' if self._workspace: self._workspace.toggle_scan(self.actionShow_Scan.isChecked()) def _open_workspace(self): ''' Open workspace window with selected scans, set workspace to be central widget. ''' if self._source: try: self._workspace = WorkSpace(self._source, self) self._connect_workspace_opened() file_name = self._source.split('/')[-1] self.setWindowTitle(WINDOW_TITLE + ' - ' + file_name) except Exception as ex: print(ex) self.setCentralWidget(self._workspace) def _create_local_folder(self, path): ''' Create local folder with unique name. :param path: [str] create folder with this as base name. :return: [str] full path of local folder ''' if path.endswith('.gz'): path = path[:-3] if path.endswith('.nii'): path = path[:-4] local_folder = os.getcwd() + '\\Nifti Files\\' + os.path.basename(path) if not os.path.isdir(local_folder): try: os.mkdir(local_folder) except NotImplementedError: # dir_fd not implemented on platform print('Unable to create directory %s' % local_folder) local_folder = '' self._local_folder = local_folder return local_folder def _create_local_nifti_copy(self, nifti_path): '''Create copy of nifti in local folder.''' local_folder = self._create_local_folder(nifti_path) base_name = os.path.basename(nifti_path) dest = os.path.join(local_folder, base_name) try: shutil.copyfile(nifti_path, dest) except shutil.SameFileError: # will raise if copy of file already exists pass except IOError: print('Permission denied.') def _create_local_nifti_from_dicom(self, directory): ''' Create nifti files from dicoms and save as a Nifti file in a local folder. Will override existing nifti file. :param directory [str]: path to directory containing dicoms :return [str]: path to nifti file, if successfully created ''' local_folder = self._create_local_folder(os.path.normpath(directory)) dicom2nifti.convert_directory(self._source, local_folder, reorient=False) nii_files = os.listdir(local_folder) if nii_files: return local_folder + "\\" + nii_files[0] else: print('Error in dicom directory.') @QtCore.pyqtSlot() def _load_source(self, dir_only=False): ''' Allow user to choose scans which will be loaded into program. If directory was successfully chosen, open workspace. :param dir_only [bool]: if True, allow user to choose a directory. If false, must choose nifti file. ''' chosen_file = self._user_choose_file(dir_only) if chosen_file: # user can choose only one file at a time self._source = chosen_file if dir_only: self._source = self._create_local_nifti_from_dicom( self._source) else: if '.nii' not in self._source: self._source = None self._create_local_nifti_copy(self._source) print("Local Nifti file created: {}".format(self._source)) try: if not self._workspace: # open new workspace self._open_workspace() else: # add to existing workspace self._workspace.add_scan(self._source) except Exception as ex: print(ex) def _save_segmentation(self): if self._workspace: self._workspace.save_segmentation() def _save_all_segmentations(self): if self._workspace: self._workspace.save_all_segmentations() def _user_choose_file(self, dir_only=False): file_dialog = QtWidgets.QFileDialog() options = QtWidgets.QFileDialog.Options() # options |= QtWidgets.QFileDialog.DontUseNativeDialog if not dir_only: file_name, _ = QtWidgets.QFileDialog.getOpenFileName( file_dialog, "Open segmentation Nifti file", "", "All files (*);; Nifti Files (*.nii)", options=options) return file_name else: dir_name = QtWidgets.QFileDialog.getExistingDirectory( file_dialog, "Select directory of dicoms", "", options=options) return dir_name def _open_segmentation(self): try: nifti_path = self._user_choose_file() if not nifti_path.endswith('.nii') and not nifti_path.endswith( '.nii.gz'): print("Must choose Nifti format file.") return segmentation = np.array(nib.load(nifti_path).get_data()) segmentation = utils.shape_nifti_2_segtool(segmentation) if self._workspace: self._workspace.set_segmentation(segmentation) except Exception as ex: print('open_segmentation error:', ex) def _about_dialog(self): '''Display the `About` dialog.''' dialog = QtWidgets.QDialog(self) dialog.ui = FetalMRI_About.Ui_Dialog() dialog.ui.setupUi(dialog) dialog.ui.okBtn.clicked.connect(dialog.close) dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose) dialog.exec_()
# ProjectName PROJECT_NAME = globalvalue_tool.get_value("project_name") # 参数判空处理 if VERSION_NUMBER is None: VERSION_NUMBER = '' # current path CURRENT_PATH = os.path.dirname(os.path.abspath(__file__)) # InitWorkSpace workdirbase = os.path.dirname(os.path.dirname(CURRENT_PATH)) if not os.path.isdir(workdirbase): os.makedirs(workdirbase) workspace = WorkSpace(workdirbase, BRANCH_NAME) # Product Update def UpdateProduct(): if VERSION_NUMBER != '': workspace.up_product(VERSION_NUMBER) else: workspace.up_product() # 是否需要打基础包 def NeedBasePack(update_dir): hot_package_dir = os.path.join(os.path.dirname(os.path.dirname(workspace.product_path)), 'FtpShare/HotPackage') hot_package_dir = os.path.join(hot_package_dir, PROJECT_NAME) branch_name = BRANCH_NAME if '/' not in BRANCH_NAME else BRANCH_NAME.replace('/', '_') package_dir_base = os.path.join(hot_package_dir, branch_name)
class Window(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): QToolTip.setFont(QFont('SansSerif', 10)) self.c = Communicate() self.c.closeApp.connect(self.close) self.setWindowTitle('Videomaker') self.setWindowIcon(QIcon('icons/video.png')) self.center() self.workspace = WorkSpace() self.widget = self.workspace.widget self.setCentralWidget(self.widget) self.speedIndexBox = 2 self.createActions() self.showMaximized() def closeEvent(self, event): reply = QMessageBox.question(self, 'Message', 'Are you sure to quit?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: event.accept() else: event.ignore() def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: self.close() if e.key() == Qt.Key_Space: self.workspace.play() def center(self): rectWindow = self.frameGeometry() self.move(rectWindow.topLeft()) def createActions(self): openAction = QAction(QIcon(os.path.join('icons', 'open.png')), 'Open', self) openAction.setShortcut('Ctrl+O') openAction.triggered.connect(self.showOpenDialog) exitAction = QAction(QIcon(os.path.join('icons', 'exit.png')), 'Exit', self) exitAction.setShortcut('Ctrl+Q') exitAction.triggered.connect(qApp.quit) renderAction = QAction(QIcon(os.path.join('icons', 'render.png')), 'Render', self) renderAction.setShortcut('Ctrl+R') renderAction.triggered.connect(self.render) cutAction = QAction(QIcon(os.path.join('icons', 'scissors.png')), 'Cut', self) cutAction.setShortcut('C') cutAction.triggered.connect(self.cut) delAction = QAction(QIcon(os.path.join('icons', 'delete.png')), 'Delete', self) delAction.setShortcut('Delete') delAction.triggered.connect(self.delete) speedAction = QAction(QIcon(os.path.join('icons', 'speed.png')), 'Change speed', self) speedAction.setShortcut('S') speedAction.triggered.connect(self.changeSpeed) imageAction = QAction(QIcon(os.path.join('icons', 'image.png')), 'Add image', self) imageAction.setShortcut('I') imageAction.triggered.connect(self.addImage) undoAction = QAction(QIcon(os.path.join('icons', 'undo.png')), 'Undo', self) undoAction.setShortcut('Ctrl+Z') undoAction.triggered.connect(self.undo) redoAction = QAction(QIcon(os.path.join('icons', 'redo.png')), 'Redo', self) redoAction.setShortcut('Ctrl+Y') redoAction.triggered.connect(self.redo) menu = self.menuBar() file = menu.addMenu('File') file.addAction(openAction) file.addAction(renderAction) file.addAction(exitAction) edit = menu.addMenu('Edit') edit.addAction(undoAction) edit.addAction(redoAction) edit.addSeparator() edit.addAction(cutAction) edit.addAction(delAction) edit.addAction(speedAction) edit.addAction(imageAction) toolBar = self.addToolBar('Cut') toolBar.addAction(undoAction) toolBar.addAction(redoAction) toolBar.addSeparator() toolBar.addAction(cutAction) toolBar.addAction(delAction) toolBar.addAction(speedAction) toolBar.addAction(imageAction) def showOpenDialog(self): fName, filter = QFileDialog.getOpenFileName(self, 'Open file', QDir.current().path()) if fName != '': self.file = fName self.workspace.mediaPlayer.setMedia( QMediaContent(QUrl.fromLocalFile(fName))) self.workspace.playButton.setEnabled(True) self.workspace.mediaPlayer.play() def cut(self): self.workspace.timelineLogic.cut(self.workspace.positionVideo) def delete(self): self.workspace.timelineLogic.delete() def changeSpeed(self): values = [0.5, 0.75, 0, 1.25, 1.5, 1.75, 2] self.s = SpeedDialog(values.index(self.workspace.timelineLogic.speed)) self.s.btn.rejected.connect(self.s.close) self.s.btn.accepted.connect(self.putSpeed) self.s.show() def putSpeed(self): before = self.workspace.timelineLogic.speed speed = self.s.box.currentText() if speed == 'Normal': after = 0 else: after = float(speed) command = SpeedAction(before, after, self.workspace.timelineLogic) self.workspace.timelineLogic.undoStack.push(command) self.s.close() def addImage(self): self.image, filter = QFileDialog.getOpenFileName( self, 'Open image', QDir.current().path(), "Image Files (*.png *.jpg)") if self.image != '': self.i = ImageDialog(self.image) self.i.btn.rejected.connect(self.i.close) self.i.btn.accepted.connect(self.putImagePos) self.i.show() def putImagePos(self): before = self.workspace.timelineLogic.imageToAdd self.i.close() id = self.i.group.checkedId() btn = self.i.group.button(id) posText = btn.text() command = ImageAction(before, (self.image, posText), self.workspace.timelineLogic) self.workspace.timelineLogic.undoStack.push(command) def render(self): fullName = QFileDialog.getSaveFileName(self, 'Render', QDir().currentPath(), 'Video(.mp4)')[0] while os.path.exists(fullName + '.mp4'): message = QMessageBox.warning( self, 'Warning', 'The file with the same name already exists.\nChoose another name.' ) fullName = QFileDialog.getSaveFileName(self, 'Render', QDir().currentPath(), 'Video(.mp4)')[0] if fullName != '': self.workspace.timelineLogic.render(self.file, fullName) message = QMessageBox.information(self, 'Rendering', '<font size=5> Ready! </font>') def undo(self): self.workspace.timelineLogic.undoStack.undo() def redo(self): self.workspace.timelineLogic.undoStack.redo()
if __name__ == '__main__': ##Polygon robot limits = [[0, 20], [0, 20], [-math.pi, math.pi]] robot = Forklift() start = np.array([10, 5, 0]) #goal = np.array([50, 60, 4.6]) #goal = np.array([50, 60, 1.51]) #goal = np.array([50, 60, 3.14]) goal = np.array([10, 15, 3.14]) goalRadius = 0.5 eps = 4.0 ws = WorkSpace(limits) ws.addObsticle(RectangleCollider([10, 10], 4.0, 1.0, 0)) ws.addObsticle(RectangleCollider([7.5, 15], 1.0, 1.5, 0)) ws.addObsticle(CircleCollider([15, 10], 1.0)) rrt = RRT(ws, eps, goalRadius, limits) goalNode = rrt.findPath(start, goal, robot, maxNodes=500) window = WorkSpaceWindow(ws, rrt, robot, width=500, height=500, scale=500 / 20)
class PythonLanguageServer(MethodDispatcher): def __init__(self, reader, writer): self._jsonrpcstreamReader = JsonRpcStreamReader(reader) self._jsonrpcstreamWriter = JsonRpcStreamWriter(writer) self._endpoint = Endpoint(self, self._jsonrpcstreamWriter.write) self.isrunning = True self.workspace = None self.config = None def run(self): self._jsonrpcstreamReader.listen(self._endpoint.consume) def m_shutdown(self): self.isrunning = False def m_exit(self): self._jsonrpcstreamReader.close() self._jsonrpcstreamWriter.close() self._endpoint.shutdown() self.workspace = None def __getitem__(self, item): log.info(item) return super(PythonLanguageServer, self).__getitem__(item) def capablilities(self): import mypy_server is_patched_mypy = mypy_server.is_patched_mypy() if not is_patched_mypy: log.info( 'Using non-patched mypy, rich language features not available.' ) python_38 = sys.version_info >= (3, 8) if not python_38: log.info( 'Using Python before 3.8, rich language features not available.' ) rich_analysis_available = is_patched_mypy and python_38 # 这三个功能不知道是干嘛用的 server_capabilities = { "textDocumentSync": lsp.TextDocumentSyncKind.FULL, # full document text 'definitionProvider': rich_analysis_available, 'hoverProvider': rich_analysis_available } return server_capabilities def m_initialize(self, processId=None, rootUri=None, rootPath=None, initializationOptions=None, **_kwargs): log.info('Language server initialized with %s %s %s %s', processId, rootUri, rootPath, initializationOptions) self.workspace = WorkSpace(rootUri, self._endpoint) try: import mypy except ImportError: log.error('Do not install mypy module!') self.workspace.show_message('Mypy is not installed.', lsp.MessageType.Warning) return {'capablilities': None} self.mypyserver = mypy_server.Server(mypy_server.options, mypy_server.DEFAULT_STATUS_FILE) return {"capabilities": self.capablilities()} def m_initialized(self, **_kwargs): pass def m_text_document__did_open(self, textDocument=None, **_kwargs): self.workspace.put_document(textDocument['uri'], textDocument['text'], version=textDocument.get('version')) def m_text_document__did_change(self, contentChanges=None, textDocument=None, **_kwargs): log.info(contentChanges) for change in contentChanges: self.workspace.update_document(textDocument['uri'], change, version=textDocument.get('version')) log.info(self.workspace._docs.items()) to_check = [] for uri, doc in self.workspace._docs.items(): fspath = uris.to_fs_path(uri) to_check.append(fspath) if mypy_server.mypy_version > "0.720": result = self.mypyserver.cmd_check(to_check, False, 80) else: result = self.mypyserver.cmd_check(to_check) diags = mypy_server.parse_mypy_out(result['out']) diagsparams = PublishDiagnosticParams(uri, diags).getDict() log.info(diagsparams) self.workspace.publish_diagnostics(diagsparams['uri'], diagsparams['diagnostics']) def m_text_document__did_save(self, textDocument=None, **_kwargs): import mypy_server mypy_server.mypy_check(self.workspace, self.config)