python - How can I initialize wx.Font objects before the wx.App is created? -


In my application there is a module called gui_constants which contains all the fonts and colors definitions of my application For example, there can be a line in gui_constants.py

  heading_font = wx.Font (12, wx.SWISS, wx.NORMAL, wx.BOLD) , Face =  

and

  heading_label = wx.StaticText (self, label = 'Lorem Ipsum') can be called heading_label.SetFont (gui_constants). Heading_font)  

The problem is that my gui_constants module is being imported before that wx.App is created Has, which is the exception:

  Traceback (most recent call last): File "./main.py", line 3, & lt; Module & gt; NewGuiApp file from New_gui_app Import "... / application / new_gui_app.py", line 3, & lt; Module & gt; The main menu file from the ideas "... / application / view / __init__.py", in line 1, in & lt; Module & gt; "... / App / View / Banner Use" from the banner import banner file, line 3, & lt; Module & gt; Import gui_constants file "... / application / gui_constants.py", line 63, & lt; Module & gt; Heading_font = wx.Font (12, wx.SWISS, wx.NORMAL, wx.BOLD, face = 'lucida grande') file "/usr/local/lib/python2.7/site-packages/wx-2.9.5- Oxx_cocoa /wx/_gdi.py ", line 2156, __init__ _gdi_.Font_swiginit (in self, _gdi_new_font (* args, ** kwargs) wx._core.PyNoAppError: wx.App object must be created first!  

Can anybody suggest a way to keep these models "continuous" announcements, while they can be prevented from getting started before wx.App Is made?

You have a few options to do this is a very easy way to do that the constant to the wx.font object Instead of changing to Tulips:

  heading_font = (12, wx.SWISS, wx.NORMAL, wx.BOLD, 'lucidagrande')  

then When you import it, you can do something like this:

  # ------------- ----------- --------------------------------------- ------- def create_font (data ): "Size, family, style, weight, face = data font = wx.Font (size, family, style, weight, face = face) Font font ################################################ ####################### Class MyPanel (wx.Panel): "" "" "" ##### - ------------------------------------------------- - ------- def __init __ (self, parent): "" "constructor" "" wx.panel .__ init __ (self, guardian) print type (gui_constants.heading_font) print create_font (gui_constants.heading_font )  

An option you can try is using eval of Python if you do this in this way, then you can weld your constant Want to store in the form, such as:

  heading_font = "wx.font (12, w) X.SWISS, wx.NORMAL, wx.BOLD, face = 'lucida gerende') " 

Then in your wxPython code, you want to do something like this:

  ############################################## ######################### Category MyPanel (wx.Panel): "" "" "" ### ---------- ---------------------------------------- ---------- DIGIT __INIT__ (self, parent): "" "constructor" "" wx.panel.__ init __ (self, guardian) print type (eval (gui_constants.heading_font)) < / Code> 

Note that eval is a minor threat that if the user has permission to modify the gui_constants file, then Sector can insert malicious code. If they can not modify it, then there is no more danger.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -