def add_license(self, v=None, path=None): """Add license file.""" if path is None: filename, selected_filter = getopenfilename( self, 'Select license file', filters='License files (*.txt)', basedir=get_home_dir(), ) if filename: paths = [filename] else: paths = [] else: paths = [path] valid_licenses, invalid_licenses = self.api.add_license(paths) for path in invalid_licenses: text = ('File: <b>"{0}"</b>' '<br>is not a valid license file.').format(path) self.message_box = MessageBoxInformation( text=text, title="Invalid license file") self.message_box.exec_() if valid_licenses: self.load_licenses()
def test(): from anaconda_navigator.utils.qthelpers import qapplication from anaconda_navigator.config import get_home_dir app = qapplication() w1 = EditableLineEdit('Project name', 'my-project', regex='[A-Za-z0-9_\- ]{1,20}') w1.show() w2 = EditablePathEdit('Icon', '', basedir=get_home_dir(), fileselect=True, caption='Select icon file', filters="Image files (*.png *.jpg)") w2.show() w3 = MessageCheckBox.warning( None, 'Delete project', 'Do you really want to delete project {0}?'.format(''), checkbox_text='Delete project files', buttons=MessageCheckBox.Yes | MessageCheckBox.No, ) reply = w3.exec_() print(reply, w3.is_checked()) app.exec_()
def duplicate_project(self, path=None): """ Copy selected project directory into `path`. """ source_path = self.list_projects.currentItem().path if path is None: path = getexistingdirectory(caption="Select folder destination " "for project duplication", basedir=get_home_dir()) if path: shutil.copy2(source_path, path)
def add_project(self, path=None, new_path=None): """ Add/import existing project given by `path` into `new_path`. """ if path is None: path = getexistingdirectory(caption="Select origin project folder " "to import", basedir=get_home_dir()) if path: self.update_status('Adding project at {0}'.format(path)) self.update_visibility(disabled=True) update_pointer(Qt.BusyCursor) # shutil.copytree does not work if the destionation folder exists # os.removedirs(new_path) # shutil.copytree(path, new_path) worker = self.api.add_project(path) worker.path = path worker.sig_finished.connect(self._project_added)
def create_new_project(self, path=None): """ Create a new project. If `path` is provided no dialog is openned. """ if path is None: path = getexistingdirectory(caption='Select new project folder ' 'location', basedir=get_home_dir()) # Check that project.yaml does not exists, otherwise warn the user and # prompt for action? if path: name = self.new_project_name_template.format(self.project_counter) self.update_status('Creating project "{0}"'.format(name)) worker = self.api.create_new_project(path=path, name=name) worker.sig_finished.connect(self._project_created) worker.path = path self.update_visibility(disabled=True) self.project_counter += 1 update_pointer(Qt.BusyCursor)
def __init__(self, parent=None): super(ProjectWidget, self).__init__(parent) # Variables self.api = AnacondaAPI() self._parent = parent self.path = None self.project = None self.timer = QTimer() self.timeout = 6000 # Widgets self.text_name = EditableLineEdit('Name', '') self.text_location = EditablePathEdit('Location', '', caption="Select new project " "directory", basedir=get_home_dir()) self.text_icon = EditablePathEdit( 'Icon', '', fileselect=True, caption='Select icon image file', filters="Image files (*.png *.jpg *.jpeg)", basedir=get_home_dir()) self.button_launch = QPushButton('Launch') self.button_upload = QPushButton('Upload to Anaconda Cloud') self.tabs = QTabWidget(parent=self) self.tab_packages = PackagesTab() # self.tab_advanced = AdvancedTab() self.tab_explorer = ExplorerTab() # Widget Setup self.setWindowTitle('Project Editor') self.button_upload.setObjectName('ButtonUpdate') self.button_launch.setObjectName('ButtonUpdate') self.tabs.addTab(self.tab_explorer, 'Files') self.tabs.addTab(self.tab_packages, 'Packages') # self.tabs.addTab(self.tab_advanced, 'Advanced options') self.text_icon._text.setVisible(False) # Layouts project_buttons = QHBoxLayout() project_buttons.addWidget(self.button_upload) # project_buttons.addWidget(self.button_launch) project_buttons.addStretch() information_layout = QHBoxLayout() information_layout.addWidget(self.text_name, 2) information_layout.addWidget(self.text_location, 4) information_layout.addWidget(self.text_icon, 1) main_layout = QVBoxLayout() # main_layout.addLayout(project_buttons, 1) # main_layout.addSpacing(6) main_layout.addLayout(information_layout, 1) main_layout.addWidget(self.tabs, 10) main_layout.addWidget(self.button_launch, 0, Qt.AlignRight) self.setLayout(main_layout) # Signals self.button_launch.clicked.connect(self.launch) self.tab_explorer.explorer.sig_home_clicked.connect( self.set_explorer_path) self.tab_explorer.treewidget.sig_edit.connect(self.edit_file) self.tab_explorer.treewidget.sig_open_py.connect(self.run_python_file) self.tab_explorer.treewidget.sig_open_py_con.connect( self.run_python_console) self.tab_explorer.treewidget.sig_open_notebook.connect( self.run_notebook) self.tab_explorer.treewidget.sig_add_endpoint.connect( self.make_command_from_file) self.tab_packages.sig_project_commands_updated.connect( self.sig_project_commands_updated) self.tab_packages.sig_apps_updated.connect(self.sig_apps_updated) self.timer.timeout.connect(self._launched) self.text_location.sig_text_changed.connect(self.update_location) self.text_name.sig_text_changed.connect(self.update_name) self.text_icon.sig_text_changed.connect(self.update_icon) # Setup self.button_upload.setDisabled(True) self.button_upload.setVisible(False)