def OnFileOverwrite(self, _): path = self.itemtopath(self.GetFirstSelected()) with guihelper.WXDialogWrapper( wx.FileDialog(self, style=wx.OPEN | wx.HIDE_READONLY | wx.CHANGE_DIR), True) as (dlg, retcode): if retcode == wx.ID_OK: infile = dlg.GetPath() contents = open(infile, "rb").read() mw = self.mainwindow mw.MakeCall( gui.Request(mw.wt.writefile, path, contents), gui.Callback(self.OnFileOverwriteResults, guihelper.dirname(path)))
def _OnEdit(self, _): _idx=self._name_lb.GetSelection() if _idx==wx.NOT_FOUND: return _key=self._name_lb.GetClientData(_idx) _entry=self._data[_key].copy() with guihelper.WXDialogWrapper(ImportCalendarPresetWizard(self, _entry)) \ as _wiz: if _wiz.RunWizard(): _entry=ImportCalendarEntry(_wiz.get()) del self._data[_key] self._data[_entry.id]=_entry self._save_to_fs() self._populate()
def OnNewSubdir(self, _): with guihelper.WXDialogWrapper( wx.TextEntryDialog(self, "Subdirectory name?", "Create Subdirectory", "newfolder"), True) as (dlg, retcode): if retcode == wx.ID_OK: item = self.GetSelection() parent = self.itemtopath(item) if len(parent): path = parent + "/" + dlg.GetValue() else: path = dlg.GetValue() mw = self.mainwindow mw.MakeCall(gui.Request(mw.wt.mkdir, path), gui.Callback(self.OnNewSubdirResults, path))
def OnImport(self, evt): with guihelper.WXDialogWrapper( wx.ProgressDialog('%s Import' % self._data_type, 'Importing %s Data, please wait ...' % self._data_type, parent=self)) as dlg: try: self._oc.read(self.folderctrl.GetValue()) self.populate(self._oc.get_display_data()) except (ValueError, IOError): guihelper.MessageDialog(self, 'Failed to get import data', 'Import Error', style=wx.OK | wx.ICON_ERROR) except: if __debug__: raise
def _OnSetDate(self, _): # bring up a calendar dlg if self._dt is None: dt = datetime.date.today() else: dt = self._dt with guihelper.WXDialogWrapper( wx.lib.calendar.CalenDlg(self, month=dt.month, day=dt.day, year=dt.year)) as dlg: dlg.Centre() if dlg.ShowModal() == wx.ID_OK: self._dt = datetime.date(dlg.calend.GetYear(), dlg.calend.GetMonth(), dlg.calend.GetDay()) self._refresh()
def OnBackupResults(self, path, exception, backup): mw = self.mainwindow if mw.HandleException(exception): return bn = guihelper.basename(path) if len(bn) < 1: bn = "root" bn += ".zip" ext = "Zip files|*.zip|All Files|*" with guihelper.WXDialogWrapper( wx.FileDialog(self, "Save File As", defaultFile=bn, wildcard=ext, style=wx.SAVE | wx.OVERWRITE_PROMPT | wx.CHANGE_DIR), True) as (dlg, retcode): if retcode == wx.ID_OK: file(dlg.GetPath(), "wb").write(backup)
def OnNewFile(self, _): parent = self.itemtopath(self.GetSelection()) with guihelper.WXDialogWrapper( wx.FileDialog(self, style=wx.OPEN | wx.HIDE_READONLY | wx.CHANGE_DIR), True) as (dlg, retcode): if retcode == wx.ID_OK: infile = dlg.GetPath() contents = open(infile, "rb").read() if len(parent): path = parent + "/" + os.path.basename(dlg.GetPath()) else: path = os.path.basename(dlg.GetPath( )) # you can't create files in root but I won't stop you mw = self.mainwindow mw.MakeCall(gui.Request(mw.wt.writefile, path, contents), gui.Callback(self.OnNewFileResults, parent))
def check_update(update_url=None, current_version=None, platform=None, flavor=''): # get info from current version if current_version is None: current_version = version.version # set flavor to blank for now, should be flavor=version.flavor if platform is None: if guihelper.IsMSWindows(): platform = 'windows' elif guihelper.IsGtk(): platform = 'linux' elif guihelper.IsMac(): platform = 'mac' else: raise ValueError, 'Invalid platform' # todo: need to figure out how to do flavor, comment out for now ## flavor=version.vendor # retrieve and parse update info print 'Checking update for BitPim ', current_version, ' running on ', \ platform, '-', flavor with guihelper.WXDialogWrapper( wx.ProgressDialog('BitPim Update', 'Retrieving BitPim Update Information...', style=wx.PD_AUTO_HIDE)) as dlg: bp_update = BitPimUpdate() s = None try: if update_url is None: bp_update.get_update_info() else: bp_update.get_update_info(update_url) dlg.Update(100) except: s = 'Failed to get BitPim update info.' if s is None: s = bp_update.display_update_info(current_version, platform, flavor) latest_version = bp_update.latest_version else: latest_version = '' if s is not None: # error messages being return, display them guihelper.MessageDialog(None, s, 'BitPim Update', wx.OK | wx.ICON_INFORMATION) return latest_version
def OnFileSaveResults(self, path, exception, contents): mw = self.mainwindow if mw.HandleException(exception): return bn = guihelper.basename(path) ext = guihelper.getextension(bn) if len(ext): ext = "%s files (*.%s)|*.%s" % (ext.upper(), ext, ext) else: ext = "All files|*" with guihelper.WXDialogWrapper( wx.FileDialog(self, "Save File As", defaultFile=bn, wildcard=ext, style=wx.SAVE | wx.OVERWRITE_PROMPT | wx.CHANGE_DIR), True) as (dlg, retcode): if retcode == wx.ID_OK: file(dlg.GetPath(), "wb").write(contents)
def OnAddImage(self, img, file, refresh=True, timestamp=None): # ::TODO:: if file is None, find next basename in our directory for # clipboard99 where 99 is next unused number with guihelper.WXDialogWrapper( ImagePreviewDialog(self, img, self.mainwindow.phoneprofile, self.active_section), True) as (dlg, retcode): if retcode == wx.ID_OK: img = dlg.GetResultImage() imgparams = dlg.GetResultParams() origin = self.active_section # if we modified the image update the timestamp if not dlg.skip: timestamp = int(time.time()) # ::TODO:: temporary hack - this should really be an imgparam extension = { 'BMP': 'bmp', 'JPEG': 'jpg', 'PNG': 'png' }[imgparams['format']] # munge name targetfilename = self.get_media_name_from_filename( file, extension) res = getattr(self, "saveimage_" + imgparams['format'])(img, imgparams) if not res: guihelper.MessageDialog( self, "Failed to convert the image in '" + file + "'", "Image not converted", style=wx.OK | wx.ICON_ERROR) return self.AddToIndex(targetfilename, origin, res, self._data, timestamp) if refresh: self.OnRefresh()
def ReplaceContents(self, name, origin, new_file_name): """Replace the contents of 'file_name' by the contents of 'new_file_name' by going through the image converter dialog """ fi = self.GetFileInfo(new_file_name) if fi is not None and fi.format == 'LGBIT': img = conversions.convertfilelgbittobmp(new_file_name) else: img = wx.Image(new_file_name) if not img.Ok(): guihelper.MessageDialog(self, "Failed to understand the image in '" + new_file_name + "'", "Image not understood", style=wx.OK | wx.ICON_ERROR) return with guihelper.WXDialogWrapper( ImagePreviewDialog(self, img, self.mainwindow.phoneprofile, self.active_section), True) as (dlg, retcode): if retcode == wx.ID_OK: img = dlg.GetResultImage() imgparams = dlg.GetResultParams() # ::TODO:: temporary hack - this should really be an imgparam extension = { 'BMP': 'bmp', 'JPEG': 'jpg', 'PNG': 'png' }[imgparams['format']] res = getattr(self, "saveimage_" + imgparams['format'])(img, imgparams) if not res: guihelper.MessageDialog( self, "Failed to convert the image in '" + new_file_name + "'", "Image not converted", style=wx.OK | wx.ICON_ERROR) self.AddToIndex(name, origin, res, self._data)
def OnAddFiles(self, filenames): for file in filenames: if file is None: continue # failed dragdrop? file_stat=os.stat(file) mtime=file_stat.st_mtime if self._raw_media: target=self.get_media_name_from_filename(file) data=open(file, 'rb').read() self.AddToIndex(target, self.active_section, data, self._data, mtime) else: # do we want to convert file? afi=fileinfo.identify_audiofile(file) if afi.size<=0: continue # zero length file or other issues newext,convertinfo=self.mainwindow.phoneprofile.QueryAudio(None, common.getext(file), afi) if convertinfo is not afi: filedata=None wx.EndBusyCursor() try: filedata=self.ConvertFormat(file, convertinfo) finally: # ensure they match up wx.BeginBusyCursor() if filedata is None: continue else: filedata=open(file, "rb").read() # check for the size limit on the file, if specified max_size=getattr(convertinfo, 'MAXSIZE', None) if max_size is not None and len(filedata)>max_size: # the data is too big self.log('ringtone %s is too big!'%common.basename(file)) with guihelper.WXDialogWrapper(wx.MessageDialog(self, 'Ringtone %s may be too big. Do you want to proceed anway?'%common.basename(file), 'Warning', style=wx.YES_NO|wx.ICON_ERROR), True) as (dlg, dlg_resp): if dlg_resp==wx.ID_NO: continue target=self.get_media_name_from_filename(file, newext) self.AddToIndex(target, self.active_section, filedata, self._data, mtime) self.OnRefresh()
def create_new_db(parent, config=None): # Create a new BitPim Storage area with guihelper.WXDialogWrapper(NewDBWizard(parent)) as wz: if wz.RunWizard(): data = wz.get() name = data.get('name', '') # Dir should aleady exist, but check anyway path = data.get('path', '') if not os.path.isdir(path): os.makedirs(path) # create a config file filename = os.path.join(path, '.bitpim') if data.get('currentsettings', False) and config: config.write(file(filename, 'wt')) conf = bp_config.Config(filename) conf.Write('name', name) # and optionally create shortcuts (Windows only) if guihelper.IsMSWindows(): if data.get('desktop', False): create_desktop_shortcut(name, filename) if data.get('startmenu', False): create_startmenu_shortcut(name, filename)
def display_update_info(self, current_version, platform, flavor): # find and display the update info based on current version & platform # find if there's a next version u = self.__updates.get(current_version, None) if u is None: # there're no next version, tell the user & bail return 'There are no updates to the current version: ' + current_version # got the update, look for the version (frm, next_version, priority, alert) = u.info v = self.__versions.get(next_version, None) if v is None: # No info on this version, tell the user & bail return 'No download info on version ' + next_version + ' available.' dl = v.get_download(platform, flavor) if dl is None or not len(dl.source): # the next version is not available for this plaform, bail return 'Load ' + next_version + ' is not available on platform ' + platform + '/' + flavor # everything's there, display them to the users lines = [] lines.append('Current Version: ' + current_version) s = 'Platform: ' + platform if flavor is not None and len(flavor): s += '/' + flavor lines.append(s) lines.append('Available for Upgrade:') lines.append('\tVersion: ' + next_version) lines.append('\tRelease Date: ' + v.release_date) if priority is not None and len(priority): lines.append('\tPriority: ' + priority) if alert is not None and len(alert): lines.append('\tWarning: ' + alert) lines.append('updates.xml Version: ' + self.xml_version) lines.append('Latest BitPim Version: ' + self.latest_version) with guihelper.WXDialogWrapper( UpdateDialog(None, dl.source, v.change_log, lines), True): pass
def OnManageCategories(self, _): with guihelper.WXDialogWrapper(pb_editor.CategoryManager(self), True): pass
def OnPrintDialog(self, mainwindow, config): with guihelper.WXDialogWrapper( guiwidgets.MemoPrintDialog(self, mainwindow, config), True): pass
def _OnFilter(self, _): with guihelper.WXDialogWrapper(FilterDialog(self, -1, 'Filtering Parameters', self._data), True) as (dlg, retcode): if retcode==wx.ID_OK: self._data.update(dlg.get()) self._populate()
def browse(self, parent=None): # how to select a source, default to select a file with guihelper.WXDialogWrapper(wx.FileDialog(parent, self.message_str, wildcard=self.wildcard), True) as (dlg, retcode): if retcode==wx.ID_OK: self._source=dlg.GetPath()
def OnBrowse(self, _): with guihelper.WXDialogWrapper(wx.FileDialog(self, defaultFile=self.filenamectrl.GetValue(), wildcard=self._wildcards, style=wx.SAVE|wx.CHANGE_DIR), True) as (dlg, retcode): if retcode==wx.ID_OK: self.filenamectrl.SetValue(dlg.GetPath())
_entry.validate_properties() _data[_key] = self._expand_item(_entry) database.ensurerecordtype(_data, importcalendarobjectfactory) self._parent.GetActiveDatabase().savemajordict('imp_cal_preset', _data) def get(self): if self._import_data: return self._import_data.get() return {} def get_categories(self): if self._import_data: return self._import_data.get_category_list() return [] def GetActiveDatabase(self): return self._parent.GetActiveDatabase() #------------------------------------------------------------------------------- # Testing if __name__ == "__main__": app = wx.PySimpleApp() f = wx.Frame(None, title='imp_cal_preset') _data = ImportCalendarEntry() _data.id with guihelper.WXDialogWrapper(ImportCalendarPresetWizard(f, _data)) \ as w: print 'RunWizard:', w.RunWizard() print 'Data:', w.get()
def ConvertFormat(self, file, convertinfo): with guihelper.WXDialogWrapper(ConvertDialog(self, file, convertinfo), True) as (dlg, retcode): return dlg.newfiledata if retcode==wx.ID_OK else None
def OnBrowseFolder(self, evt): with guihelper.WXDialogWrapper(wx.FileDialog(self, "Pick a CSV Calendar File", wildcard='*.csv'), True) as (dlg, retcode): if retcode==wx.ID_OK: self.folderctrl.SetValue(dlg.GetPath()) self.__read=False
def OnImport(self, evt): with guihelper.WXDialogWrapper(wx.ProgressDialog('CSV Calendar Import', 'Importing CSV Calendar Data, please wait ...', parent=self)) as dlg: self.__oc.read(self.folderctrl.GetValue()) self.populate(self.__oc.get_display_data())
def OnBrowseFolder(self, _): with guihelper.WXDialogWrapper( SelectURLDialog(self, 'Select a Google Calendar iCal URL', self._db), True) as (dlg, retcode): if retcode == wx.ID_OK: self.folderctrl.SetValue(dlg.GetPath())