我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用wx.GA_HORIZONTAL。
def __init__( self, parent ): wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = 'ImagePy', size = wx.Size(-1,-1), pos = wx.DefaultPosition, style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) logopath = os.path.join(root_dir, 'data/logo.ico') #self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_3DLIGHT ) ) self.SetIcon(wx.Icon(logopath, wx.BITMAP_TYPE_ICO)) self.SetSizeHints( wx.Size( 600,-1 ), wx.DefaultSize ) IPy.curapp = self # Todo:Fixed absolute/relative path! # print("menuspath:{}".format( os.path.join(root_dir,"menus"))) # print("toolspath:{}".format(os.path.join(root_dir,"tools")) # menuspath = os.path.join(root_dir, "menus") # toolspath = os.path.join(root_dir,"tools") self.menubar = pluginloader.buildMenuBarByPath(self, 'menus') self.SetMenuBar( self.menubar ) self.shortcut = pluginloader.buildShortcut(self) self.SetAcceleratorTable(self.shortcut) sizer = wx.BoxSizer(wx.VERTICAL) self.toolbar = toolsloader.build_tools(self, 'tools') #self.toolbar.Realize() #sizertool.Add(self.toolbar, 1, 0, 5 ) #sizertool.Add(self.morebar, 0, 0, 5) sizer.Add(self.toolbar, 0, wx.EXPAND, 5 ) #sizer.AddSpacer( ( 0, 0), 1, wx.EXPAND, 5 ) self.line_color = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL ) #self.line_color.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_HIGHLIGHT ) ) sizer.AddStretchSpacer(prop=1) sizer.Add(self.line_color, 0, wx.EXPAND |wx.ALL, 0 ) stapanel = wx.Panel( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL ) sizersta = wx.BoxSizer( wx.HORIZONTAL ) self.txt_info = wx.StaticText( stapanel, wx.ID_ANY, "ImagePy v0.2", wx.DefaultPosition, wx.DefaultSize, 0 ) self.txt_info.Wrap( -1 ) #self.txt_info.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_INFOBK ) ) sizersta.Add( self.txt_info, 1, wx.ALIGN_BOTTOM|wx.BOTTOM|wx.LEFT|wx.RIGHT, 2 ) self.pro_bar = wx.Gauge( stapanel, wx.ID_ANY, 100, wx.DefaultPosition, wx.Size( 100,15 ), wx.GA_HORIZONTAL ) sizersta.Add( self.pro_bar, 0, wx.ALIGN_BOTTOM|wx.BOTTOM|wx.LEFT|wx.RIGHT, 2 ) stapanel.SetSizer(sizersta) stapanel.SetDropTarget(FileDrop()) sizer.Add(stapanel, 0, wx.EXPAND, 5 ) self.SetSizer( sizer ) self.Centre( wx.BOTH ) self.Layout() self.Fit() self.update = False self.Bind(wx.EVT_CLOSE, self.on_close) thread = threading.Thread(None, self.hold, ()) thread.setDaemon(True) thread.start()
def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"Background Task", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.gauge = wx.Gauge(self, wx.ID_ANY, 10 ** 3, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL) self.gauge.SetValue(0) gb_sizer.Add(self.gauge, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) self.button = wx.Button(self, wx.ID_ANY, u"Run", wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.button, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) gb_sizer.AddGrowableCol(0) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH) # Connect Events self.button.Bind(wx.EVT_BUTTON, self.on_run) self.model = WatchableDict() self.model["complete"] = 0 pywatch.wx.ValueWatcher(self.gauge, self.model, "complete") # Virtual event handlers, overide them in your derived class
def __init__(self, parent): wx.Frame.__init__(self, parent, title=u"Addition Frame") self.model = WatchableDict() self.model["a"] = 2 self.model["b"] = 3 self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) self.spin_ctrl_a = wx.SpinCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 10, 0) gb_sizer.Add(self.spin_ctrl_a, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 5) pywatch.wx.ValueChanger(self.spin_ctrl_a, self.model, "a") self.static_text = wx.StaticText(self, wx.ID_ANY, u"+", wx.DefaultPosition, wx.DefaultSize, 0) self.static_text.Wrap(-1) gb_sizer.Add(self.static_text, wx.GBPosition(0, 1), wx.GBSpan(1, 1), wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5) self.spin_ctrl_b = wx.SpinCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.SP_ARROW_KEYS, 0, 10, 0) gb_sizer.Add(self.spin_ctrl_b, wx.GBPosition(0, 2), wx.GBSpan(1, 1), wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, 0) pywatch.wx.ValueChanger(self.spin_ctrl_b, self.model, "b") self.static_text_out = wx.StaticText(self, wx.ID_ANY, u"{}", wx.DefaultPosition, wx.DefaultSize, 0) self.static_text_out.Wrap(-1) gb_sizer.Add(self.static_text_out, wx.GBPosition(1, 0), wx.GBSpan(1, 3), wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL, 5) pywatch.wx.LabelWatcher(self.static_text_out, self.model, ("a", "b", lambda: self.model["a"] + self.model["b"])) self.gauge = wx.Gauge(self, wx.ID_ANY, 20, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL) self.gauge.SetValue(0) gb_sizer.Add(self.gauge, wx.GBPosition(2, 0), wx.GBSpan(1, 3), wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER_HORIZONTAL, 0) pywatch.wx.ValueWatcher(self.gauge, self.model, ("a", "b", lambda: self.model["a"] + self.model["b"])) gb_sizer.AddGrowableCol(0) gb_sizer.AddGrowableCol(2) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH)