Example #1
0
    def OnExportLauncher(self, event=None):
        Logger.Debug(__name__, u'Export launcher ...')

        export = GetFileSaveDialog(GetMainWindow(), GT(u'Save Launcher'))

        if ShowDialog(export):
            target = export.GetPath()

            # Create a backup file
            # FIXME: Create backup files in WriteFile function?
            overwrite = False
            if os.path.isfile(target):
                backup = u'{}.backup'.format(target)
                shutil.copy(target, backup)
                overwrite = True

            try:
                self.ExportToFile(target)

                if overwrite:
                    os.remove(backup)

            except UnicodeEncodeError:
                detail1 = GT(
                    u'Unfortunately Debreate does not support unicode yet.')
                detail2 = GT(
                    u'Remove any non-ASCII characters from your project.')

                ShowErrorDialog(GT(u'Save failed'),
                                u'{}\n{}'.format(detail1, detail2),
                                title=GT(u'Unicode Error'))

                os.remove(target)
                # Restore from backup
                shutil.move(backup, target)
Example #2
0
	def OnPreviewControl(self, event=None):
		ctrl_info = self.GetCtrlInfo()

		preview = TextPreview(title=GT(u'Control File Preview'),
				text=ctrl_info, size=(600,400))

		ShowDialog(preview)
Example #3
0
 def OnHelpButton(self, event=None):
     label = self.GetCurrentPage().GetTitle()
     page_help = MarkdownDialog(self, title=GT(u'Help'), readonly=True)
     
     page_help.SetText(GT(u'Help information for page "{}"'.format(label)))
     
     ShowDialog(page_help)
Example #4
0
    def ProjectSaveAs(self):
        wildcards = (
            u'{} (.{})'.format(GT(u'Debreate project files'), PROJECT_ext),
            u'*.{}'.format(PROJECT_ext),
        )

        save_dialog = GetFileSaveDialog(self, GT(u'Save Debreate Project'),
                                        wildcards, PROJECT_ext)

        if ShowDialog(save_dialog):
            project_path = save_dialog.GetPath()
            project_filename = save_dialog.GetFilename()

            Logger.Debug(__name__,
                         GT(u'Project save path: {}').format(project_path))
            Logger.Debug(
                __name__,
                GT(u'Project save filename: {}').format(project_filename))

            saved = self.ProjectSave(project_path)
            if saved == dbrerrno.SUCCESS:
                self.ProjectSetDirty(False)

            return saved

        Logger.Debug(__name__, GT(u'Not saving project'))

        return dbrerrno.ECNCLD
Example #5
0
	def OnHelpButton(self, event=None):
		al_help = MarkdownDialog(self, title=GT(u'Auto-Link Help'))
		description = GT(u'Debreate offers an Auto-Link Executables feature. What this does is finds any executables in the Files section and creates a postinst script that will create soft links to them in the specified path. This is useful if you are installing executables to a directory that is not found in the system PATH but want to access it from the PATH. For example, if you install an executable "bar" to the directory "/usr/share/foo" in order to execute "bar" from a terminal you would have to type /usr/share/foo/bar. Auto-Link can be used to place a link to "bar" somewhere on the system path like "/usr/bin". Then all that needs to be typed is bar to execute the program. Auto-Link also creates a prerm script that will delete the link upon removing the package.')
		instructions = GT(u'How to use Auto-Link: Press the IMPORT button to import any executables from the Files section. Then press the GENERATE button. Post-Install and Pre-Remove scripts will be created that will place symbolic links to your executables in the path displayed above.')

		al_help.SetText(u'{}\n\n{}'.format(description, instructions))

		ShowDialog(al_help)
Example #6
0
    def OnBrowse(self, event=None):
        if event:
            button_id = event.GetEventObject().GetId()

            if button_id == btnid.STAGE:
                stage = GetDirDialog(self, GT(u'Choose Directory'))

                if (ShowDialog(stage)):
                    self.input_stage.SetValue(stage.GetPath())

            elif button_id == btnid.TARGET:
                target = GetFileSaveDialog(self, GT(u'Choose Filename'), (
                    GT(u'Debian packages'),
                    u'*.deb',
                ), u'deb')

                if (ShowDialog(target)):
                    self.input_target.SetValue(target.GetPath())
Example #7
0
	def OnSave(self, event=None):
		# Get data to write to control file
		control = self.GetCtrlInfo()

		save_dialog = GetFileSaveDialog(GetMainWindow(), GT(u'Save Control Information'))
		save_dialog.SetFilename(u'control')

		if ShowDialog(save_dialog):
			# Be sure not to strip trailing newline (dpkg is picky)
			WriteFile(save_dialog.GetPath(), control, noStrip=u'\n')
