Python GTK (Glade) Notebook - python

I'm currently developing a small application in Python with the use of GTK+ (and Glade). Everything has been fairly simple to integrate so far, until I came up with the idea to add tabs instead of pop-ups. Note: Still using Python 2.7+
Is there any easy way to implement already existing pages inside a new tab(notebook) like structure? I'm having difficulties to find how to add content per separate tab created in glade.
Perhabs a more 'clear' question: What Notebook function will be required to call a specific V/HBox with every different tab? The current structure looks like (minus Menu / statusbar):
[ mainWindow ] --> (1) mainOverview (gtkVbox) --> (2A) mainContent (gtkHbox) ... other non-related content
The structure I was hoping for would look like:
[ mainWindow ] --> (1) mainOverview --> (2) noteBook --> (3) Tab1 --> (4) mainContent (gtkHbox) -- (3) Tab2 --> (4) secondaryContent (gtkHbox)
The application itself works fine (multithreaded, fully functioning) without the tabs, the mainContent(gtkHbox) contains a file/recursive directory analyzer, a few checkboxes and a general overview. I was hoping for an easy way to display this main window (the gtkHbox) ONLY when having Tab1 selected.
Having difficulties to find good reference pages that display a proper way to call content pages per notebook tab. Any reference-pages or useful links are very much appreciated! Thanks so far! My apologies if this is a rather newbish question, I'm not new to Python coding, but interfaces on the other hand... ;)

Not an answer, but it looks like "another.anon.coward" already answered this in a comment...
If you double click on the tab, then that page is selected for adding content in glade. You can go ahead and add content for that page. As for switching you can use set_current_page to switch to page whose content you want to display. Register for "switch-page" signal to find out which page has been switched to.

click on the notebook widget on the widget explorer(object inspector) on the left of glade. Then use your left and right keyboard arrow keys to move from tab to tab. You can also double click on the label of the tab as pyrotherm has said in his answer. But if you want to do it programatically get the notebook object from the ui using the get_object method of Gtk.builder class. Then do this to add a page
builder = Gtk.Builder()
builder.add_from_file("example.glade")
self.notebook = builder.get_object("notebook1") # set the id of the notebook in glade
self.page1 = Gtk.Box()
self.page1.add(Gtk.Label(label="Default Page!"))
self.notebook.append_page(self.page1, Gtk.Label(label="Plain Title"))
Now add the content you want to it. Now on to signals. Pyrotherm has already answered it. though there is no signal named switch-page. its named switch_page. You can look at the list of signals of notebook here

Related

pywinauto ribbon menu returns no control identifiers

I'm trying to automate a series of tasks I have to do with a given software. I've managed to "wing it" using keyboard controls, but to extend the complexity of the script I need to access a ribbon menu.
So far, my code is as follows:
windows = pwa.Desktop(backend="win32").windows()
running_windows = [window.window_text() for window in windows]
midas_title = ""
target_title = "Civil"
for window in running_windows:
if target_title in window:
midas_title += window
else:
pass
app = pwa.Application().connect(title=midas_title)
app[midas_title].set_focus()
app.MidasGenMainFrmClass['MIDAS/Civil'].print_control_identifiers()
app.MidasGenMainFrmClass['BCGPRibbonBar:40000000:8:10003:10'].print_control_identifiers()
Judging by the top/left and bottom/right coordinates of the BCGPRibbonBar:40000000:8:10003:10, that seems to be the menu that I want to access so that I can click on the "Results" button in this ribbon (my final goal), but when I do print_control_identifiers() on that the output I get is this:
BCGPRibbonBar:40000000:8:10003:10 - 'MIDAS/Civil' (L0, T0, R1920, B174)
['MIDAS/CivilBCGPRibbonBar:40000000:8:10003:10', 'BCGPRibbonBar:40000000:8:10003:10', 'MIDAS/Civil']
child_window(title="MIDAS/Civil", class_name="BCGPRibbonBar:40000000:8:10003:10")
I'm very new to this, but seems like the ribbon has no children?
Seems like I'm too new to embed images, but link here to what the ribbon menu looks like
And finally, link to the image of the inspector of the "Results" menu where I'd like to click
Hopefully this is sufficient information, but please let me know if anything is missing.
If anyone has any idea of what I might be doing wrong, that would be extremely helpful.
Use backend="uia" instead of backend="win32". Ribbon controls are visible to UIA backend only. Application(backend="uia") is also a must.

