def _create_control(self, parent): """ Create the toolkit-specific control that represents the window. """ control = wx.MDIParentFrame(parent, -1, self.title, style=wx.DEFAULT_FRAME_STYLE, size=self.size, pos=self.position) return control
def createParentWindowCtr(self): self._parentWindowUI = wx.MDIParentFrame(None, -1, title=ProjectConfig["name"], size=ProjectConfig["winSize"], style=wx.DEFAULT_FRAME_STYLE | wx.FRAME_NO_WINDOW_MENU) # 加载并获取UI self._parentWindowUI.Bind(wx.EVT_SIZE, self.onParentWinSize) self._parentWindowUI.ClientWindow.Bind(wx.EVT_SIZE, self.onClientWinSize) self.__PreWinUISize = self._parentWindowUI.Size # 初始化self.__PreWinUISize self._parentWindowUI.ClientWindow.Size = self._parentWindowUI.Size
def preview(self, widget, position=None): """Generate and instantiate preview widget. None will be returned in case of errors. The error details are written to the application log file.""" preview_filename = self._get_preview_filename() if preview_filename is None: return if wx.Platform == "__WXMAC__" and not compat.PYTHON2: # workaround for Mac OS testing: sometimes the caches need to be invalidated import importlib importlib.invalidate_caches() # make a valid name for the class (this can be invalid for some sensible reasons...) preview_classname = widget.WX_CLASS.split('.')[-1].split(':')[-1] # randomize the class name to make preview work when there are multiple classes with the same name (e.g. XRC) preview_classname = '_%d_%s' % (random.randrange(10**8, 10** 9), preview_classname) widget.properties["class"].set_temp(preview_classname) frame = None try: self.generate_code(True, preview_filename, widget) # import generated preview module dynamically preview_path = os.path.dirname(preview_filename) preview_module_name = os.path.basename(preview_filename) preview_module_name = os.path.splitext(preview_module_name)[0] preview_module = plugins.import_module(preview_path, preview_module_name) if not preview_module: misc.error_message( _('Can not import the preview module from file \n"%s".\n' 'The details are written to the log file.\n' 'If you think this is a wxGlade bug, please report it.') % self.output_path) return None try: preview_class = getattr(preview_module, preview_classname) # .klass) except AttributeError: # module loaded previously -> do a re-load XXX this is required for Python 3; check alternatives if sys.version_info.major < 3: preview_module = reload(preview_module) else: import importlib preview_module = importlib.reload(preview_module) preview_class = getattr(preview_module, preview_classname) if not preview_class: misc.error_message( _('No preview class "%s" found.\nThe details are written to the log file.\n' 'If you think this is a wxGlade bug, please report it.') % widget.klass) return None if issubclass(preview_class, wx.MDIChildFrame): frame = wx.MDIParentFrame(None, -1, '') frame.SetMenuBar(wx.MenuBar()) # avoid assertion error child = preview_class(frame, -1, '') child.SetTitle('<Preview> - ' + child.GetTitle()) w, h = child.GetSize() frame.SetClientSize((w + 20, h + 20)) elif not issubclass(preview_class, (wx.Frame, wx.Dialog)): # the toplevel class isn't really toplevel, add a frame... frame = wx.Frame(None, -1, widget.klass) if issubclass(preview_class, wx.MenuBar): menubar = preview_class() frame.SetMenuBar(menubar) panel = wx.Panel(frame) elif issubclass(preview_class, wx.ToolBar): toolbar = preview_class(frame, -1) frame.SetToolBar(toolbar) panel = wx.Panel(frame) frame.SetMinSize(toolbar.GetBestSize()) frame.Fit() else: panel = preview_class(frame, -1) frame.Fit() else: frame = preview_class(None, -1, '') def on_close(event): frame.Unbind(wx.EVT_CHAR_HOOK) compat.DestroyLater(frame) widget.preview_widget = None widget.properties["preview"].set_label(_('Show Preview')) frame.Bind(wx.EVT_CLOSE, on_close) frame.SetTitle(_('<Preview> - %s') % frame.GetTitle()) # raise the frame if position: frame.SetPosition(position) else: frame.CenterOnScreen() if widget.widget: # avoid Design and Preview window at the same position pos = widget.widget.GetPosition() if frame.GetPosition() == pos: frame.SetPosition((pos[0] + 200, pos[1] + 100)) frame.Show() # install handler for key down events frame.Bind(wx.EVT_CHAR_HOOK, self.on_char_hook) # remove the temporary file if not config.debugging: name = os.path.join(preview_path, preview_module_name + ".py") if os.path.isfile(name): os.unlink(name) except Exception as inst: if config.debugging or config.testing: raise widget.preview_widget = None widget.properties["preview"].set_label(_('Show Preview')) bugdialog.Show(_("Generate Preview"), inst) return frame
def preview(self, widget, out_name=None): """Generate and instantiate preview widget. None will be returned in case of errors. The error details are written to the application log file.""" if out_name is None: import warnings warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, "application") try: out_name = os.tempnam(None, 'wxg') + '.py' except AttributeError: # XXX use a different name; e.g. the project file name with "_temp" out_name = "C:\\Users\\Dietmar\\wxg_tmp.py" widget_class_name = widget.klass # make a valid name for the class (this can be invalid for some sensible reasons...) widget_class = widget.klass[widget.klass.rfind('.') + 1:] widget_class = widget.klass[widget.klass.rfind(':') + 1:] # ALB 2003-11-08: always randomize the class name: this is to make preview work even when there are multiple # classes with the same name (which makes sense for XRC output...) widget_class = '_%d_%s' % (random.randrange(10**8, 10** 9), widget_class) widget.properties["class"].set(widget_class) self.real_output_path = self.output_path self.properties["output_path"].set(out_name) real_multiple_files = self.multiple_files real_language = self.language real_use_gettext = self.use_gettext self.properties["use_gettext"].set(False) self.properties["language"].set('python') self.properties["multiple_files"].set(False) overwrite = self.overwrite self.properties["overwrite"].set(False) frame = None try: self.generate_code(preview=True) # import generated preview module dynamically preview_path = os.path.dirname(self.output_path) preview_module_name = os.path.basename(self.output_path) preview_module_name = os.path.splitext(preview_module_name)[0] preview_module = plugins.import_module(preview_path, preview_module_name) if not preview_module: wx.MessageBox( _('Can not import the preview module from file \n"%s".\n' 'The details are written to the log file.\nIf you think this is a wxGlade bug, please ' 'report it.') % self.output_path, _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) return None try: preview_class = getattr(preview_module, widget.klass) except AttributeError: # module loade previously -> do a re-load XXX this is required for Python 3; check alternatives import importlib preview_module = importlib.reload(preview_module) preview_class = getattr(preview_module, widget.klass) if not preview_class: wx.MessageBox( _('No preview class "%s" found.\nThe details are written to the log file.\n' 'If you think this is a wxGlade bug, please report it.') % widget.klass, _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) return None if issubclass(preview_class, wx.MDIChildFrame): frame = wx.MDIParentFrame(None, -1, '') child = preview_class(frame, -1, '') child.SetTitle('<Preview> - ' + child.GetTitle()) w, h = child.GetSize() frame.SetClientSize((w + 20, h + 20)) elif not issubclass(preview_class, (wx.Frame, wx.Dialog)): # the toplevel class isn't really toplevel, add a frame... frame = wx.Frame(None, -1, widget_class_name) if issubclass(preview_class, wx.MenuBar): menubar = preview_class() frame.SetMenuBar(menubar) elif issubclass(preview_class, wx.ToolBar): toolbar = preview_class(frame, -1) frame.SetToolBar(toolbar) else: panel = preview_class(frame, -1) frame.Fit() else: frame = preview_class(None, -1, '') def on_close(event): frame.Destroy() widget.preview_widget = None widget.properties["preview"].set_label(_('Preview')) wx.EVT_CLOSE(frame, on_close) frame.SetTitle(_('<Preview> - %s') % frame.GetTitle()) # raise the frame frame.CenterOnScreen() frame.Show() # remove the temporary file (and the .pyc/.pyo ones too) for ext in ('', 'c', 'o', '~'): name = self.output_path + ext if os.path.isfile(name): os.unlink(name) except Exception as inst: widget.preview_widget = None widget.properties["preview"].set_label(_('Preview')) bugdialog.Show(_("Generate Preview"), inst) # restore app state widget.properties["class"].set(widget_class_name) self.properties["output_path"].set(self.real_output_path) del self.real_output_path self.properties["multiple_files"].set(real_multiple_files) self.properties["language"].set(real_language) self.properties["use_gettext"].set(real_use_gettext) self.properties["overwrite"].set(overwrite) return frame
def preview(self, widget, out_name=None): """\ Generate and instantiate preview widget. None will be returned in case of errors. The error details are written to the application log file. """ if out_name is None: import warnings warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, "application") out_name = os.tempnam(None, 'wxg') + '.py' widget_class_name = widget.klass # make a valid name for the class (this can be invalid for # some sensible reasons...) widget.klass = widget.klass[widget.klass.rfind('.') + 1:] widget.klass = widget.klass[widget.klass.rfind(':') + 1:] # ALB 2003-11-08: always randomize the class name: this is to make # preview work even when there are multiple classes with the same name # (which makes sense for XRC output...) widget.klass = '_%d_%s' % \ (random.randrange(10 ** 8, 10 ** 9), widget.klass) self.real_output_path = self.output_path self.output_path = out_name real_multiple_files = self.multiple_files real_language = self.language real_use_gettext = self.use_gettext self.use_gettext = False self.language = 'python' self.multiple_files = 0 overwrite = self.overwrite self.overwrite = 0 frame = None try: self.generate_code(preview=True) # import generated preview module dynamically preview_path = os.path.dirname(self.output_path) preview_module_name = os.path.basename(self.output_path) preview_module_name = os.path.splitext(preview_module_name)[0] preview_module = plugins.import_module(preview_path, preview_module_name) if not preview_module: wx.MessageBox( _('Can not import the preview module from file \n' '"%s".\n' 'The details are written to the log file.\n' 'If you think this is a wxGlade bug, please ' 'report it.') % self.output_path, _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) return None preview_class = getattr(preview_module, widget.klass) if not preview_class: wx.MessageBox( _('No preview class "%s" found.\n' 'The details are written to the log file.\n' 'If you think this is a wxGlade bug, please ' 'report it.') % widget.klass, _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION) return None if issubclass(preview_class, wx.MDIChildFrame): frame = wx.MDIParentFrame(None, -1, '') child = preview_class(frame, -1, '') child.SetTitle('<Preview> - ' + child.GetTitle()) w, h = child.GetSize() frame.SetClientSize((w + 20, h + 20)) elif not (issubclass(preview_class, wx.Frame) or issubclass(preview_class, wx.Dialog)): # the toplevel class isn't really toplevel, add a frame... frame = wx.Frame(None, -1, widget_class_name) if issubclass(preview_class, wx.MenuBar): menubar = preview_class() frame.SetMenuBar(menubar) elif issubclass(preview_class, wx.ToolBar): toolbar = preview_class(frame, -1) frame.SetToolBar(toolbar) else: panel = preview_class(frame, -1) frame.Fit() else: frame = preview_class(None, -1, '') def on_close(event): frame.Destroy() widget.preview_widget = None widget.preview_button.SetLabel(_('Preview')) wx.EVT_CLOSE(frame, on_close) frame.SetTitle(_('<Preview> - %s') % frame.GetTitle()) # raise the frame frame.CenterOnScreen() frame.Show() # remove the temporary file (and the .pyc/.pyo ones too) for ext in '', 'c', 'o', '~': name = self.output_path + ext if os.path.isfile(name): os.unlink(name) except Exception, inst: widget.preview_widget = None widget.preview_button.SetLabel(_('Preview')) bugdialog.Show(_("Generate Preview"), inst)
def preview(self, widget, out_name=[None]): if out_name[0] is None: import warnings warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, "application") out_name[0] = os.tempnam(None, 'wxg') + '.py' #print 'Temporary name:', out_name[0] widget_class_name = widget.klass # make a valid name for the class (this can be invalid for # some sensible reasons...) widget.klass = widget.klass[widget.klass.rfind('.')+1:] widget.klass = widget.klass[widget.klass.rfind(':')+1:] #if widget.klass == widget.base: # ALB 2003-11-08: always randomize the class name: this is to make # preview work even when there are multiple classes with the same name # (which makes sense for XRC output...) import random widget.klass = '_%d_%s' % \ (random.randrange(10**8, 10**9), widget.klass) self.real_output_path = self.output_path self.output_path = out_name[0] real_codegen_opt = self.codegen_opt real_language = self.language real_use_gettext = self.use_gettext self.use_gettext = False self.language = 'python' self.codegen_opt = 0 overwrite = self.overwrite self.overwrite = 0 frame = None try: self.generate_code(preview=True) # dynamically import the generated module FrameClass = misc.import_name(self.output_path, widget.klass) if issubclass(FrameClass, wx.MDIChildFrame): frame = wx.MDIParentFrame(None, -1, '') child = FrameClass(frame, -1, '') child.SetTitle('<Preview> - ' + child.GetTitle()) w, h = child.GetSize() frame.SetClientSize((w+20, h+20)) elif not (issubclass(FrameClass, wx.Frame) or issubclass(FrameClass, wx.Dialog)): # the toplevel class isn't really toplevel, add a frame... frame = wx.Frame(None, -1, widget_class_name) if issubclass(FrameClass, wx.MenuBar): menubar = FrameClass() frame.SetMenuBar(menubar) elif issubclass(FrameClass, wx.ToolBar): toolbar = FrameClass(frame, -1) frame.SetToolBar(toolbar) else: panel = FrameClass(frame, -1) frame.Fit() else: frame = FrameClass(None, -1, '') # make sure we don't get a modal dialog... s = frame.GetWindowStyleFlag() frame.SetWindowStyleFlag(s & ~wx.DIALOG_MODAL) def on_close(event): frame.Destroy() widget.preview_widget = None widget.preview_button.SetLabel(_('Preview')) wx.EVT_CLOSE(frame, on_close) frame.SetTitle(_('<Preview> - %s') % frame.GetTitle()) # raise the frame frame.CenterOnScreen() frame.Show() # remove the temporary file (and the .pyc/.pyo ones too) for ext in '', 'c', 'o', '~': name = self.output_path + ext if os.path.isfile(name): os.unlink(name) except Exception, e: #traceback.print_exc() widget.preview_widget = None widget.preview_button.SetLabel(_('Preview')) wx.MessageBox(_("Problem previewing gui: %s") % str(e), _("Error"), wx.OK|wx.CENTRE|wx.ICON_EXCLAMATION)#, self.notebook)
def preview(self, widget, position=None): """Generate and instantiate preview widget. None will be returned in case of errors. The error details are written to the application log file.""" # some checks #if compat.IS_PHOENIX: #found = common.app_tree.find_widgets_by_classnames(widget.node, "EditPropertyGridManager") #if found: #error = ("Preview with PropertyGridManager controls is currently deactivated as it causes crashes " #"with wxPython Phoenix") #wx.MessageBox( error, _('Error'), wx.OK | wx.CENTRE | wx.ICON_EXCLAMATION ) #return # XXX check other things as well, e.g. different bitmap sizes for BitmapButton preview_filename = self._get_preview_filename() if preview_filename is None: return widget_class_name = widget.klass # make a valid name for the class (this can be invalid for some sensible reasons...) widget_class = widget.klass[widget.klass.rfind('.') + 1:] widget_class = widget.klass[widget.klass.rfind(':') + 1:] # ALB 2003-11-08: always randomize the class name: this is to make preview work even when there are multiple # classes with the same name (which makes sense for XRC output...) widget_class = '_%d_%s' % (random.randrange(10**8, 10** 9), widget_class) widget.properties["class"].set(widget_class) if wx.Platform == "__WXMAC__" and not compat.PYTHON2: # workaround for Mac OS testing: sometimes the caches need to be invalidated import importlib importlib.invalidate_caches() frame = None try: self.generate_code(True, preview_filename, widget) # import generated preview module dynamically preview_path = os.path.dirname(preview_filename) preview_module_name = os.path.basename(preview_filename) preview_module_name = os.path.splitext(preview_module_name)[0] preview_module = plugins.import_module(preview_path, preview_module_name) if not preview_module: misc.error_message( _('Can not import the preview module from file \n"%s".\n' 'The details are written to the log file.\n' 'If you think this is a wxGlade bug, please report it.') % self.output_path) return None try: preview_class = getattr(preview_module, widget.klass) except AttributeError: # module loade previously -> do a re-load XXX this is required for Python 3; check alternatives import importlib preview_module = importlib.reload(preview_module) preview_class = getattr(preview_module, widget.klass) if not preview_class: misc.error_message( _('No preview class "%s" found.\nThe details are written to the log file.\n' 'If you think this is a wxGlade bug, please report it.') % widget.klass) return None if issubclass(preview_class, wx.MDIChildFrame): frame = wx.MDIParentFrame(None, -1, '') frame.SetMenuBar(wx.MenuBar()) # avoid assertion error child = preview_class(frame, -1, '') child.SetTitle('<Preview> - ' + child.GetTitle()) w, h = child.GetSize() frame.SetClientSize((w + 20, h + 20)) elif not issubclass(preview_class, (wx.Frame, wx.Dialog)): # the toplevel class isn't really toplevel, add a frame... frame = wx.Frame(None, -1, widget_class_name) if issubclass(preview_class, wx.MenuBar): menubar = preview_class() frame.SetMenuBar(menubar) panel = wx.Panel(frame) elif issubclass(preview_class, wx.ToolBar): toolbar = preview_class(frame, -1) frame.SetToolBar(toolbar) panel = wx.Panel(frame) frame.SetMinSize(toolbar.GetBestSize()) frame.Fit() else: panel = preview_class(frame, -1) frame.Fit() else: frame = preview_class(None, -1, '') def on_close(event): frame.Unbind(wx.EVT_CHAR_HOOK) compat.DestroyLater(frame) widget.preview_widget = None widget.properties["preview"].set_label(_('Show Preview')) frame.Bind(wx.EVT_CLOSE, on_close) frame.SetTitle(_('<Preview> - %s') % frame.GetTitle()) # raise the frame if position: frame.SetPosition(position) else: frame.CenterOnScreen() if widget.widget: # avoid Design and Preview window at the same position pos = widget.widget.GetPosition() if frame.GetPosition() == pos: frame.SetPosition((pos[0] + 200, pos[1] + 100)) frame.Show() # install handler for key down events frame.Bind(wx.EVT_CHAR_HOOK, self.on_char_hook) # remove the temporary file if not config.debugging: name = os.path.join(preview_path, preview_module_name + ".py") if os.path.isfile(name): os.unlink(name) except Exception as inst: if config.debugging or config.testing: raise widget.preview_widget = None widget.properties["preview"].set_label(_('Show Preview')) bugdialog.Show(_("Generate Preview"), inst) # XXX restore app state widget.properties["class"].set(widget_class_name) return frame
def test_mdiParentFrame1(self): f = wx.MDIParentFrame(None, title="MDI Parent") f.Close()
def test_mdiChildFrame2(self): f = wx.MDIParentFrame(None, title="MDI Parent") f.SetMenuBar(wx.MenuBar()) c = wx.MDIChildFrame() c.Create(f, title="MDI Child") f.Close()
def test_mdiClientWindow(self): f = wx.MDIParentFrame(None, title="MDI Parent") cw = f.GetClientWindow() self.assertTrue(isinstance(cw, wx.MDIClientWindow)) f.Close()
def __init__ (self, master): self.this = wx.MDIParentFrame (master.win, size=(300,120)) self.this.Show () self.master = master