Example #8
0
 def OnOpenLogFile(self, event=None):
     log_select = GetFileOpenDialog(self, GT(u'Open Log'), directory=PATH_logs)
     
     if ShowDialog(log_select):
         logFile = log_select.GetPath()
         
         if os.path.isfile(logFile):
             self.SetLogFile(logFile)
             
             return
         
         ShowErrorDialog(u'{}: {}'.format(GT(u'File does not exist'), logFile),
                 parent=self)
Example #9
0
    def SetTabName(self, index=-1, rename=False, checkBox=None, checked=False):
        getname = TextEntryDialog(GetMainWindow(), GT(u'Name for new page'))
        new_name = None

        if not rename and checkBox:
            check_box = CheckBox(getname, label=checkBox)
            check_box.SetValue(checked)

            sizer = getname.GetSizer()
            insert_point = len(sizer.GetChildren()) - 1

            sizer.InsertSpacer(insert_point, 5)
            sizer.Insert(insert_point + 1, check_box, 0, wx.LEFT, 16)

            getname.SetSize(sizer.GetMinSize())
            getname.Fit()
            getname.CenterOnParent()

        valid_name = False

        while not valid_name:
            if new_name and TextIsEmpty(new_name):
                getname.Clear()

            # User cancelled
            if not ShowDialog(getname):
                return False

            else:
                new_name = getname.GetValue()

            valid_name = self._title_is_ok(new_name)

            if valid_name:
                break

            ShowErrorDialog(GT(u'Page name cannot contain whitespace'),
                            warn=True)

        if rename:
            if index < 0:
                return False

            return self.Tabs.SetPageText(index, new_name)

        if checkBox:
            return self.AddPage(new_name, checkBox=check_box)

        return self.AddPage(new_name)
Example #10
0
    def OnLoadLauncher(self, event=None):
        dia = GetFileOpenDialog(GetMainWindow(), GT(u'Open Launcher'))

        if ShowDialog(dia):
            path = dia.GetPath()

            data = ReadFile(path, split=True, convert=list)

            # Remove unneeded lines
            if data[0] == u'[Desktop Entry]':
                data = data[1:]

            self.Reset()
            # First line needs to be changed to '1'
            data.insert(0, u'1')
            self.Set(u'\n'.join(data))
Example #11
0
    def OnLoadLauncher(self, event=None):
        dia = wx.FileDialog(GetMainWindow(),
                            GT(u'Open Launcher'),
                            os.getcwd(),
                            style=wx.FD_CHANGE_DIR)

        if ShowDialog(dia):
            path = dia.GetPath()

            data = ReadFile(path, split=True)

            # Remove unneeded lines
            if data[0] == u'[Desktop Entry]':
                data = data[1:]

            self.Reset()
            self.SetLauncherData(u'\n'.join(data))
Example #12
0
    def OnExportLauncher(self, event=None):
        Logger.Debug(__name__, u'Export launcher ...')

        # Get data to write to control file
        menu_data = self.GetLauncherInfo().encode(u'utf-8')

        dia = wx.FileDialog(GetMainWindow(),
                            GT(u'Save Launcher'),
                            os.getcwd(),
                            style=wx.FD_SAVE | wx.FD_CHANGE_DIR
                            | wx.FD_OVERWRITE_PROMPT)

        if ShowDialog(dia):
            path = dia.GetPath()

            # Create a backup file
            overwrite = False
            if os.path.isfile(path):
                backup = u'{}.backup'.format(path)
                shutil.copy(path, backup)
                overwrite = True

            try:
                WriteFile(path, menu_data)

                if overwrite:
                    os.remove(backup)

            except UnicodeEncodeError:
                detail1 = GT(
                    u'Unfortunately Debreate does not support unicode yet.')
                detail2 = GT(
                    u'Remove any non-ASCII characters from your project.')

                ShowErrorDialog(GT(u'Save failed'),
                                u'{}\n{}'.format(detail1, detail2),
                                title=GT(u'Unicode Error'))

                os.remove(path)
                # Restore from backup
                shutil.move(backup, path)
Example #13
0
	def OnBrowse(self, event=None):
		dia = GetDirDialog(GetMainWindow(), GT(u'Choose Target Directory'))
		if ShowDialog(dia):
			self.ti_target.SetValue(dia.GetPath())