How to modify panels individually in a wxPython wizard?

I am quite new to wxPython and want to build a wizzard. I used this guide as a base ("wxPython: How to Create a Generic Wizard"). I tried to add some widgets the panel, e.g. some radio buttons at the second page by inserting the following code at line 56 in add_page():
if(title=="Page 2"):
k1=wx.RadioButton(panel,-1,'Argument1',(35,60),(150,20), style = wx.RB_GROUP)
k2=wx.RadioButton(panel,-1,'Argument2',(35,80),(150,20))
But as soon as I try to add some sizer to the the second panel, all pages are affected. I tried quite a few variations of where to place the sizers, but without success. So my question is: is this the appropriate place to modify the individual pages and could someone give me a hint of how to write a minimalistic example of e.g inserting a boxSizer and a button in the first page and a boxSizer and a RadioButton in the second page?

Search text and scroll down with qwebview

I'm using Qwebview with Pyside/Qt to view an HTML page on a GUI I'm working on.
I need the possibility to add a search text function, otherwise it is useless for the purpose the GUI is made.
I've searched but I didn't find anything useful for build a code that search the text and scrolls down the page as it is made in the common browsers.
The only function I found is findText but it returns a boolean and I cannot see how it can be useful.
Do somebody have an hint / advice / guide or code for this request?
Thank you.
Okay, so it turns out that i had an example of this using a QTextBrowser, which has a lot of this built into utility functions.
You can still do it with a QWebBrowser though.
Bind ctrl-f to open a search panel, and then make it so that the search box sends out two signals;
(presuming it's a QLineEdit), returnPressed, and textChanged.
Each of them then calls findText on the QWebPage object.
The important part is setting the correct flag in the findText call (which you'll want to set with checkboxes in your search functionality, i'd say).
You set the flags so that HighlightAllOccurrences is not set.
I cannot see any way to get details on a selection. Are you sure that when you do not set the HighlightAllOccurences flag it does not scroll to the next selection automatically?

wxPython non-focussed context menu

I have been able to create normal popup menus (such as context ones) using self.PopupMenu(menu, pos) and constructing a menu however one issue I run in to is that whenever I pop it up (say when I change the text in a text box ala search such as in Google Suggestions or iTunes) it will change the focus to the context menu. This seems to be built into the PopupMenu system, is there a way to show a menu but not give it focus.
Examples
Similar to (but not exactly) SuperTooltip in wxPython Demo
What these are (but in wxPython) https://developer.apple.com/library/mac/documentation/userexperience/conceptual/applehiguidelines/Windows/Windows.html#//apple_ref/doc/uid/20000961-SW4
Right now it looks like I just should create it out of a dialog with no title etc.
iTunes
Google Search
It sounds like you want an autocomplete window. There's an article on this topic on the wxPython wiki here:
http://wiki.wxpython.org/TextCtrlAutoComplete
You might also find this article helpful:
http://megamicrobase.wordpress.com/2009/01/16/adventures-in-wxpython-autocompleting/
Or perhaps this thread:
https://groups.google.com/forum/#!topic/wxpython-users/tgQcNj0b1kY

How to make an editor using markdowns with Qt4 and Python?

I'd like to make a small desktop editor to take notes, that uses markdowns to format text quickly. The application should transcribe markdowns instantaneously or after clicking on a button.
For this I'd like to use Qt4 and Python.
What, in your opinion, is the most efficient way to proceed?
In the case the rich text is rendered after pressing a button, I suppose I could use QTextEdit widget for the edit-mode, but what to use to display the rich text? I want this to look good. Should I render the text in HTML? Or something else?
Please advise.
You can look at how ReText has done it. Maybe even ReText is the app you want to code :-)
I came here because I'm looking for a solution for the same task.
Here is what I would (or hopefully will) try:
Subclass QTextEdit, which can display both plain and rich text.
supply two string properties, one containing Markdown source, the other generated HTML.
For entering "edit mode" (however your UI will handle this)
self.setText(self.markdown)
self.setReadOnly(False)
For leaving "edit mode":
self.markdown = self.toPlainText()
self.toHtml() # convert self.markdown to self.html
# don't know yet how to achieve that
self.setHtml(self.html)
self.setReadOnly(True)
For displaying the HTML one can use a CSS stylesheet.
As UI interface I could imagine: clicking on the readonly display mode switches to edit mode, [Ctrl]-[Enter] triggers HTML generation.

Categories

Resources