def on_import_preferences(self, event=None): """ Imports a preference file. Backs up the user's current preference file into a directory, with a timestamp on the filename """ logger.debug("Prompting to import preferences") wildcard = _("Whyteboard Preference Files") + u" (*.pref)|*.pref" filename = file_dialog(self, _("Import Preferences From..."), wx.OPEN, wildcard, get_home_dir()) if filename: Config().init(filename) _dir = os.path.join(get_home_dir(), u"pref-bkup") if not os.path.isdir(_dir): os.makedirs(_dir) home = os.path.join(get_home_dir(), u"user.pref") if os.path.exists(home): stamp = time.strftime(u"%d-%m-%Y_%H-%M_%S") logger.debug("Renaming old preferences file to [%s]", stamp) os.rename(home, os.path.join(_dir, stamp + u".user.pref")) config = Config().clone() config.init(filename) self.update_config(config.config)
def load_file(self, evt): """ Display a file chooser window and try to load the file """ _dir = self.directory or u"" vids = u"*.avi; *.mkv; *.mov; *.mpg; *ogg; *.wmv" audio = u"*.mp3; *.oga; *.ogg; *.wav" wildcard = u"%s |%s;%s|" % (_("Media Files"), vids, audio) wildcard += u"%s (%s)|%s|" % (_("Video Files"), vids, vids) wildcard += u"%s (%s)|%s" % (_("Audio Files"), audio, audio) name = file_dialog(self, _("Choose a media file"), wx.OPEN, wildcard, _dir) if name: self.do_load_file(name)
def on_export_preferences(self, event=None): """ Copies the user's preferences file to another file. """ if not os.path.exists(Config().filename()): wx.MessageBox(_("You have not set any preferences"), _("Export Error")) return wildcard = _("Whyteboard Preference Files") + u" (*.pref)|*.pref" filename = file_dialog(self, _("Export preferences to..."), wx.SAVE | wx.OVERWRITE_PROMPT, wildcard) if filename: if not os.path.splitext(filename)[1]: filename += u".pref" shutil.copy(os.path.join(get_home_dir(), u"user.pref"), filename)
def on_open(self, event=None, text=None): """ Opens a file, sets Utility's temp. file to the chosen file, prompts for an unsaved file and calls do_open(). text is img/pdf/ps for the "import file" menu item """ wildcard = meta.dialog_wildcard if text == u"img": wildcard = wildcard[wildcard.find(_(u"Image Files")) : wildcard.find(u"|" + _(u'Whyteboard files')) ] # image to page elif text: wildcard = wildcard[wildcard.find(u"PDF/PS/SVG") : wildcard.find(u"*.SVG|")] # page descriptions _dir = Config().get('last_opened_dir') or u"" filename = file_dialog(self, _("Open file..."), wx.OPEN, wildcard, _dir) if filename: self.open_file(filename)
def on_save_as(self, event=None): """ Prompts for the filename and location to save to. """ wildcard = _("Whyteboard file ") + u"(*.wtbd)|*.wtbd" _dir = Config().get('last_opened_dir') or u"" _file = self.util.filename if not _file: _file = u"" name = file_dialog(self, _("Save Whyteboard As..."), wx.SAVE | wx.OVERWRITE_PROMPT, wildcard, _dir, _file) if name: if not os.path.splitext(name)[1]: # no file extension name += u'.wtbd' if is_save_file(name): self.util.filename = name self.on_save()
def on_export_pdf(self, event=None): """ Exports the all the sheets as a PDF. Must first export all sheets as imgages, convert to PDF (displaying a progress bar) and then remove all the temporary files """ if not self.util.im_location: self.util.prompt_for_im() if not self.util.im_location: return filename = file_dialog(self, _("Export data to..."), wx.SAVE | wx.OVERWRITE_PROMPT, u"PDF (*.pdf)|*.pdf") if filename: ext = os.path.splitext(filename)[1] if not ext: # no file extension filename += u'.pdf' elif ext.lower() != u".pdf": wx.MessageBox(_("Invalid filetype to export as:") + u" .%s" % ext, u"Whyteboard") return names = [] canvas = self.canvas for x in range(self.tab_count): self.canvas = self.tabs.GetPage(x) name = u"%s-tempblahhahh-%s-.jpg" % (filename, x) names.append(name) self.util.export(name) self.canvas = canvas self.process = wx.Process(self) files = "" for x in names: files += u'"%s" ' % x # quote filenames for windows cmd = u'%s -define pdf:use-trimbox=true %s"%s"' % (self.util.im_location, files, filename) self.pid = wx.Execute(cmd, wx.EXEC_ASYNC, self.process) self.show_progress_dialog(_("Converting..."), True, True) [os.remove(x) for x in names]
def export_prompt(self): """ Find out the filename to save to """ val = None # return value wildcard = (u"PNG (*.png)|*.png|JPEG (*.jpg, *.jpeg)|*.jpeg;*.jpg|" + u"BMP (*.bmp)|*.bmp|TIFF (*.tiff)|*.tiff") filename = file_dialog(self, _("Export data to..."), wx.SAVE | wx.OVERWRITE_PROMPT, wildcard) if filename: _name = os.path.splitext(filename)[1].replace(u".", u"") types = {0: u"png", 1: u"jpg", 2: u"bmp", 3: u"tiff"} if not os.path.splitext(filename)[1]: _name = types[dlg.GetFilterIndex()] filename += u"." + _name val = filename if not _name in meta.types[2:]: wx.MessageBox(u"%s .%s" % (_("Invalid filetype to export as:"), _name), u"Whyteboard") else: val = filename return val