Example #14
0
    def OnBuild(self, event=None):
        if event:
            event.Skip()

        # Show control file preview for editing
        if UsingTest(u'alpha') and self.chk_editctrl.GetValue():
            self.EditControl()

        wizard = GetWizard()

        pg_control = wizard.GetPage(pgid.CONTROL)
        pg_files = wizard.GetPage(pgid.FILES)
        pg_launcher = wizard.GetPage(pgid.LAUNCHERS)

        required_fields = {
            GT(u'Control'): pg_control.GetRequiredFields(),
        }

        # Check if launchers are enabled for build
        if pg_launcher.GetLaunchersCount():
            required_fields[GT(
                u'Menu Launcher')] = pg_launcher.GetRequiredFields()

            # FIXME: Old code won't work with multiple launchers
            for RF in required_fields[GT(u'Menu Launcher')]:
                Logger.Debug(
                    __name__,
                    GT(u'Required field (Menu Launcher): {}').format(
                        RF.GetName()))

        for p_name in required_fields:
            Logger.Debug(__name__, GT(u'Page name: {}').format(p_name))
            for F in required_fields[p_name]:
                if not isinstance(F, wx.StaticText) and TextIsEmpty(
                        F.GetValue()):
                    f_name = F.GetName()

                    msg_l1 = GT(u'One of the required fields is empty:')
                    msg_full = u'{}: {} ➜ {}'.format(msg_l1, p_name, f_name)

                    Logger.Warn(__name__, msg_full)

                    DetailedMessageDialog(GetMainWindow(),
                                          GT(u'Cannot Continue'),
                                          ICON_EXCLAMATION,
                                          text=msg_full).ShowModal()

                    for P in wizard.GetAllPages():
                        if P.GetTitle() == p_name:
                            Logger.Debug(
                                __name__,
                                GT(u'Showing page with required field: {}').
                                format(p_name))
                            wizard.ShowPage(P.GetId())

                    return

        if GetField(pg_files, inputid.LIST).MissingFiles():
            ShowErrorDialog(GT(u'Files are missing in file list'),
                            warn=True,
                            title=GT(u'Warning'))

            wizard.ShowPage(pgid.FILES)

            return

        ttype = GT(u'Debian Packages')
        save_dialog = GetFileSaveDialog(GetMainWindow(), GT(u'Build Package'),
                                        u'{} (*.deb)|*.deb'.format(ttype),
                                        u'deb')

        package = GetFieldValue(pg_control, inputid.PACKAGE)
        version = GetFieldValue(pg_control, inputid.VERSION)
        arch = GetFieldValue(pg_control, inputid.ARCH)
        save_dialog.SetFilename(u'{}_{}_{}.deb'.format(package, version, arch))

        if ShowDialog(save_dialog):
            self.Build(save_dialog.GetPath())
Example #15
0
 def OnBrowse(self, event=None):
     browse_dialog = GetFileOpenDialog(GetMainWindow(), GT(u'Open File'))
     if ShowDialog(browse_dialog):
         self.ImportFromFile(browse_dialog.GetPath())
Example #16
0
    def ProjectOpen(self, project_file=None):
        Logger.Debug(__name__, u'Opening project: {}'.format(project_file))

        # Need to show file open dialog because no project file was specified
        if not project_file:
            wc_z = GetDialogWildcards(ID_PROJ_Z)
            wc_l = GetDialogWildcards(ID_PROJ_L)
            wc_a = GetDialogWildcards(ID_PROJ_A)
            wc_t = GetDialogWildcards(ID_PROJ_T)

            wildcards = (
                wc_a[0],
                wc_a[1],
                wc_z[0],
                wc_z[1],
                wc_t[0],
                wc_t[1],
                wc_l[0],
                wc_l[1],
            )

            open_dialog = GetFileOpenDialog(self, GT(u'Open Debreate Project'),
                                            wildcards)
            if not ShowDialog(open_dialog):
                return dbrerrno.ECNCLD

            # Get the path and set the saved project
            project_file = open_dialog.GetPath()

        # Failsafe check that file exists
        if not os.path.isfile(project_file):
            err_l1 = GT(u'Cannot open project:')
            err_details = GT(u'File does not exist')

            ShowErrorDialog(u'{} {}'.format(err_l1, project_file), err_details)

            return dbrerrno.ENOENT

        # Check for unsaved changes & reset project to defaults
        if not self.ProjectClose():
            return dbrerrno.ECNCLD

        mime_type = GetFileMimeType(project_file)

        Logger.Debug(__name__, GT(u'Project mime type: {}').format(mime_type))

        opened = None
        if mime_type == u'text/plain':
            p_text = ReadFile(project_file)

            filename = os.path.split(project_file)[1]

            # Legacy projects should return None since we can't save in that format
            opened = self.ProjectOpenLegacy(p_text, filename)

        else:
            opened = self.ProjectOpenArchive(project_file, mime_type)

        Logger.Debug(
            __name__,
            GT(u'Project loaded before OnProjectOpen: {}').format(
                self.ProjectIsLoaded()))

        if opened == dbrerrno.SUCCESS:
            self.LoadedProject = project_file

            # Set project 'unmodified' for newly opened project
            self.ProjectSetDirty(False)

        Logger.Debug(
            __name__,
            GT(u'Project loaded after OnOpenPreject: {}').format(
                self.ProjectIsLoaded()))

        if DebugEnabled() and self.ProjectIsLoaded():
            Logger.Debug(__name__,
                         GT(u'Loaded project: {}').format(self.LoadedProject))

        return opened
Example #17
0
    def OnPreviewLauncher(self, event=None):
        preview = TextPreview(title=GT(u'Menu Launcher Preview'),
                              text=self.Get(),
                              size=(500, 400))

        ShowDialog(preview)