On Windows 7 64-bit, using Python 2.7.3 and wx version 2.8.12.1.
I'm trying to get a wx.Frame styled as wx.SIMPLE_BORDER or wx.NO_BORDER to have a shadow like other windows, like this:
Drop Shadow
Unfortunately, this seems to be a part of the wx.RESIZE_BORDER style. Here is what happens without that:
No Shadow
So, I went to Googling and found this ArtManager class in the wx.lib.agw.artmanager module, which had a DropShadow function, claiming that it "Adds a shadow under the window (Windows Only)."
But, it didn't seem to do anything. No errors, but no results. Perhaps it doesn't work on Windows 7, but I'm hoping you have a better answer. Of course, I'd be open to other methods of creating a shadow, but this is the one I had found.
Here's my code:
import wx
import wx.lib.agw.artmanager
class main(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, style=wx.SIMPLE_BORDER, size=(469, 400))
am = wx.lib.agw.artmanager.ArtManager()
self.Center()
self.Show()
am.DropShadow(self, True)
class app(wx.App):
def OnInit(self):
frame = main(None, -1)
frame.Show(True)
return True
app = app()
app.MainLoop()
Related
I am following this example https://github.com/cztomczak/cefpython/blob/master/examples/wxpython.py for cefpython3 and wxpython. However I am looking to disable the windows border so the program can no longer be adjusted size wise and their is no title bar. But I would like to keep it so the program can be moved around the screen. I have done some research but not come across a way to successfully do this.
The following appears to do the job on Linux.
Your mileage may vary.
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", size=(360,100)):
super(MyFrame, self).__init__(parent, id, title, size, style = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX))
self.panel = wx.Panel(self)
self.panel.SetBackgroundColour('palegreen')
self.Show()
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None,title="Non-Resizeable Frame")
app.MainLoop()
I am designing a windows utility software for Windows 7 coded in Python with Wxpython for GUI works.I dont want to open my software if it is already opened.
I want a function like this if user opens that software a message box is to be displayed on windows screen showing that "Your application is already running".
Plz help.
Thanks in advance...
There's already existing wxPython facility that implements wanted logic, called wx.SingleInstanceChecker. Here's and example of code (shamelessly borrowed from wxPython wiki):
import wx
class SingleAppFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(300, 300))
self.Centre()
class SingleApp(wx.App):
def OnInit(self):
self.name = "SingleApp-%s" % wx.GetUserId()
self.instance = wx.SingleInstanceChecker(self.name)
if self.instance.IsAnotherRunning():
wx.MessageBox("Another instance is running", "ERROR")
return False
frame = SingleAppFrame(None, "SingleApp")
frame.Show()
return True
app = SingleApp(redirect=False)
app.MainLoop()
This cannonical example (for a matter of luck) makes exatly what you've asked.
In the following sample program I can't seem to get the notebook control to use the styles I tell it to use. Despite the FNB_HIDE_ON_SINGLE_TAB, FNB_NO_NAV_BUTTONS and FNB_X_ON_TABS styles I still see the navigation buttons and a single tab with no close button. It's the same for all styles I've tried, they're all completely ignored.
I'm running this on Ubuntu 11.10, python 2.7.2 and wxPython 2.8.11 if it matters
import wx
import wx.lib.flatnotebook as FNB
class TabCtrl(FNB.FlatNotebook):
def __init__(self, parent):
windowstyle = FNB.FNB_HIDE_ON_SINGLE_TAB|FNB.FNB_NO_NAV_BUTTONS|FNB.FNB_X_ON_TAB
super(TabCtrl, self).__init__(parent, style=windowstyle)
self.pages = []
self.pages.append(wx.Panel(self))
self.AddPage(self.pages[0], 'Test')
class MainFrame(wx.Frame):
def __init__(self, *args, **kwargs):
super(MainFrame, self).__init__(*args, **kwargs)
self.panel = wx.Panel(self)
self.tabs = TabCtrl(self.panel)
sizer = wx.GridBagSizer(vgap=8, hgap=8)
sizer.Add(self.tabs, (0, 0), (10, 30), wx.EXPAND)
sizer.AddGrowableCol(29)
sizer.AddGrowableRow(9)
self.panel.SetSizer(sizer)
self.panel.Fit()
self.SetInitialSize()
class App(wx.App):
def __init__(self, *args, **kwargs):
super(App, self).__init__(*args, **kwargs)
self.frame = MainFrame(None, title='Test')
self.frame.Show()
app = App()
app.MainLoop()
FNB_NO_NAV_BUTTONS and FNB_X_ON_TABS both work on my machine (using the wxPython demo) using wxPython 2.8.12, Windows 7, Python 2.6. When it comes to anything in the AGW widget set, I highly recommend downloading the latest version from SVN. I know the author of that library and he's always updating it and fixing bugs, so updating to the latest in SVN is usually worth it.
EDIT: I was looking at this again and I think you're putting at least some of those flags in on the wrong parameter. There's an "agwStyle" argument in FlatNotebook too and I'm thinking that's where some or all of those FlatNotebook-related flags should be applied to:
super(TabCtrl, self).__init__(parent, agwStyle=windowstyle)
It may be a bug. I have tried various ways to change the style without being successful. Even example located on wxPyWiki does not work for me when it comes to changing the styles.
I would consider asking about it on wxPython-users mailing list.
Is there anyway to disable a notebook tab? Like you can with the Widgets themselves? I have a long process I kick off, and while it should be pretty self-explanatory for those looking at it, I want to be able to prevent the user from mucking around in other tabs until the process it is running is complete.
I couldn't seem to find anything in wx.Notebook to help with this?
Code snippet:
def __init__(self, parent):
wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style=wx.BK_DEFAULT)
self.AddPage(launchTab.LaunchPanel(self), "Launch")
self.AddPage(scanTab.ScanPanel(self), "Scan")
self.AddPage(extractTab.ExtractPanel(self), "Extract")
self.AddPage(virtualsTab.VirtualsPanel(self), "Virtuals")
It si not doable with wx.Notebook. But you can use some of the more advanced widgets such as wx.lib.agw.aui.AuiNotebook:
import wx
import wx.lib.agw.aui as aui
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
style = aui.AUI_NB_DEFAULT_STYLE ^ aui.AUI_NB_CLOSE_ON_ACTIVE_TAB
self.notebook = aui.AuiNotebook(self, agwStyle=style)
self.panel1 = wx.Panel(self.notebook)
self.panel2 = wx.Panel(self.notebook)
self.panel3 = wx.Panel(self.notebook)
self.notebook.AddPage(self.panel1, "First")
self.notebook.AddPage(self.panel2, "Second")
self.notebook.AddPage(self.panel3, "Third")
self.notebook.EnableTab(1, False)
self.Show()
app = wx.App(False)
win = MainWindow(None)
app.MainLoop()
Technically, wx.Notebook doesn't have a way to disable a tab. However, you can do the same thing by checking which tab is clicked on and if it is "disabled", veto the EVT_NOTEBOOK_PAGE_CHANGING or EVT_NOTEBOOK_PAGE_CHANGED event. Alternately, you can use the AUI notebook as mentioned above. Note that that is the one from the agw lib, NOT from the wx.aui one. The FlatNotebook also provides the ability to disable tabs. See the wxPython demo for an example.
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
p = wx.Panel(self)
self.nb = wx.Notebook(p)
......
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
def OnPageChanged(self, event):
if wx.IsBusy():
self.Unbind(wx.EVT_NOTEBOOK_PAGE_CHANGED)
self.nb.SetSelection(event.GetOldSelection())
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
The active tab can be set by Notebook.SetSelection(). But the event should be unbinded/disable and bind/enable around it to avoid in infinite looping. There should be wx.BeginBusyCursor(), wx.EndBusyCursor() in panel codes. Then The tab changing is "disabled" when app is busy.
I am currently using wx.CustomTree, to use to display a series of configuration settings. I generally fill them with wx.TextCtrl / wx.Combobox, to allow the user to edit / enter stuff. Here is my code:
class ConfigTree(CT.CustomTreeCtrl):
"""
Holds all non gui drawing panel stuff
"""
def __init__(self, parent):
CT.CustomTreeCtrl.__init__(self, parent,
id = common.ID_CONTROL_SETTINGS,
style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_BUTTONS
| wx.TR_HAS_VARIABLE_ROW_HEIGHT | wx.TR_SINGLE)
#self.HideWindows()
#self.RefreshSubtree(self.root)
self.population_size_ctrl = None
self.SetSizeHints(350, common.FRAME_SIZE[1])
self.root = self.AddRoot("Configuration Settings")
child = self.AppendItem(self.root, "Foo", wnd=wx.TextCtrl(self, wx.ID_ANY, "Lots Of Muffins"))
The problem is, any children nodes, the data for these nodes is not filled in. When i basically expand the configuration settings tree node. I see the "Foo" node, however the textbox is empty. This is the same for both text node, Until i actually click on the child node. I've looked tried every form of update / etc. Does anyone have any ideas?
To: Anurag Uniyal
Firstly sorry for not giving the rest of the code. I've gotten around this problem by simply resizing the window everytime i demo the application.
So i tried the code on my Macbook Pro running Mac OS X, with newest wx and python 2.6. I still have the same problem, however i noticed resizing the window, or even touching the scrollbar fixes the issue.
I also noticed however, there is absolutely NO problems running on Windows Vista / Windows 7.
So trying this on another macbook running an older version of wx + python. Results in the same problem :(
Is there anyway to force the panel to redraw it self? Which i am pretty sure happens when i resize the window.
If you don't have any ideas then i'll strip it down and make a demo example, im home and won't be at work until later tommorow.
You can use RefreshItems if you are using virtual controls, or you could refresh the panel, which would update the contents of all the children windows (widgets).
I tested it on window with wx version 2.8.10.1 and it works, which OS and wx version you are using?
here is self contained code, which can be copy-pasted and run
import wx
import wx.lib.customtreectrl as CT
class ConfigTree(CT.CustomTreeCtrl):
"""
Holds all non gui drawing panel stuff
"""
def __init__(self, parent):
CT.CustomTreeCtrl.__init__(self, parent,
id = -1,
style = wx.TR_DEFAULT_STYLE | wx.TR_HAS_BUTTONS
| wx.TR_HAS_VARIABLE_ROW_HEIGHT | wx.TR_SINGLE)
self.population_size_ctrl = None
self.SetSizeHints(350, 350)
self.root = self.AddRoot("Configuration Settings")
child = self.AppendItem(self.root, "Foo", wnd=wx.TextCtrl(self, wx.ID_ANY, "Lots Of Muffins"))
def main():
app = wx.App()
frame = wx.Frame(None, title="Test tree", size=(500,500))
p = wx.Panel(frame, size=(500,500))
tree = ConfigTree(p)
tree.SetSize((500,500))
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()