Exemplo n.º 1
0
 def load_wdhistory(self, workdir=None):
     """Load history from a text file in user home directory"""
     if osp.isfile(self.LOG_PATH):
         wdhistory, _ = encoding.readlines(self.LOG_PATH)
         wdhistory = [name for name in wdhistory if os.path.isdir(name)]
     else:
         if workdir is None:
             workdir = get_home_dir()
         wdhistory = [workdir]
     return wdhistory
Exemplo n.º 2
0
 def _filename_global(self):
     """Create a .ini filename located in user home directory.
     This .ini files stores the global trex preferences.
     """
     if self.subfolder is None:
         config_file = osp.join(get_home_dir(), '.%s.ini' % self.name)
         return config_file
     else:
         folder = get_conf_path()
         # Save defaults in a "defaults" dir of .trex2 to not pollute it
         if 'defaults' in self.name:
             folder = osp.join(folder, 'defaults')
             if not osp.isdir(folder):
                 os.mkdir(folder)
         config_file = osp.join(folder, '%s.ini' % self.name)
         return config_file
Exemplo n.º 3
0
 def setup_menu_actions(self):
     """Setup and update the menu actions."""
     self.recent_project_menu.clear()
     self.recent_projects_actions = []
     if self.recent_projects:
         for project in self.recent_projects:
             if self.is_valid_project(project):
                 name = project.replace(get_home_dir(), '~')
                 action = create_action(self,
                                        name,
                                        icon=ima.icon('project'),
                                        triggered=lambda v, path=project:
                                        self.open_project(path=path))
                 self.recent_projects_actions.append(action)
             else:
                 self.recent_projects.remove(project)
         self.recent_projects_actions += [
             None, self.clear_recent_projects_action
         ]
     else:
         self.recent_projects_actions = [self.clear_recent_projects_action]
     add_actions(self.recent_project_menu, self.recent_projects_actions)
     self.update_project_actions()
Exemplo n.º 4
0
    def open_project(self,
                     path=None,
                     restart_consoles=True,
                     save_previous_files=True):
        """Open the project located in `path`"""
        if path is None:
            basedir = get_home_dir()
            path = getexistingdirectory(parent=self,
                                        caption=_("Open project"),
                                        basedir=basedir)
            if not self.is_valid_project(path):
                if path:
                    QMessageBox.critical(
                        self, _('Error'),
                        _("<b>%s</b> is not a TRex project!") % path)
                return
            else:
                self.add_to_recent(path)

        # A project was not open before
        if self.current_active_project is None:
            if save_previous_files:
                self.editor.save_open_files()
            self.editor.set_option('last_working_dir', getcwd())
            self.show_explorer()
        else:  # we are switching projects
            self.set_project_filenames(self.editor.get_open_filenames())

        self.current_active_project = EmptyProject(path)
        self.latest_project = EmptyProject(path)
        self.set_option('current_project_path', self.get_active_project_path())
        self.setup_menu_actions()
        self.sig_project_loaded.emit(path)
        self.pythonpath_changed.emit()
        if restart_consoles:
            self.restart_consoles()
Exemplo n.º 5
0
# 1. If you want to *change* the default value of a current option, you need to
#    do a MINOR update in config version, e.g. from 3.0.0 to 3.1.0
# 2. If you want to *remove* options that are no longer needed in our codebase,
#    or if you want to *rename* options, then you need to do a MAJOR update in
#    version, e.g. from 3.0.0 to 4.0.0
# 3. You don't need to touch this value if you're just adding a new option
CONF_VERSION = '32.0.0'

# Main configuration instance
try:
    CONF = UserConfig('trex',
                      defaults=DEFAULTS,
                      load=(not TEST),
                      version=CONF_VERSION,
                      subfolder=SUBFOLDER,
                      backup=True,
                      raw_mode=True)
except:
    CONF = UserConfig('trex',
                      defaults=DEFAULTS,
                      load=False,
                      version=CONF_VERSION,
                      subfolder=SUBFOLDER,
                      backup=True,
                      raw_mode=True)

