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()
Related
According to the docs, dialogs created in wxPython and shown with ShowModal should handle the escape (ESC) key by searching for a button with ID_CANCEL and simulating a click (i.e. triggering its EVT_BUTTON event).
This was working in all but one of my dialogs. After a lot of debugging, I discovered that the cancel button - or any other button! - should have focus. In other words, as long as I call .SetFocus() on one of the buttons I create, the ESC key works fine.
Does anybody know what's going on here? Do dialogs displayed with ShowModal() not automatically get focus? Should they? Or am I misunderstanding something?
In the example code below, uncomment the line b.SetFocus() to see the difference:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent):
super(MainWindow, self).__init__(parent)
self.Show()
d = SomeDialog(self)
d.ShowModal()
self.Destroy()
class SomeDialog(wx.Dialog):
def __init__(self, parent):
super(SomeDialog, self).__init__(parent)
button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
button.Bind(wx.EVT_BUTTON, self.action_cancel)
#button.SetFocus()
def action_cancel(self, e):
self.EndModal(wx.ID_CANCEL)
if __name__ == '__main__':
app = wx.App(False)
frame = MainWindow(None)
app.MainLoop()
Update: This happens when running on linux (Fedora 20, Gnome)
You can call the dialog's SetFocus() method to set focus on itself:
import wx
class MainWindow(wx.Frame):
def __init__(self, parent):
super(MainWindow, self).__init__(parent)
self.Show()
d = SomeDialog(self)
d.ShowModal()
self.Destroy()
class SomeDialog(wx.Dialog):
def __init__(self, parent):
super(SomeDialog, self).__init__(parent)
button = wx.Button(self, wx.ID_CANCEL, 'Cancel')
button.Bind(wx.EVT_BUTTON, self.action_cancel)
self.SetFocus()
def action_cancel(self, e):
self.EndModal(wx.ID_CANCEL)
if __name__ == '__main__':
app = wx.App(False)
frame = MainWindow(None)
app.MainLoop()
This works on Kubuntu 14.04 with wxPython 2.8.12.1 and Python 2.7.6. However, I suspect that when you set focus to the dialog, it is probably passing the focus to its first child just as a wx.Panel will do. I don't know why Linux is behaving in this manner, but I would agree with #nepix32 and #VZ that this should work without the SetFocus(). You can call it anyway as a workaround, but you should probably report it as a bug. There's a link on the wxPython website where you can submit your bug report.
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()
I'm trying to test out the wx.Notebook tabs in one of my guis. However, I've got a problem where only a tiny portion of the tab shows in the top left corner.
As you can see, only a very small part of it is showing. I can't figure out what wrong.
My code is as follows:
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "test", size=(640,480))
panel = wx.Panel(self)
notebook = wx.Notebook(panel, style=wx.BK_DEFAULT, size=(640,480))
tabOne = wx.Panel(notebook)
notebook.AddPage(tabOne, "Tab One")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, flag=wx.EXPAND)
self.SetSizer(sizer)
if __name__ == '__main__':
app = wx.PySimpleApp(redirect=False)
frame = MyFrame(parent=None, id=-1)
frame.Show()
app.MainLoop()
Anyone know what would cause such a thing?
You have to fix one line:
notebook = wx.Notebook(self, style=wx.BK_DEFAULT, size=(640,480))
Formerly you created the notebook as child of panel which hasn't any sizer set. Hence the small size. panel is now obsolete.
I am building a Python program that searches things on a remote website.
Sometimes the operation takes many seconds and I believe that the user will not notice the status bar message "Search Operation in progress".
Therefore, I would like to change the mouse cursor to highlight that the program is still waiting for a result.
This is the method I am using:
def OnButtonSearchClick( self, event ):
"""
If there is text in the search text, launch a SearchOperation.
"""
searched_value = self.m_search_text.GetValue()
if not searched_value:
return
# clean eventual previous results
self.EnableButtons(False)
self.CleanSearchResults()
operations.SearchOperation(self.m_frame, searched_value)
I tried two different approaches, both before the last line:
wx.BeginBusyCursor()
self.m_frame.SetCursor(wx.StockCursor(wx.CURSOR_WAIT))
None of them are working.
I am using KDE under GNU/Linux. This does not work under Gnome, too
Any hints? Thank you
I asked Robin Dunn, the maker of wxPython about this, and it looks like this should work, but doesn't. However, if you call the panel's SetCursor(), it DOES work or so I'm told. Here's an example you can try:
import wx
########################################################################
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
# Add a self.panel so it looks the correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
btn = wx.Button(self.panel, label="Change Cursor")
btn.Bind(wx.EVT_BUTTON, self.changeCursor)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(btn)
self.panel.SetSizer(sizer)
#----------------------------------------------------------------------
def changeCursor(self, event):
""""""
myCursor= wx.StockCursor(wx.CURSOR_WAIT)
self.panel.SetCursor(myCursor)
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
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.