def SetLicense(self): ## Defines where the LICENSE.txt is located # # By default it is located in the folder 'doc' # under the applications root directory. The # install script or Makefile should change this # to reflect installed path. if INSTALLED: license_path = u'{}/share/doc/debreate/copyright'.format(PREFIX) else: license_path = u'{}/docs/LICENSE.txt'.format(PREFIX) if os.path.isfile(license_path): lic_text = ReadFile(license_path) else: lic_text = GT( u'ERROR: Could not locate license file:\n\t\'{}\' not found'. format(license_path)) lic_text += u'\n\nCopyright © {} {} <{}>'.format( GetYear(), AUTHOR_name, AUTHOR_email) lic_text += u'\n\nhttps://opensource.org/licenses/MIT' self.license.SetValue(lic_text) self.license.SetInsertionPoint(0)
def OnTemplateShort(self, event=None): if self.DestroyLicenseText(): self.dsp_copyright.Clear() license_path = u'{}/{}'.format(sys_licenses_path, self.sel_templates.GetString(self.sel_templates.GetSelection())) self.dsp_copyright.WriteText(u'{}\n\n{}'.format(copyright_header.format(GetYear()), license_path)) self.dsp_copyright.SetInsertionPoint(0) self.dsp_copyright.SetFocus()
def __init__(self, parent): ManSectBase.__init__(self, parent) self.Panel = BorderedPanel(parent) txt_section = wx.StaticText(self.Panel, label=GT(u'Section')) self.sel_section = Choice(self.Panel, choices=tuple(sections)) self.sel_section.Default = u'1' self.sel_section.SetStringSelection(self.sel_section.Default) # Section description that changes with EVT_CHOICE self.LabelSection = wx.StaticText(self.Panel) self.SetSectionLabel() txt_date = wx.StaticText(self.Panel, label=GT(u'Date')) spin_year = wx.SpinCtrl(self.Panel, min=1900, max=2100, initial=GetYear(string_value=False)) spin_month = wx.SpinCtrl(self.Panel, min=1, max=12, initial=GetMonthInt()) spin_day = wx.SpinCtrl(self.Panel, min=1, max=31, initial=GetDayInt()) # FIXME: What is this for? txt_unknown1 = wx.StaticText(self.Panel, label=GT(u'Unknown')) ti_unknown1 = wx.TextCtrl(self.Panel) # FIXME: What is this for? txt_unknown2 = wx.StaticText(self.Panel, label=GT(u'Unknown')) ti_unknown2 = wx.TextCtrl(self.Panel) # *** Event Handling *** # self.sel_section.Bind(wx.EVT_CHOICE, self.OnSetSection) # *** Layout *** # lyt_section = BoxSizer(wx.HORIZONTAL) lyt_section.Add(txt_section, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER, 5) lyt_section.Add(self.sel_section, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER, 5) lyt_section.Add(self.LabelSection, 0, wx.LEFT | wx.RIGHT | wx.ALIGN_CENTER, 5) lyt_date = wx.GridBagSizer() lyt_date.Add(txt_date, (1, 0), flag=wx.ALIGN_CENTER_VERTICAL) lyt_date.Add(wx.StaticText(self.Panel, label=GT(u'Year')), (0, 1)) lyt_date.Add(wx.StaticText(self.Panel, label=GT(u'Month')), (0, 2)) lyt_date.Add(wx.StaticText(self.Panel, label=GT(u'Day')), (0, 3)) lyt_date.Add(spin_year, (1, 1), flag=wx.LEFT, border=5) lyt_date.Add(spin_month, (1, 2)) lyt_date.Add(spin_day, (1, 3)) lyt_uknwn1 = BoxSizer(wx.HORIZONTAL) lyt_uknwn1.Add(txt_unknown1, 0, wx.ALIGN_CENTER_VERTICAL) lyt_uknwn1.Add(ti_unknown1, 0, wx.LEFT, 5) lyt_uknwn2 = BoxSizer(wx.HORIZONTAL) lyt_uknwn2.Add(txt_unknown2, 0, wx.ALIGN_CENTER_VERTICAL) lyt_uknwn2.Add(ti_unknown2, 0, wx.LEFT, 5) # Change orientation of main sizer to vertical self.lyt_main = BoxSizer(wx.VERTICAL) self.lyt_main.Add(lyt_section, 0, wx.TOP, 5) self.lyt_main.Add(lyt_date, 0, wx.TOP, 5) self.lyt_main.Add(lyt_uknwn1, 0, wx.TOP, 5) self.lyt_main.Add(lyt_uknwn2, 0, wx.TOP, 5) self.Panel.SetSizer(self.lyt_main)
def OnTemplateFull(self, event=None): selected_template = self.sel_templates.GetStringSelection() template_file = self.GetLicensePath(selected_template) if self.DestroyLicenseText(): if not template_file or not os.path.isfile(template_file): ShowErrorDialog(GT(u'Could not locate license file: {}').format(self.GetSelectedName())) return Logger.Debug(__name__, u'Copying license {}'.format(template_file)) license_text = ReadFile(template_file, noStrip=u' ') # Number defines how many empty lines to add after the copyright header # Boolean/Integer defines whether copyright header should be centered/offset add_header = { u'Artistic': (1, True), u'BSD': (0, False), } template_name = os.path.basename(template_file) if template_name in add_header: license_text = license_text.split(u'\n') empty_lines = add_header[template_name][0] for L in range(empty_lines): license_text.insert(0, wx.EmptyString) header = copyright_header.format(GetYear()) center_header = add_header[template_name][1] if center_header: Logger.Debug(__name__, u'Centering header...') offset = 0 # Don't use isinstance() here because boolean is an instance of integer if type(center_header) == int: offset = center_header else: # Use the longest line found in the text to center the header longest_line = GetLongestLine(license_text) Logger.Debug(__name__, u'Longest line: {}'.format(longest_line)) header_length = len(header) if header_length < longest_line: offset = (longest_line - header_length) / 2 if offset: Logger.Debug(__name__, u'Offset: {}'.format(offset)) header = u'{}{}'.format(u' ' * offset, header) # Special changes for BSD license if template_name == u'BSD': line_index = 0 for LI in license_text: if u'copyright (c)' in LI.lower(): license_text[line_index] = header break line_index += 1 else: license_text.insert(0, header) license_text = u'\n'.join(license_text) if not license_text: ShowErrorDialog(GT(u'License template is empty')) return self.dsp_copyright.SetValue(license_text) self.dsp_copyright.SetInsertionPoint(0) self.dsp_copyright.SetFocus()