# Removing old .trex.ini location:
old_location = osp.join(get_home_dir(), '.trex.ini')
if osp.isfile(old_location):
    os.remove(old_location)
Exemplo n.º 6
0
    def __init__(self, parent):
        """Project creation dialog."""
        super(ProjectDialog, self).__init__(parent=parent)

        # Variables
        current_python_version = '.'.join([
            to_text_string(sys.version_info[0]),
            to_text_string(sys.version_info[1])
        ])
        python_versions = ['2.7', '3.4', '3.5']
        if current_python_version not in python_versions:
            python_versions.append(current_python_version)
            python_versions = sorted(python_versions)

        self.project_name = None
        self.location = get_home_dir()

        # Widgets
        self.groupbox = QGroupBox()
        self.radio_new_dir = QRadioButton(_("New directory"))
        self.radio_from_dir = QRadioButton(_("Existing directory"))

        self.label_project_name = QLabel(_('Project name'))
        self.label_location = QLabel(_('Location'))
        self.label_project_type = QLabel(_('Project type'))
        self.label_python_version = QLabel(_('Python version'))

        self.text_project_name = QLineEdit()
        self.text_location = QLineEdit(get_home_dir())
        self.combo_project_type = QComboBox()
        self.combo_python_version = QComboBox()

        self.button_select_location = QToolButton()
        self.button_cancel = QPushButton(_('Cancel'))
        self.button_create = QPushButton(_('Create'))

        self.bbox = QDialogButtonBox(Qt.Horizontal)
        self.bbox.addButton(self.button_cancel, QDialogButtonBox.ActionRole)
        self.bbox.addButton(self.button_create, QDialogButtonBox.ActionRole)

        # Widget setup
        self.combo_python_version.addItems(python_versions)
        self.radio_new_dir.setChecked(True)
        self.text_location.setEnabled(True)
        self.text_location.setReadOnly(True)
        self.button_select_location.setIcon(get_std_icon('DirOpenIcon'))
        self.button_cancel.setDefault(True)
        self.button_cancel.setAutoDefault(True)
        self.button_create.setEnabled(False)
        self.combo_project_type.addItems(self._get_project_types())
        self.combo_python_version.setCurrentIndex(
            python_versions.index(current_python_version))
        self.setWindowTitle(_('Create new project'))
        self.setFixedWidth(500)
        self.label_python_version.setVisible(False)
        self.combo_python_version.setVisible(False)

        # Layouts
        layout_top = QHBoxLayout()
        layout_top.addWidget(self.radio_new_dir)
        layout_top.addWidget(self.radio_from_dir)
        layout_top.addStretch(1)
        self.groupbox.setLayout(layout_top)

        layout_grid = QGridLayout()
        layout_grid.addWidget(self.label_project_name, 0, 0)
        layout_grid.addWidget(self.text_project_name, 0, 1, 1, 2)
        layout_grid.addWidget(self.label_location, 1, 0)
        layout_grid.addWidget(self.text_location, 1, 1)
        layout_grid.addWidget(self.button_select_location, 1, 2)
        layout_grid.addWidget(self.label_project_type, 2, 0)
        layout_grid.addWidget(self.combo_project_type, 2, 1, 1, 2)
        layout_grid.addWidget(self.label_python_version, 3, 0)
        layout_grid.addWidget(self.combo_python_version, 3, 1, 1, 2)

        layout = QVBoxLayout()
        layout.addWidget(self.groupbox)
        layout.addSpacing(10)
        layout.addLayout(layout_grid)
        layout.addStretch()
        layout.addSpacing(20)
        layout.addWidget(self.bbox)

        self.setLayout(layout)

        # Signals and slots
        self.button_select_location.clicked.connect(self.select_location)
        self.button_create.clicked.connect(self.create_project)
        self.button_cancel.clicked.connect(self.close)
        self.radio_from_dir.clicked.connect(self.update_location)
        self.radio_new_dir.clicked.connect(self.update_location)
        self.text_project_name.textChanged.connect(self.update_location)