def import_xrc(self, event): import xrc2wxg, cStringIO if not self.ask_save(): return infile = misc.FileSelector(_("Import file"), wildcard="XRC files (*.xrc)" "|*.xrc|All files|*", flags=wx.OPEN | wx.FILE_MUST_EXIST, default_path=self.cur_dir) if infile: buf = cStringIO.StringIO() try: xrc2wxg.convert(infile, buf) buf.seek(0) self._open_app(buf, is_filelike=True) common.app_tree.app.saved = False except Exception, msg: import traceback traceback.print_exc() wx.MessageBox(_("An exception occurred while importing file " "\"%s\".\nThis is the error message associated " "with it:\n %s\n" "For more details, look at the full traceback " "on the console.\nIf you think this is a " "wxGlade bug, please report it.") % \ (infile, msg), _("Error"), wx.OK|wx.CENTRE|wx.ICON_ERROR)
def open_app(self, event_unused): """\ loads a wxGlade project from an xml file NOTE: this is very slow and needs optimisation efforts NOTE2: the note above should not be True anymore :) """ if not self.ask_save(): return from xml_parse import XmlWidgetBuilder, ProgressXmlWidgetBuilder infile = misc.FileSelector(_("Open file"), wildcard="wxGlade files (*.wxg)|*.wxg|" "wxGlade Template files (*.wgt)|*.wgt|" "XML files (*.xml)|*.xml|All files|*", flags=wx.OPEN | wx.FILE_MUST_EXIST, default_path=self.cur_dir) if infile: # ALB 2004-10-15 try to restore possible autosave content... if common.check_autosaved(infile) and \ wx.MessageBox(_("There seems to be auto saved data for " "this file: do you want to restore it?"), _("Auto save detected"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES: common.restore_from_autosaved(infile) else: common.remove_autosaved(infile) self._open_app(infile) self.cur_dir = os.path.dirname(infile)
def ShowModal(self): if self.owner.codegen_opt == 0: self.value = misc.FileSelector( self.file_message, self.prev_dir or "", wildcard=self.wildcard, flags=self.file_style) else: self.value = misc.DirSelector( self.dir_message, self.prev_dir or "", style=self.dir_style) if self.value: self.prev_dir = self.value if not os.path.isdir(self.prev_dir): self.prev_dir = os.path.dirname(self.prev_dir) return wx.ID_OK return wx.ID_CANCEL
def builder(parent, sizer, pos, number=[1]): """\ factory function for EditStaticBitmap objects. """ name = 'bitmap_%s' % number[0] while common.app_tree.has_name(name): number[0] += 1 name = 'bitmap_%s' % number[0] bitmap = misc.FileSelector("Select the image") static_bitmap = EditStaticBitmap(name, parent, wx.NewId(), bitmap, sizer, pos, common.property_panel) node = Tree.Node(static_bitmap) static_bitmap.node = node static_bitmap.show_widget(True) common.app_tree.insert(node, sizer.node, pos - 1)
def builder(parent, sizer, pos, number=[1]): """\ factory function for EditBitmapButton objects. """ name = 'bitmap_button_%s' % number[0] while common.app_tree.has_name(name): number[0] += 1 name = 'bitmap_button_%s' % number[0] bitmap = misc.FileSelector(_("Select the image for the button")) button = EditBitmapButton(name, parent, wx.NewId(), bitmap, sizer, pos, common.property_panel) node = Tree.Node(button) button.node = node button.show_widget(True) common.app_tree.insert(node, sizer.node, pos-1)
def save_app_as(self, event): """\ saves a wxGlade project onto an xml file chosen by the user """ fn = misc.FileSelector(_("Save project as..."), wildcard="wxGlade files (*.wxg)|*.wxg|" "wxGlade Template files (*.wgt) |*.wgt|" "XML files (*.xml)|*.xml|All files|*", flags=wx.SAVE | wx.OVERWRITE_PROMPT, default_path=self.cur_dir) if fn: common.app_tree.app.filename = fn #remove the template flag so we can save the file. common.app_tree.app.is_template = False self.save_app(event) self.cur_dir = os.path.dirname(fn) if misc.check_wx_version(2, 3, 3): self.file_history.AddFileToHistory(fn)
def OnBrowse(self, event=None): """ Going to browse for file... """ current = self.GetValue() directory = os.path.split(current) if os.path.isdir(current): directory = current current = '' elif directory and os.path.isdir(directory[0]): current = directory[1] directory = directory[0] else: directory = self.startDirectory value = misc.FileSelector(self.dialogTitle, directory, current, wildcard=self.fileMask, flags=self.fileMode) if value: self.SetValue(value)
def ShowModal(self): self.value = misc.FileSelector( self.message, wildcard=self.wildcard, flags=self.style) if self.value: return wx.ID_OK