def add_aspect_onweb(self, url, pageurl, linktext='', defaultauthor='', category_phrase='', author_is_corporate=False, tags=None, inferred_filetype=None, threaded=False): '''Add information gleaned from the document being on the web (in-situ)''' assert type(url) in (str, unicode) assert type(pageurl) in (str, unicode) assert type(linktext) in (str, unicode) self.WebData_Url = url self.WebData_PageUrl = pageurl self.WebData_LinkText = linktext if author_is_corporate: self.corpauthor = defaultauthor else: self.author = defaultauthor self.collection = category_phrase # Set basic bibliographic data if not self.BibData_Type: self.BibData_HowPublished = PIE_CONFIG.get( 'Format', 'default_howpublished_text') self.BibData_Type = PIE_CONFIG.get( 'Format', 'default_bibtex_entry_type') if tags: self.add_tags(tags, threaded) if inferred_filetype: self.set_file_type(inferred_filetype) self.aspects['onweb']=True self.aspects['bibdata']=True
def OnSetPassword(self, evt): existpwd = PIE_CONFIG.get('Security', 'file_key_unhashed') if existpwd: dia0 = wx.MessageDialog(self, _('There already appears to be a password set.\nChanging it now will mean that any files you have already\nencrypted will become UNREADABLE.\nChanging your password should NOT be necessary, but you can\nproceed if you wish.'), _('Warning'), style=wx.OK|wx.CANCEL) ans = dia0.ShowModal() if ans == wx.ID_CANCEL: return dia0a = wx.PasswordEntryDialog(self, _('Enter existing password')) ans = dia0a.ShowModal() if ans == wx.ID_CANCEL: return pwd0 = dia0a.GetValue() dia0a.Destroy() if pwd0 != existpwd: wx.MessageBox(_('That is not your current password'), _('Error')) return dia1 = wx.PasswordEntryDialog(self, _('Enter password')) ans = dia1.ShowModal() if ans == wx.ID_CANCEL: return pwd1 = dia1.GetValue() dia1.Destroy() dia2 = wx.PasswordEntryDialog(self, _('Confirm password')) ans = dia2.ShowModal() if ans == wx.ID_CANCEL: return pwd2 = dia2.GetValue() dia2.Destroy() if pwd1 != pwd2: wx.MessageBox(_('The passwords did not match.'), _('Error')) return if len(pwd1) < 4: wx.MessageBox(_('This password seems a bit short. Try another')) return PIE_CONFIG.set('Security', 'file_key', pwd1) assert PIE_CONFIG.get('Security', 'file_key') != None PIE_INTERNALS.set_encryption_hash(PIE_CONFIG.get('Security', 'file_key'))
def add_aspect_onweb(self, url, pageurl, linktext='', defaultauthor='', category_phrase='', author_is_corporate=False, tags=None, inferred_filetype=None, threaded=False): '''Add information gleaned from the document being on the web (in-situ)''' assert type(url) in (str, unicode) assert type(pageurl) in (str, unicode) assert type(linktext) in (str, unicode) self.WebData_Url = url self.WebData_PageUrl = pageurl self.WebData_LinkText = linktext if author_is_corporate: self.corpauthor = defaultauthor else: self.author = defaultauthor self.collection = category_phrase # Set basic bibliographic data if not self.BibData_Type: self.BibData_HowPublished = PIE_CONFIG.get( 'Format', 'default_howpublished_text') self.BibData_Type = PIE_CONFIG.get('Format', 'default_bibtex_entry_type') if tags: self.add_tags(tags, threaded) if inferred_filetype: self.set_file_type(inferred_filetype) self.aspects['onweb'] = True self.aspects['bibdata'] = True
def trim_filename(path): assert type(path) in (str, unicode) if len(path) > PIE_CONFIG.getint('Format', 'filesystem_length_limit') - 5: dirn = os.path.dirname(path) basen, ext = os.path.splitext(os.path.basename(path)) basen = basen[:PIE_CONFIG.getint('Format', 'filesystem_length_limit') - len(ext) - len(dirn) - 5] # -5 to account for addition chars from auto_increment_fn return os.path.join(dirn, basen.strip() + ext) else: return path
def trim_filename(path): assert type(path) in (str, unicode) if len(path) > PIE_CONFIG.getint('Format', 'filesystem_length_limit') - 5: dirn = os.path.dirname(path) basen, ext = os.path.splitext(os.path.basename(path)) basen = basen[:PIE_CONFIG.getint( 'Format', 'filesystem_length_limit') - len(ext) - len( dirn ) - 5] # -5 to account for addition chars from auto_increment_fn return os.path.join(dirn, basen.strip() + ext) else: return path
def GetData(self): retdata = ('Profile', {'bibliography_file': self.bibfilectrl.GetPath(), 'desktopdir': self.desktopdirctrl.GetPath(), 'rootdir': self.rootdirctrl.GetPath(), 'export_bibtex': self.bib_cb.GetValue(), 'export_starred_only': self.bibexpstarred_cb.GetValue(), 'last_dir_saved_to': PIE_CONFIG.get('Profile', 'last_dir_saved_to'), 'last_dir_opened': PIE_CONFIG.get('Profile', 'last_dir_opened') }) return retdata
def OnAddProfile(self, evt): tedia = wx.TextEntryDialog( self, _('Name of new settings profile'), _('New profile'), defaultValue='') tedo = tedia.ShowModal() if tedo == wx.ID_CANCEL: return profile_name = tedia.GetValue() if len(profile_name) < 1 or len(profile_name) > 30: return retdata = self.GetData() PIE_CONFIG.add_profile(profile_name, retdata[1]) # PIE_CONFIG.set('TheProfile', 'current_profile', self.GetProfile()) self._refill_profile_choice() self.profileChoice.SetStringSelection(profile_name)
def suggest_path_store_with_bibdata(obj): assert obj.has_aspect('cached') assert obj.has_aspect('bibdata') root = LIBRARYDIR auth = obj.Author(favour_corporate=False) if obj.BibData_Journal: subd = obj.BibData_Journal # elif obj. # obj. else: subd = u'' print 'suggest_path_store_with_bibdata: ____' ext = os.path.splitext(obj.FileData_FullPath)[1] # try to fix odd file extensions (phtml, php etc) if not ext in FEXTENSIONS[obj.FileData_FileType]: if len(FEXTENSIONS[obj.FileData_FileType]) == 1: # only guess if there's only one possible extension ext = FEXTENSIONS[obj.FileData_FileType][0] fn_prop = "%s - %s%s" % ( obj.ReferDate().strftime("%Y%m%d"), translate_non_alphanumerics(obj.Title()), ext) proposal = os.path.join( root, auth.strip(), subd.strip(), fn_prop[:PIE_CONFIG.getint('Format', 'filesystem_length_limit')].strip() ) proposal = trim_filename(proposal) proposal = auto_increment_fn(proposal) print 'SUGGESTING:', proposal if os.path.exists(proposal): raise IOError, 'File already exists. TODO - auto-fix' return proposal, ('librarydir', [i for i in (auth, subd) if i], os.path.basename(proposal))
def clean_backups(): if len(os.listdir(BACKUPDIR)) < 2: return # always have at least one backup if len(os.listdir(BACKUPDIR)) > 25: # more than 25 backups is a bit silly files = [os.path.join(BACKUPDIR, i) for i in os.listdir(BACKUPDIR)] files.sort() for f in files[:len(files) - 25]: try: os.remove(f) print 'deleting old backup %s' % f except: continue for fn in os.listdir(BACKUPDIR): fn = os.path.join(BACKUPDIR, fn) if os.path.isfile(fn): # print fn.split('.') try: fdate = datetime.datetime.strptime( fn.split('.')[-1], '%Y%m%d-%H%M') deldays = datetime.timedelta(days=PIE_CONFIG.getint( 'Internal', 'delete_backups_after_days')) today = datetime.datetime.today() if today - fdate > deldays: os.remove(fn) print 'deleting old backup %s' % fn else: print 'Leave %s' % fn except: traceback.print_exc() continue
def clean_backups(): if len(os.listdir(BACKUPDIR)) < 2: return # always have at least one backup if len(os.listdir(BACKUPDIR)) > 25: # more than 25 backups is a bit silly files = [os.path.join(BACKUPDIR, i) for i in os.listdir(BACKUPDIR)] files.sort() for f in files[:len(files)-25]: try: os.remove(f) print 'deleting old backup %s' % f except: continue for fn in os.listdir(BACKUPDIR): fn = os.path.join(BACKUPDIR, fn) if os.path.isfile(fn): # print fn.split('.') try: fdate = datetime.datetime.strptime( fn.split('.')[-1], '%Y%m%d-%H%M') deldays = datetime.timedelta(days=PIE_CONFIG.getint( 'Internal', 'delete_backups_after_days')) today = datetime.datetime.today() if today - fdate > deldays: os.remove(fn) print 'deleting old backup %s' % fn else: print 'Leave %s' % fn except: traceback.print_exc() continue
def OnAddProfile(self, evt): tedia = wx.TextEntryDialog(self, _('Name of new settings profile'), _('New profile'), defaultValue='') tedo = tedia.ShowModal() if tedo == wx.ID_CANCEL: return profile_name = tedia.GetValue() if len(profile_name) < 1 or len(profile_name) > 30: return retdata = self.GetData() PIE_CONFIG.add_profile(profile_name, retdata[1]) # PIE_CONFIG.set('TheProfile', 'current_profile', self.GetProfile()) self._refill_profile_choice() self.profileChoice.SetStringSelection(profile_name)
def suggest_path_store_with_bibdata(obj): assert obj.has_aspect('cached') assert obj.has_aspect('bibdata') root = LIBRARYDIR auth = obj.Author(favour_corporate=False) if obj.BibData_Journal: subd = obj.BibData_Journal # elif obj. # obj. else: subd = u'' print 'suggest_path_store_with_bibdata: ____' ext = os.path.splitext(obj.FileData_FullPath)[1] # try to fix odd file extensions (phtml, php etc) if not ext in FEXTENSIONS[obj.FileData_FileType]: if len(FEXTENSIONS[obj.FileData_FileType]) == 1: # only guess if there's only one possible extension ext = FEXTENSIONS[obj.FileData_FileType][0] fn_prop = "%s - %s%s" % (obj.ReferDate().strftime("%Y%m%d"), translate_non_alphanumerics(obj.Title()), ext) proposal = os.path.join( root, auth.strip(), subd.strip(), fn_prop[:PIE_CONFIG.getint('Format', 'filesystem_length_limit')].strip( )) proposal = trim_filename(proposal) proposal = auto_increment_fn(proposal) print 'SUGGESTING:', proposal if os.path.exists(proposal): raise IOError, 'File already exists. TODO - auto-fix' return proposal, ('librarydir', [i for i in (auth, subd) if i], os.path.basename(proposal))
def _init_webcam(self): self.proc.parse_config('enable') device = PIE_CONFIG.get('Internal', 'webcam_device') self.proc.init(device) self.proc.visible = True self.proc.set_data_handler(self.HandleData) print 'web cam init done' return True
def onOk(self, evt=1): # commit changes to folders self.cleanerpanel.Finalise() commit_folders() # compile PIE_CONFIG settings profiledata = self.profilepanel.GetData() theprofile = self.profilepanel.GetProfile() alldata = [] alldata.append(profiledata) alldata.append(('TheProfile', {'current_profile': theprofile})) alldata.append(self.formatpanel.GetData()) for sectionkey, dataset in alldata: for key, val in dataset.items(): PIE_CONFIG.set(sectionkey, key, str(val)) PIE_CONFIG.update_profile(theprofile, profiledata[1]) PIE_CONFIG.write_pieconfig() if PIE_CONFIG.get('Profile', 'rootdir') != self.profilepanel.rootdiratstart: # tell the system if the root directory has changed newevt = PieLocationChangedEvent() wx.PostEvent(self, newevt) # tell the system that the folder choices should be updated aevt = PieUpdateAtomChoicesEvent( dests=[f.EndName for f in FOLDER_LOOKUP['projectdir']]) wx.PostEvent(self, aevt) self.EndModal(wx.ID_OK)
def GetData(self): retdata = ('Profile', { 'bibliography_file': self.bibfilectrl.GetPath(), 'desktopdir': self.desktopdirctrl.GetPath(), 'rootdir': self.rootdirctrl.GetPath(), 'export_bibtex': self.bib_cb.GetValue(), 'export_starred_only': self.bibexpstarred_cb.GetValue(), 'last_dir_saved_to': PIE_CONFIG.get('Profile', 'last_dir_saved_to'), 'last_dir_opened': PIE_CONFIG.get('Profile', 'last_dir_opened') }) return retdata
def OnChangeProfile(self, evt=0): nprofile = PIE_CONFIG.get_profile(evt.GetString()) self.rootdirctrl.SetPath(nprofile['rootdir']) self.desktopdirctrl.SetPath(nprofile['desktopdir']) self.bib_cb.SetValue(nprofile['export_bibtex']) self.bibexpstarred_cb.SetValue(nprofile['export_starred_only']) if nprofile['export_bibtex'] == True: self.bibfilectrl.Enable(True) else: self.bibfilectrl.Enable(False) self.bibfilectrl.SetPath(nprofile['bibliography_file'])
def suggest_type(gd, bd): '''Suggest a bibtex type based on google's format field and whether appropriate fields are filled''' if gd.has_key('format'): fmt = gd['format'] else: return PIE_CONFIG.get('Format', 'default_bibtex_entry_type') if fmt.lower() in bibtexfields.keys(): # canuse = True # for f in bibtexfields[fmt][0]: # if not f in bd.keys(): # canuse = False # break # if canuse: # return fmt # else: # return PIE_CONFIG.get('Format', 'default_bibtex_entry_type') return fmt else: return PIE_CONFIG.get('Format', 'default_bibtex_entry_type')
def _set_columndata(self, idx, obj, msgtype=None): '''Set relevant data to the column at row: idx''' # print 'BibListCtrl._set_columndata' if not msgtype: msgtype = obj.get_icon_code('bibwindow') self.SetItemImage(idx, MessageType[msgtype]) # self.SetItemText(idx, '') if obj.notes: self.SetStringItem(idx, 1, u'\u270D') # writing pen else: self.SetStringItem(idx, 1, '') self.SetStringItem(idx, 2, obj.Author()) self.SetStringItem(idx, 3, fmtdate(obj.ReferDate())) self.SetStringItem(idx, 4, obj.Title(atom_title_hack=ATH)) if obj.StatData_FollowUpFlag: td = datetime.datetime.today() - obj.StatData_FollowUpDate if td.days < PIE_CONFIG.getint('Internal', 'flagged_purpleafter'): self.SetItemTextColour(idx, 'blue') elif td.days > PIE_CONFIG.getint('Internal', 'flagged_redafter'): self.SetItemTextColour(idx, 'red') else: self.SetItemTextColour(idx, 'purple') else: self.SetItemTextColour(idx, wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT))
def OnSetPassword(self, evt): existpwd = PIE_CONFIG.get('Security', 'file_key_unhashed') if existpwd: dia0 = wx.MessageDialog( self, _('There already appears to be a password set.\nChanging it now will mean that any files you have already\nencrypted will become UNREADABLE.\nChanging your password should NOT be necessary, but you can\nproceed if you wish.' ), _('Warning'), style=wx.OK | wx.CANCEL) ans = dia0.ShowModal() if ans == wx.ID_CANCEL: return dia0a = wx.PasswordEntryDialog(self, _('Enter existing password')) ans = dia0a.ShowModal() if ans == wx.ID_CANCEL: return pwd0 = dia0a.GetValue() dia0a.Destroy() if pwd0 != existpwd: wx.MessageBox(_('That is not your current password'), _('Error')) return dia1 = wx.PasswordEntryDialog(self, _('Enter password')) ans = dia1.ShowModal() if ans == wx.ID_CANCEL: return pwd1 = dia1.GetValue() dia1.Destroy() dia2 = wx.PasswordEntryDialog(self, _('Confirm password')) ans = dia2.ShowModal() if ans == wx.ID_CANCEL: return pwd2 = dia2.GetValue() dia2.Destroy() if pwd1 != pwd2: wx.MessageBox(_('The passwords did not match.'), _('Error')) return if len(pwd1) < 4: wx.MessageBox(_('This password seems a bit short. Try another')) return PIE_CONFIG.set('Security', 'file_key', pwd1) assert PIE_CONFIG.get('Security', 'file_key') != None PIE_INTERNALS.set_encryption_hash( PIE_CONFIG.get('Security', 'file_key'))
def f_(text, protectcaps=False): if type(text) in (str, unicode): if protectcaps: text = protect_caps( text, PIE_CONFIG.getboolean( 'Format', 'protect_all_caps_in_citations') ) if texify: text = eblc(text) return text else: #this ain't text, don't touch it return text
def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.defbibtexchoice = wx.Choice(self, -1, choices=self.bibtexchoices.keys()) self.defbibtexchoice.SetStringSelection( PIE_CONFIG.get('Format', 'default_bibtex_entry_type')) tta = wx.ToolTip( _('Web pages and downloads will use this type by default')) self.defbibtexchoice.SetToolTip(tta) self.howpublishedtext = wx.TextCtrl(self, -1, validator=pieBibtexValidator(True)) ttb = wx.ToolTip( _('Web pages and downloads will use this text in the "howpublished" field by default' )) self.howpublishedtext.SetValue( PIE_CONFIG.get('Format', 'default_howpublished_text')) self.urlchoice = wx.Choice(self, -1, choices=self.uchz.keys()) ttc = wx.ToolTip( _("When referencing urls, should pieberry use the full URL, the page that referred to the full URL (where possible) or just the domain name of the site?" )) self.urlchoice.SetToolTip(ttc) self.urlchoice.SetStringSelection(self.uchz_rv[PIE_CONFIG.get( 'Format', 'url_level_represent')]) self.plaintextfmtchoice = wx.Choice(self, -1, choices=self.ptxtfchz.keys()) self.plaintextfmtchoice.SetStringSelection( self.ptxtfchz_rv[PIE_CONFIG.get('Format', 'plaintext_citation_format')]) self.protectcaps_cb = wx.CheckBox( self, -1, _('Prevent reformatting of capital letters in citations')) self.protectcaps_cb.SetValue( PIE_CONFIG.getboolean('Format', 'protect_all_caps_in_citations')) self.writepdf_cb = wx.CheckBox(self, -1, _('Write file metadata when possible')) ttd = wx.ToolTip( _(''' Pieberry will try to update metadata fields of pdf, office-xml and open document files to reflect the known bibliographic data to a limited extent (generally just the title and author). It doesn\'t always, however, work (but should fail safe)''')) self.writepdf_cb.SetToolTip(ttd) self.writepdf_cb.SetValue( PIE_CONFIG.getboolean('Format', 'write_file_metadata')) self.fnlen_spinner = wx.SpinCtrl(self, -1, min=40, max=255) self.fnlen_spinner.SetValue( PIE_CONFIG.getint('Format', 'filesystem_length_limit')) self._do_layout() self._do_bindings()
def _set_columndata(self, idx, obj, msgtype=None): '''Set relevant data to the column at row: idx''' # print 'BibListCtrl._set_columndata' if not msgtype: msgtype = obj.get_icon_code('bibwindow') self.SetItemImage(idx, MessageType[msgtype]) # self.SetItemText(idx, '') if obj.notes: self.SetStringItem(idx, 1, u'\u270D') # writing pen else: self.SetStringItem(idx, 1, '') self.SetStringItem(idx, 2, obj.Author()) self.SetStringItem(idx, 3, fmtdate(obj.ReferDate())) self.SetStringItem(idx, 4, obj.Title(atom_title_hack=ATH)) if obj.StatData_FollowUpFlag: td = datetime.datetime.today() - obj.StatData_FollowUpDate if td.days < PIE_CONFIG.getint('Internal', 'flagged_purpleafter'): self.SetItemTextColour(idx, 'blue') elif td.days > PIE_CONFIG.getint('Internal', 'flagged_redafter'): self.SetItemTextColour(idx, 'red') else: self.SetItemTextColour(idx, 'purple') else: self.SetItemTextColour( idx, wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOWTEXT))
def __init__(self, *args, **kw): wx.Panel.__init__(self, *args, **kw) sizer = wx.BoxSizer(wx.VERTICAL) self.toolbar = wx.ToolBar(self, -1) self.MakeToolBar() self.titlelabel = wx.StaticText(self, -1, 'The title') self.authorlabel = wx.StaticText(self, -1, 'The Author') self.datelabel = wx.StaticText(self, -1, 'Date') self.tagedit = PieTagWidget(self, -1, mode="lhorizontal") self.tagedit.setTagList(get_all_tags().keys()) self.tagedit.Bind(EVT_PIE_TAG_ADDED, self.OnTagAdded) self.tagedit.Bind(EVT_PIE_TAG_CLICKED, self.OnTagClicked) self.rtc = rt.RichTextCtrl( self, style=wx.VSCROLL|wx.HSCROLL|wx.NO_BORDER|wx.WANTS_CHARS) rtcfont = wx.Font(12, wx.FONTFAMILY_ROMAN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL) self.rtc.SetFont(rtcfont) sizer.Add(self.titlelabel, 0, wx.EXPAND|wx.ALL, 5) font = wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD) self.titlelabel.SetFont(font) sizer.Add(self.authorlabel, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) sizer.Add(self.datelabel, 0, wx.EXPAND|wx.ALL, 5) sizer.Add(self.tagedit) sizer.Add(self.toolbar, 0, wx.EXPAND) sizer.Add(self.rtc, 1, wx.ALL|wx.EXPAND, 0) self.savebt = wx.Button(self, -1, _('Save')) self.donebt = wx.Button(self, -1, _('Save and Close')) lsizer = wx.BoxSizer(wx.HORIZONTAL) lsizer.Add((20,20), 1) lsizer.Add(self.savebt, 0, wx.ALL, 3) lsizer.Add(self.donebt, 0, wx.ALL, 3) sizer.Add(lsizer, 0, wx.EXPAND) self.SetSizer(sizer) self.Layout() self._do_bindings() self.savetimer = PeriodicSaveTimer(self) self.savetimer.Start(PIE_CONFIG.getint('Internal', 'minutes_between_save_notes') * 60 * 1000) wx.CallAfter(self.rtc.SetFocus)
def Url(self): '''The most salient url for _reference_ purposes. If the actual URL is definitely needed, access property WebData_Url''' if not self.WebData_Url: return '' behav = PIE_CONFIG.get('Format', 'url_level_represent') if behav == 'full': return self.WebData_Url elif behav == 'referpage': if self.WebData_PageUrl: return self.WebData_PageUrl else: return self.WebData_Url elif behav == 'domain': return validify_domain(self.WebData_Url) else: raise ValueError, 'Invalid url handling variable'
def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.defbibtexchoice = wx.Choice(self, -1, choices=self.bibtexchoices.keys()) self.defbibtexchoice.SetStringSelection( PIE_CONFIG.get('Format', 'default_bibtex_entry_type')) tta = wx.ToolTip(_('Web pages and downloads will use this type by default')) self.defbibtexchoice.SetToolTip(tta) self.howpublishedtext = wx.TextCtrl(self, -1, validator=pieBibtexValidator(True)) ttb = wx.ToolTip(_('Web pages and downloads will use this text in the "howpublished" field by default')) self.howpublishedtext.SetValue( PIE_CONFIG.get('Format', 'default_howpublished_text')) self.urlchoice = wx.Choice(self, -1, choices = self.uchz.keys()) ttc = wx.ToolTip(_("When referencing urls, should pieberry use the full URL, the page that referred to the full URL (where possible) or just the domain name of the site?")) self.urlchoice.SetToolTip(ttc) self.urlchoice.SetStringSelection( self.uchz_rv[PIE_CONFIG.get('Format', 'url_level_represent')]) self.plaintextfmtchoice = wx.Choice(self, -1, choices=self.ptxtfchz.keys()) self.plaintextfmtchoice.SetStringSelection( self.ptxtfchz_rv[PIE_CONFIG.get('Format', 'plaintext_citation_format')]) self.protectcaps_cb = wx.CheckBox(self, -1, _('Prevent reformatting of capital letters in citations')) self.protectcaps_cb.SetValue( PIE_CONFIG.getboolean('Format', 'protect_all_caps_in_citations')) self.writepdf_cb = wx.CheckBox(self, -1, _('Write file metadata when possible')) ttd = wx.ToolTip(_(''' Pieberry will try to update metadata fields of pdf, office-xml and open document files to reflect the known bibliographic data to a limited extent (generally just the title and author). It doesn\'t always, however, work (but should fail safe)''')) self.writepdf_cb.SetToolTip(ttd) self.writepdf_cb.SetValue( PIE_CONFIG.getboolean('Format', 'write_file_metadata')) self.fnlen_spinner = wx.SpinCtrl(self, -1, min=40, max=255) self.fnlen_spinner.SetValue( PIE_CONFIG.getint('Format', 'filesystem_length_limit')) self._do_layout() self._do_bindings()
def __fill_fields(self, obj): '''Preload data''' self.obj = obj if obj.BibData_Key: self.keyAutoCb.SetValue(False) self.keyCtrl.SetValue(obj.BibData_Key) else: self.keyAutoCb.SetValue(True) self.keyCtrl.SetValue('Autogen') #autogen_bibtex_key(bibdata)) self.keyCtrl.Enable(False) if obj.BibData_Type: self.choiceBook.ChangeSelection( self.panelref.index(obj.BibData_Type.lower())) else: self.choiceBook.ChangeSelection( self.panelref.index( PIE_CONFIG.get('Format', 'default_bibtex_entry_type').lower())) self.authorCtrl.SetValue(obj.Author()) if obj.AuthorIsCorporate(): self.authorIsCorporateCb.SetValue(wx.CHK_CHECKED) if obj.filemetadata.has_key('author'): if type(obj.filemetadata['author']) in (unicode, str): self.authorAltCtrl.SetValue(obj.filemetadata['author']) self.titleCtrl.SetValue(obj.Title(texstuff=True)) if obj.filemetadata.has_key('title'): if type(obj.filemetadata['title']) in (unicode, str): self.titleAltCtrl.SetValue(obj.filemetadata['title']) print obj.ReferDate().timetuple() self.datePicker.SetValue(pydate2wxdate(obj.ReferDate())) if obj.BibData_Abstract: self.abstractct.SetValue(obj.BibData_Abstract) self.authorCtrl.SetFocus() bibdata = {} for bibtexkey, objkey in bibtexmap.items(): bibdata[bibtexkey] = getattr(obj, objkey) for i in range(len(self.panelref)): self.choiceBook.GetPage(i).setData(bibdata)
def __fill_fields(self, obj): '''Preload data''' self.obj = obj if obj.BibData_Key: self.keyAutoCb.SetValue(False) self.keyCtrl.SetValue(obj.BibData_Key) else: self.keyAutoCb.SetValue(True) self.keyCtrl.SetValue('Autogen')#autogen_bibtex_key(bibdata)) self.keyCtrl.Enable(False) if obj.BibData_Type: self.choiceBook.ChangeSelection( self.panelref.index(obj.BibData_Type.lower())) else: self.choiceBook.ChangeSelection( self.panelref.index(PIE_CONFIG.get( 'Format', 'default_bibtex_entry_type').lower())) self.authorCtrl.SetValue(obj.Author()) if obj.AuthorIsCorporate(): self.authorIsCorporateCb.SetValue(wx.CHK_CHECKED) if obj.filemetadata.has_key('author'): if type(obj.filemetadata['author']) in (unicode, str): self.authorAltCtrl.SetValue(obj.filemetadata['author']) self.titleCtrl.SetValue(obj.Title(texstuff=True)) if obj.filemetadata.has_key('title'): if type(obj.filemetadata['title']) in (unicode, str): self.titleAltCtrl.SetValue(obj.filemetadata['title']) print obj.ReferDate().timetuple() self.datePicker.SetValue( pydate2wxdate(obj.ReferDate())) if obj.BibData_Abstract: self.abstractct.SetValue(obj.BibData_Abstract) self.authorCtrl.SetFocus() bibdata = {} for bibtexkey, objkey in bibtexmap.items(): bibdata[bibtexkey] = getattr(obj, objkey) for i in range(len(self.panelref)): self.choiceBook.GetPage(i).setData(bibdata)
def __init__(self, *args, **kwds): # begin wxGlade: GladeMainWindow.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self._mgr = wxaui.AuiManager(self) self.ContextPane = BetterContextPanel(self, -1) # self.TabPane = NBPanel(self) # self.TabBook = self.TabPane.nb self.TabBook = wxauip.AuiNotebook(self, -1) if PIE_CONFIG.get('Internal', 'tab_art') == 'simple': self.TabBook.SetArtProvider(wxauip.AuiSimpleTabArt()) # self.TabBook.SetMinSize((500,500)) # self.TabBook = fnb.FlatNotebook(self, -1) self.StatusBar = wx.StatusBar(self, -1) if sys.platform != 'win32': self.StatusBar.SetStatusStyles([1, wx.SB_FLAT]) # Menu Bar menuBar = wx.MenuBar() fileMenu = wx.Menu() toolMenu = wx.Menu() locateMenu = wx.Menu() gatherMenu = wx.Menu() viewMenu = wx.Menu() helpMenu = wx.Menu() atomMenu = wx.Menu() debugMenu = wx.Menu() self.menu_savebibs = wx.MenuItem( fileMenu, -1, _('&Export Bibliography\tCtrl-shift-b'), _('Export all starred items with bibliographic data to a BibTeX file')) self.menu_savebibs.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_MENU, (16, 16))) self.menu_print = wx.MenuItem( fileMenu, -1, _('&Print\tCtrl-p'), _('Print notes or report')) self.menu_print.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_MENU)) self.menu_pagesetup = wx.MenuItem( fileMenu, -1, _('P&age setup'), _('Set up printer page layout')) self.menu_quit = wx.MenuItem( fileMenu, -1, _('&Quit\tCtrl-q'), _('Quit')) self.menu_quit.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_MENU)) self.menu_rescan = wx.MenuItem( fileMenu, -1, _('&Index folders now'), _('Make Pieberry scan and index files and folders in your Pieberry directory')) self.menu_config = wx.MenuItem(fileMenu, -1, _('S&ettings'), _('Configure Pieberry')) self.menu_about = wx.MenuItem(helpMenu, -1, _('&About'), _('About Pieberry')) # self.menu_pageref = wx.MenuItem( # toolMenu, # -1, # _('Create &reference for top-level page'), # _('Reference')) self.menu_emptyref = wx.MenuItem( toolMenu, -1, _('&Create new (empty) bibliography entry\tCtrl-n'), _('Bring up a dialog to allow you to enter bibliographic data')) self.menu_emptyref.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_MENU)) self.menu_manual = wx.MenuItem(helpMenu, -1, _('&Manual')) self.menu_atom_process = wx.MenuItem( atomMenu, -1, _('&Process files from desktop\tCtrl-m'), _('Get documents off your desktop and sort them into folders')) self.menu_atom_process.SetBitmap( wx.Bitmap(os.path.join(IMGDIR, 'ic_broom16.png'))) # self.menu_atom_settings = wx.MenuItem( # atomMenu, -1, _('Desktop cleaner settings'), 'Settings') self.menu_find = wx.MenuItem( toolMenu, -1, _('&Find items in bibliography\tCtrl-f'), _('Search Pieberry\'s internal database')) self.menu_find.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_FIND, wx.ART_MENU)) self.menu_find_in_folders = wx.MenuItem( toolMenu, -1, _('F&ind your files\tCtrl-shift-f'), _('Search database by file name')) self.menu_find_in_folders.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_FIND, wx.ART_MENU)) self.menu_scan_web_page = wx.MenuItem( gatherMenu, -1, _('Scan &web page for documents\tCtrl-w'), _('Read and find links to documents on a given web page')) self.menu_scan_web_page.SetBitmap( wx.Bitmap(os.path.join(IMGDIR, 'ic_globe16.png'))) self.menu_google_books = wx.MenuItem( gatherMenu, -1, _('Search &Google Books\tCtrl-g'), _('Search Google Books for relevant references')) self.menu_google_books.SetBitmap( wx.Bitmap(os.path.join(IMGDIR, 'ic_google16.png'))) if ZBAR: self.menu_scan_barcode = wx.MenuItem( gatherMenu, -1, _('Scan ISBN &barcode\tCtrl-shift-o'), _('Scan a book\'s barcode containing its ISBN and look it up in Google Books')) self.menu_import_pieslice = wx.MenuItem( gatherMenu, -1, _('Import from pieslice file'), _("Import bundled information in Pieberry's own 'pieslice' file format")) self.menu_import_bibtex = wx.MenuItem( gatherMenu, -1, _('&Import from BibTeX file'), _('Import biblographic items from a BibTeX file')) self.menu_paste_bibtex = wx.MenuItem( gatherMenu, -1, _('&Paste in BibTeX entries\tCtrl-shift-p'), _('Paste BibTeX format citations from a source like JStor')) self.menu_import_bibtex.SetBitmap( wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_MENU)) self.menu_filter = wx.MenuItem( locateMenu, -1, _('Fil&ter\tCtrl-t'), _('Filter the items in the current view')) self.menu_toggle_context = wx.MenuItem( viewMenu, -1, _('&Toggle context panel')) self.menu_toggle_context.SetCheckable(True) self.menu_view_starred = wx.MenuItem( viewMenu, -1, _('View &important documents\tCtrl-1')) self.menu_view_flagged = wx.MenuItem( viewMenu, -1, _('View documents &flagged for review/follow-up\tCtrl-2')) self.menu_view_recentact = wx.MenuItem( viewMenu, -1, _('View most r&ecently used documents\tCtrl-3')) self.menu_view_recent = wx.MenuItem( viewMenu, -1, _('View most &recently added documents\tCtrl-4')) self.menu_view_project_folders = wx.MenuItem( viewMenu, -1, _('&Navigate project folders\tCtrl-7')) self.menu_view_library_folders = wx.MenuItem( viewMenu, -1, _('N&avigate library folders\tCtrl-8')) self.menu_view_meetingpaper_folders = wx.MenuItem( viewMenu, -1, _('Na&vigate meeting paper folders\tCtrl-9')) self.menu_view_tags = wx.MenuItem( viewMenu, -1, _('View Tags\tCtrl-0')) # BEGIN debug menu if PIE_CONFIG.getboolean('Internal', 'show_debug_ui'): self.menu_debug_addwebpane = wx.MenuItem( debugMenu, -1, _('Add Web Pane')) self.menu_debug_addbibpane = wx.MenuItem( debugMenu, -1, _('Add Bib Pane')) self.menu_debug_adddlpane = wx.MenuItem( debugMenu, -1, _('Add Pane with dld items')) self.menu_debug_addatompane = wx.MenuItem( debugMenu, -1, _('Add Pane with desktop items')) self.menu_debug_forcescan = wx.MenuItem( debugMenu, -1, _('Force scan of folders')) self.menu_debug_notespane = wx.MenuItem( debugMenu, -1, 'Add notes pane') self.menu_debug_rectifyobjectrels = wx.MenuItem( debugMenu, -1, 'Rectify object relationships' ) debugMenu.AppendItem(self.menu_debug_addatompane) debugMenu.AppendItem(self.menu_debug_adddlpane) debugMenu.AppendItem(self.menu_debug_addwebpane) debugMenu.AppendItem(self.menu_debug_addbibpane) debugMenu.AppendItem(self.menu_debug_forcescan) debugMenu.AppendItem(self.menu_debug_notespane) debugMenu.AppendItem(self.menu_debug_rectifyobjectrels) self.Bind(wx.EVT_MENU, self.DebugAddNotesPane, self.menu_debug_notespane) self.Bind(wx.EVT_MENU, self.DebugAddAtomisePane, self.menu_debug_addatompane) self.Bind(wx.EVT_MENU, self.DebugAddDownloadedPane, self.menu_debug_adddlpane) self.Bind(wx.EVT_MENU, self.DebugAddWebPane, self.menu_debug_addwebpane) self.Bind(wx.EVT_MENU, self.DebugAddBibPane, self.menu_debug_addbibpane) self.Bind(wx.EVT_MENU, self.DebugForceScan, self.menu_debug_forcescan) self.Bind(wx.EVT_MENU, self.DebugRectifyObjectRels, self.menu_debug_rectifyobjectrels) # END debug menu fileMenu.AppendItem(self.menu_savebibs) fileMenu.AppendItem(self.menu_print) fileMenu.AppendItem(self.menu_pagesetup) fileMenu.AppendItem(self.menu_config) fileMenu.AppendItem(self.menu_rescan) fileMenu.AppendSeparator() fileMenu.AppendItem(self.menu_quit) helpMenu.AppendItem(self.menu_manual) helpMenu.AppendItem(self.menu_about) locateMenu.AppendItem(self.menu_find) locateMenu.AppendItem(self.menu_find_in_folders) locateMenu.AppendItem(self.menu_filter) gatherMenu.AppendItem(self.menu_scan_web_page) gatherMenu.AppendItem(self.menu_google_books) if ZBAR: gatherMenu.AppendItem(self.menu_scan_barcode) gatherMenu.AppendSeparator() gatherMenu.AppendItem(self.menu_emptyref) gatherMenu.AppendItem(self.menu_import_pieslice) gatherMenu.AppendItem(self.menu_import_bibtex) gatherMenu.AppendItem(self.menu_paste_bibtex) gatherMenu.AppendSeparator() gatherMenu.AppendItem(self.menu_atom_process) viewMenu.AppendItem(self.menu_toggle_context) viewMenu.AppendSeparator() viewMenu.AppendItem(self.menu_view_starred) viewMenu.AppendItem(self.menu_view_flagged) viewMenu.AppendItem(self.menu_view_recentact) viewMenu.AppendItem(self.menu_view_recent) viewMenu.AppendSeparator() viewMenu.AppendItem(self.menu_view_project_folders) viewMenu.AppendItem(self.menu_view_library_folders) viewMenu.AppendItem(self.menu_view_meetingpaper_folders) viewMenu.AppendSeparator() viewMenu.AppendItem(self.menu_view_tags) menuBar.Append(fileMenu, _('&File')) menuBar.Append(gatherMenu, _('&Gather')) menuBar.Append(locateMenu, _('&Locate')) menuBar.Append(viewMenu, _('&View')) menuBar.Append(helpMenu, _('&Help')) if PIE_CONFIG.getboolean('Internal', 'show_debug_ui'): menuBar.Append(debugMenu, _('&Debug')) self.SetMenuBar(menuBar) self.SetAutoLayout(True) self.Bind(wx.EVT_MENU, self.OnPrint, self.menu_print) self.Bind(wx.EVT_MENU, self.OnPageSetup, self.menu_pagesetup) self.Bind(wx.EVT_MENU, self.onFind, self.menu_find) self.Bind(wx.EVT_MENU, self.onFindInFolders, self.menu_find_in_folders) self.Bind(wx.EVT_MENU, self.OnDesktopProcessGen, self.menu_atom_process) self.Bind(wx.EVT_MENU, self.onSaveBibs, self.menu_savebibs) self.Bind(wx.EVT_MENU, self.onClose, self.menu_quit) wx.EVT_CLOSE(self, self.onClose) self.Bind(wx.EVT_MENU, self.onConfig, self.menu_config) self.Bind(wx.EVT_MENU, self.onAbout, self.menu_about) self.Bind(wx.EVT_MENU, self.OnCreateNewBibObj, self.menu_emptyref) self.Bind(wx.EVT_MENU, self.onShowManual, self.menu_manual) self.Bind(wx.EVT_MENU, self.ToggleWebPanel, self.menu_scan_web_page) self.Bind(wx.EVT_MENU, self.ToggleFilterPanel, self.menu_filter) self.Bind(wx.EVT_MENU, self.ToggleContextPanel, self.menu_toggle_context) self.Bind(wx.EVT_MENU, self.OnImportPieSlice, self.menu_import_pieslice) self.Bind(wx.EVT_MENU, self.OnImportBibtex, self.menu_import_bibtex) self.Bind(wx.EVT_MENU, self.OnPasteBibtex, self.menu_paste_bibtex) self.Bind(wx.EVT_MENU, self.OnViewMostRecent, self.menu_view_recent) self.Bind(wx.EVT_MENU, self.OnViewFlagged, self.menu_view_flagged) self.Bind(wx.EVT_MENU, self.OnViewRecentlyInteracted, self.menu_view_recentact) self.Bind(wx.EVT_MENU, self.OnViewStarred, self.menu_view_starred) self.Bind(wx.EVT_MENU, self.OnViewProjectFolders, self.menu_view_project_folders) self.Bind(wx.EVT_MENU, self.OnViewLibraryFolders, self.menu_view_library_folders) self.Bind(wx.EVT_MENU, self.OnViewMeetingPaperFolders, self.menu_view_meetingpaper_folders) self.Bind(wx.EVT_MENU, self.OnViewTags, self.menu_view_tags) self.Bind(wx.EVT_MENU, self.OnStartIndexer, self.menu_rescan) self.Bind(wx.EVT_MENU, self.ToggleGoogleSearchPanel, self.menu_google_books) if ZBAR: self.Bind(wx.EVT_MENU, self.OnScanBarcode, self.menu_scan_barcode) # self.menu_savebibs.Enable(False) # self.menu_discard.Enable(False) # Menu Bar end # Printing self.printer = wx.richtext.RichTextPrinting() self.__set_properties() self.__do_layout() self._do_bindings()
import wx, sys, datetime import wx.lib.mixins.listctrl as listmix from pprint import pprint from imagelist import PieImageList, MessageType from pieberry.pieconfig.config import PIE_CONFIG from pieberry.pieutility.date import fmtdate ATH = False if PIE_CONFIG.getboolean('Format', 'atom_title_hack'): ATH = True def filterout(filtertext, fields): '''determine whether to filter out a given term''' if not filtertext: return False to_filter_out = True for t in fields: if filtertext.lower() in t.lower(): to_filter_out = False if to_filter_out: return True else: return False class BaseListCtrl(wx.ListCtrl, listmix.ColumnSorterMixin, listmix.ListCtrlAutoWidthMixin): '''Control for displaying results in the download/scraping process''' columnheads = ('',) columnwidths = (480,) def __init__(self, parent): wx.ListCtrl.__init__(self, parent=parent, id=-1,
def _refill_profile_choice(self): self.profileChoice.Clear() for i in PIE_CONFIG.get_profile_names(): self.profileChoice.Append(i)
def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.profileChoice = wx.Choice(self, -1, choices=PIE_CONFIG.get_profile_names()) self.profileChoice.SetStringSelection( PIE_CONFIG.get('TheProfile', 'current_profile')) tta = wx.ToolTip(_('A profile allows you to point Pieberry at different Pieberry directories and databases')) self.profileChoice.SetToolTip(tta) self.profileaddbt = wx.Button(self, -1, _('Add')) self.rootdirctrl = wx.DirPickerCtrl( self, -1, path = PIE_CONFIG.get('Profile', 'rootdir'), style = wx.DIRP_USE_TEXTCTRL) self.rootdirctrl.SetPath(PIE_CONFIG.get('Profile', 'rootdir')) self.rootdiratstart = PIE_CONFIG.get('Profile', 'rootdir') self.desktopdirctrl = wx.DirPickerCtrl( self, -1, path = PIE_CONFIG.get('Profile', 'desktopdir'), style = wx.DIRP_USE_TEXTCTRL) self.desktopdirctrl.SetPath(PIE_CONFIG.get('Profile', 'desktopdir')) self.bib_cb = wx.CheckBox(self, -1, _('Export bibliography to pre-specified file')) # style=wx.ALIGN_RIGHT) ttb = wx.ToolTip(_("Setting the bibliography here means that Pieberry won't prompt you for a bibliography file every time you export it.")) self.bib_cb.SetToolTip(ttb) self.bib_cb.SetValue(PIE_CONFIG.getboolean('Profile', 'export_bibtex')) self.bibfilectrl = wx.FilePickerCtrl( self, -1, wildcard = "BibTeX files (*.bib;*.bibtex)|*.bib;*.bibtex", style = wx.FLP_USE_TEXTCTRL|wx.FLP_SAVE) if PIE_CONFIG.getboolean('Profile', 'export_bibtex') == True: self.bibfilectrl.Enable(True) else: self.bibfilectrl.Enable(False) self.bibfilectrl.SetPath(PIE_CONFIG.get('Profile', 'bibliography_file')) self.bibexpstarred_cb = wx.CheckBox(self, -1, _('Export starred items only')) ttc = wx.ToolTip(_('Export only starred items with adequate bibliographic data (unchecking will export all with adequate bibliographic data in the library but not project folders)')) self.bibexpstarred_cb.SetToolTip(ttc) self.bibexpstarred_cb.SetValue( PIE_CONFIG.getboolean('Profile', 'export_starred_only')) self._do_layout() self._do_bindings()
def __init__(self, *args, **kwargs): wx.Panel.__init__(self, *args, **kwargs) self.profileChoice = wx.Choice(self, -1, choices=PIE_CONFIG.get_profile_names()) self.profileChoice.SetStringSelection( PIE_CONFIG.get('TheProfile', 'current_profile')) tta = wx.ToolTip( _('A profile allows you to point Pieberry at different Pieberry directories and databases' )) self.profileChoice.SetToolTip(tta) self.profileaddbt = wx.Button(self, -1, _('Add')) self.rootdirctrl = wx.DirPickerCtrl(self, -1, path=PIE_CONFIG.get( 'Profile', 'rootdir'), style=wx.DIRP_USE_TEXTCTRL) self.rootdirctrl.SetPath(PIE_CONFIG.get('Profile', 'rootdir')) self.rootdiratstart = PIE_CONFIG.get('Profile', 'rootdir') self.desktopdirctrl = wx.DirPickerCtrl(self, -1, path=PIE_CONFIG.get( 'Profile', 'desktopdir'), style=wx.DIRP_USE_TEXTCTRL) self.desktopdirctrl.SetPath(PIE_CONFIG.get('Profile', 'desktopdir')) self.bib_cb = wx.CheckBox( self, -1, _('Export bibliography to pre-specified file')) # style=wx.ALIGN_RIGHT) ttb = wx.ToolTip( _("Setting the bibliography here means that Pieberry won't prompt you for a bibliography file every time you export it." )) self.bib_cb.SetToolTip(ttb) self.bib_cb.SetValue(PIE_CONFIG.getboolean('Profile', 'export_bibtex')) self.bibfilectrl = wx.FilePickerCtrl( self, -1, wildcard="BibTeX files (*.bib;*.bibtex)|*.bib;*.bibtex", style=wx.FLP_USE_TEXTCTRL | wx.FLP_SAVE) if PIE_CONFIG.getboolean('Profile', 'export_bibtex') == True: self.bibfilectrl.Enable(True) else: self.bibfilectrl.Enable(False) self.bibfilectrl.SetPath(PIE_CONFIG.get('Profile', 'bibliography_file')) self.bibexpstarred_cb = wx.CheckBox(self, -1, _('Export starred items only')) ttc = wx.ToolTip( _('Export only starred items with adequate bibliographic data (unchecking will export all with adequate bibliographic data in the library but not project folders)' )) self.bibexpstarred_cb.SetToolTip(ttc) self.bibexpstarred_cb.SetValue( PIE_CONFIG.getboolean('Profile', 'export_starred_only')) self._do_layout() self._do_bindings()
from pieberry.pieconfig.config import PIE_CONFIG # use gettext from pieberry.pieconfig.identity import PIE_APPNAME import gettext gettext.install(PIE_APPNAME) # instantiate app app = wx.PySimpleApp(0) wx.InitAllImageHandlers() # run first-run wizard if PIE_CONFIG.getboolean('Internal', 'first_run') or not os.path.isdir(PIE_CONFIG.get('Profile', 'rootdir')): from pieberry.ui.firstrunwizard import show_wizard res, rpaths = show_wizard() if not res: sys.exit(0) PIE_CONFIG.set('Profile', 'rootdir', rpaths[0]) if not os.path.isdir(rpaths[0]): try: os.makedirs(rpaths[0]) except: print 'Could not create user folder - exiting' sys.exit(1) PIE_CONFIG.set('Profile', 'desktopdir', rpaths[1]) assert os.path.isdir(rpaths[1]) # set up user paths
def main(): print '__file__ =', __file__ frozen = getattr(sys, 'frozen', '') if not frozen: # not frozen: in regular python interpreter approot = GetAppdir() elif frozen in ('dll', 'console_exe', 'windows_exe'): # py2exe: approot = os.path.dirname(sys.executable) os.chdir(approot) sys.path.insert(0, approot) print 'Setting working directory:', approot # import global variables print 'Init global variables' from pieberry.pieconfig.globalvars import DEBUG, PY2EXE, PYNOTIFY, U_ERROR_BEHAV # set up system paths print 'Init system paths' import pieberry.pieconfig.initsys pieberry.pieconfig.initsys.init_config_location() pieberry.pieconfig.initsys.init_resource_locations() print 'Init config' # import config source import pieberry.pieconfig.config pieberry.pieconfig.config.make_config() print 'Create config' from pieberry.pieconfig.config import PIE_CONFIG # use gettext from pieberry.pieconfig.identity import PIE_APPNAME, PIE_VERSION import gettext gettext.install(PIE_APPNAME) # instantiate app app = wx.PySimpleApp(0) wx.InitAllImageHandlers() # run first-run wizard if PIE_CONFIG.getboolean('Internal', 'first_run') or not os.path.isdir(PIE_CONFIG.get('Profile', 'rootdir')): from pieberry.ui.firstrunwizard import show_wizard res, rpaths = show_wizard() if not res: sys.exit(0) PIE_CONFIG.set('Profile', 'rootdir', rpaths[0]) if not os.path.isdir(rpaths[0]): try: os.makedirs(rpaths[0]) except: print 'Could not create user folder - exiting' sys.exit(1) PIE_CONFIG.set('Profile', 'desktopdir', rpaths[1]) assert os.path.isdir(rpaths[1]) # set up user paths print 'Init user paths' import pieberry.pieconfig.paths pieberry.pieconfig.paths.init_storage_location(PIE_CONFIG.get('Profile', 'rootdir')) pieberry.pieconfig.paths.create_directories() pieberry.pieconfig.paths.init_desktop_location(PIE_CONFIG.get('Profile', 'desktopdir')) # clean up the cache pieberry.pieconfig.paths.clean_cache_path() # backup database and clean up backup dir from pieberry.piedb.backup import backup_db, clean_backups from pieberry.piedb.dbname import DBNAME from pieberry.pieconfig.paths import DBDIR if not os.path.exists(os.path.join(DBDIR, DBNAME)): dbstarting = True else: dbstarting = False clean_backups() backup_db(DBDIR) # init database print 'Init database' from pieberry.piedb import create_piedb_engine create_piedb_engine(pieberry.pieconfig.paths.DBDIR) from pieberry.piedb import SQLABase, engine, Session # clear out the directories if debugging # if DEBUG: # nuke_directories() # create_directories() # fill_desktopdir() print 'Init pieberry.pieobject' from pieberry.pieobject import PieObject from pieberry.pieobject.tags import init_tags, gen_tag_lookup from pieberry.pieobject.folder import generate_folder_list print 'Init tables' SQLABase.metadata.create_all(engine) if PIE_CONFIG.getboolean('Internal', 'first_run') or dbstarting: init_tags() gen_tag_lookup() print 'Establish internals' from pieberry.pieobject import PIE_INTERNALS PIE_INTERNALS.establish() print 'Generating initial folder list' generate_folder_list() print 'Init PIEBERRY.UI' from functionwindow import FunctionMainWindow frame_1 = FunctionMainWindow(None, -1, "") app.SetTopWindow(frame_1) frame_1.Show() frame_1.SetTitle(u'Pieberry [%s]' % PIE_CONFIG.get('TheProfile', 'current_profile')) PIE_CONFIG.set('Internal', 'first_run', 'False') PIE_CONFIG.write_pieconfig() if PIE_INTERNALS.getboolean('Identity', 'Hitherto_unset'): print 'Need to rectify object relationships' frame_1.DebugRectifyObjectRels(1) PIE_INTERNALS.set('Identity', 'Hitherto_unset', False) app.MainLoop()
def __init__(self): '''entries is a list of bibdata dicts''' self._entries = [] self._location = PIE_CONFIG.get('Profile', 'bibliography_file')
import wx, sys, datetime import wx.lib.mixins.listctrl as listmix from pprint import pprint from imagelist import PieImageList, MessageType from pieberry.pieconfig.config import PIE_CONFIG from pieberry.pieutility.date import fmtdate ATH = False if PIE_CONFIG.getboolean('Format', 'atom_title_hack'): ATH = True def filterout(filtertext, fields): '''determine whether to filter out a given term''' if not filtertext: return False to_filter_out = True for t in fields: if filtertext.lower() in t.lower(): to_filter_out = False if to_filter_out: return True else: return False class BaseListCtrl(wx.ListCtrl, listmix.ColumnSorterMixin, listmix.ListCtrlAutoWidthMixin): '''Control for displaying results in the download/scraping process''' columnheads = ('', ) columnwidths = (480, ) def __init__(self, parent):
import pieberry.pieconfig.config pieberry.pieconfig.config.make_config() print 'Create config' from pieberry.pieconfig.config import PIE_CONFIG # use gettext from pieberry.pieconfig.identity import PIE_APPNAME import gettext gettext.install(PIE_APPNAME) # instantiate app app = wx.PySimpleApp(0) wx.InitAllImageHandlers() # run first-run wizard if PIE_CONFIG.getboolean('Internal', 'first_run') or not os.path.isdir( PIE_CONFIG.get('Profile', 'rootdir')): from pieberry.ui.firstrunwizard import show_wizard res, rpaths = show_wizard() if not res: sys.exit(0) PIE_CONFIG.set('Profile', 'rootdir', rpaths[0]) if not os.path.isdir(rpaths[0]): try: os.makedirs(rpaths[0]) except: print 'Could not create user folder - exiting' sys.exit(1) PIE_CONFIG.set('Profile', 'desktopdir', rpaths[1]) assert os.path.isdir(rpaths[1]) # set up user paths
def main(): print '__file__ =', __file__ frozen = getattr(sys, 'frozen', '') if not frozen: # not frozen: in regular python interpreter approot = GetAppdir() elif frozen in ('dll', 'console_exe', 'windows_exe'): # py2exe: approot = os.path.dirname(sys.executable) os.chdir(approot) sys.path.insert(0, approot) print 'Setting working directory:', approot # import global variables print 'Init global variables' from pieberry.pieconfig.globalvars import DEBUG, PY2EXE, PYNOTIFY, U_ERROR_BEHAV # set up system paths print 'Init system paths' import pieberry.pieconfig.initsys pieberry.pieconfig.initsys.init_config_location() pieberry.pieconfig.initsys.init_resource_locations() print 'Init config' # import config source import pieberry.pieconfig.config pieberry.pieconfig.config.make_config() print 'Create config' from pieberry.pieconfig.config import PIE_CONFIG # use gettext from pieberry.pieconfig.identity import PIE_APPNAME, PIE_VERSION import gettext gettext.install(PIE_APPNAME) # instantiate app app = wx.PySimpleApp(0) wx.InitAllImageHandlers() # run first-run wizard if PIE_CONFIG.getboolean('Internal', 'first_run') or not os.path.isdir( PIE_CONFIG.get('Profile', 'rootdir')): from pieberry.ui.firstrunwizard import show_wizard res, rpaths = show_wizard() if not res: sys.exit(0) PIE_CONFIG.set('Profile', 'rootdir', rpaths[0]) if not os.path.isdir(rpaths[0]): try: os.makedirs(rpaths[0]) except: print 'Could not create user folder - exiting' sys.exit(1) PIE_CONFIG.set('Profile', 'desktopdir', rpaths[1]) assert os.path.isdir(rpaths[1]) # set up user paths print 'Init user paths' import pieberry.pieconfig.paths pieberry.pieconfig.paths.init_storage_location( PIE_CONFIG.get('Profile', 'rootdir')) pieberry.pieconfig.paths.create_directories() pieberry.pieconfig.paths.init_desktop_location( PIE_CONFIG.get('Profile', 'desktopdir')) # clean up the cache pieberry.pieconfig.paths.clean_cache_path() # backup database and clean up backup dir from pieberry.piedb.backup import backup_db, clean_backups from pieberry.piedb.dbname import DBNAME from pieberry.pieconfig.paths import DBDIR if not os.path.exists(os.path.join(DBDIR, DBNAME)): dbstarting = True else: dbstarting = False clean_backups() backup_db(DBDIR) # init database print 'Init database' from pieberry.piedb import create_piedb_engine create_piedb_engine(pieberry.pieconfig.paths.DBDIR) from pieberry.piedb import SQLABase, engine, Session # clear out the directories if debugging # if DEBUG: # nuke_directories() # create_directories() # fill_desktopdir() print 'Init pieberry.pieobject' from pieberry.pieobject import PieObject from pieberry.pieobject.tags import init_tags, gen_tag_lookup from pieberry.pieobject.folder import generate_folder_list print 'Init tables' SQLABase.metadata.create_all(engine) if PIE_CONFIG.getboolean('Internal', 'first_run') or dbstarting: init_tags() gen_tag_lookup() print 'Establish internals' from pieberry.pieobject import PIE_INTERNALS PIE_INTERNALS.establish() print 'Generating initial folder list' generate_folder_list() print 'Init PIEBERRY.UI' from functionwindow import FunctionMainWindow frame_1 = FunctionMainWindow(None, -1, "") app.SetTopWindow(frame_1) frame_1.Show() frame_1.SetTitle(u'Pieberry [%s]' % PIE_CONFIG.get('TheProfile', 'current_profile')) PIE_CONFIG.set('Internal', 'first_run', 'False') PIE_CONFIG.write_pieconfig() if PIE_INTERNALS.getboolean('Identity', 'Hitherto_unset'): print 'Need to rectify object relationships' frame_1.DebugRectifyObjectRels(1) PIE_INTERNALS.set('Identity', 'Hitherto_unset', False) app.MainLoop()