I want to get the process id of the currently active tab in browsers. I know all browsers doesn't create a different process for each tab but chrome and edge do so. Just like in browser task manager we can see different PID of each tab.
Below code can give me the title of tabs in browser. But it gives a common handle and common id to all tabs which I think is the id of the main browser. If two tabs have same title how will I differentiate between them?
PS - Any unique id assigned to each tab can be helpful like process-id, session-id or anything else.
time.sleep(3)
i = 0
while i < 1:
hwnd = win32gui.GetForegroundWindow()
pid = win32process.GetWindowThreadProcessId(hwnd)
title = win32gui.GetWindowText(hwnd)
print(" handle : {} title: {}".format(hwnd,title))
processinfo([pid[-1]])
pr = psutil.Process(pid[-1])
children = pr.children()
for child in children:
print("Child id: {} name : {} exe: {}".format(child.pid,child.name,child.exe()))
i = i + 1
time.sleep(1)
Related
Is it possible to add a simple badge to a title bar node item? Each tab in my layout represents a separate application. My users would like to see a number next to the name on the tab to indicate whether there are documents in that application needing their attention. If no documents, then no badge, just the application name by itself. If there are documents, then display the application name and a badge for the number. I'm not finding a way to include the span tag in a PageLinkNode or BasicLinkNode.
PageLinkNode (xe:pageTreeNode) label can only be plain text.
You can use the image property though:
<xe:this.titleBarTabs>
<xe:pageTreeNode
page="..."
label="Application A"
image="#{javascript: var nr = 5;
nr > 0 ? ('badge' + Math.min(nr, 10) + '.gif') : ''}">
</xe:pageTreeNode>
Add to Resources/Images ten pictures badge1.gif, badge2.gif, ... badge10.gif with the numbers as pictures. badge10.gif would be a 9+ picture.
As an alternative, you could provide the number of documents as part of the label (e.g. "Your Application Name [23]") and convert it on client side onClientLoad event to HTML label + badge-span.
With this code:
QtCore.QObject.connect(self.tabWidget, QtCore.SIGNAL("tabCloseRequested(int)"),
self.tabWidget.removeTab)
I can close any tab QTabWidget, and the names of these tabs are:
work_1
work_2
work_3
But I want the tab work_1 never closes.
Use Index did not work for two reasons:
The tabs can be dynamically moved by this code:
self.tabWidget.setMovable (True)
That makes the Index are constantly changing.
The user has the ability to add new tabs.
Tabs can be identified by their widgets, and the widgets can be identified by their objectName (or some other unique attribute):
self.tabWidget.tabCloseRequested.connect(sef.removeTab)
...
def removeTab(self, index):
widget = self.tabWidget.widget(index)
if widget is not None and widget.objectName() != 'work_1':
self.tabWidget.removeTab(index)
or perhaps more simply:
if widget is not None and widget is not self.work_1:
self.tabWidget.removeTab(index)
I need to detect whether a Uiview is a standard opened view or if it is an activated viewport on a sheet. Querying the uiview’s view Id returns the Id of the activated viewport's view. I have found no direct way to detect that a uiview is actually a sheet with an activated viewport.
I am already tracking opened views in the view activated event for another purpose. So I considered storing the view Id with the uiview hashcode for later checking that it was indeed a sheetview prior to becoming an activated view. Unfortunately, and I think in opposition to standard use, the uiview hashcode is not stable. Multiple hashcode requests from the uiview object return different values.
Does anyone have a way to detect this condition? I need to be able to use the the methods on the uiview still. So any help to find the actual child windows I would like to relate to the uiview object. The view still says "Sheet: ..." in the title when a view is activated.
TaskDialog mainDialog = new TaskDialog("Hello, viewport check!");
mainDialog.MainInstruction = "Hello, viewport check!";
mainDialog.MainContent =
"Sadly Revit API doesn't automatically know if the user is in an active viewport. "
+ "Please click 'Yes' if your are, or 'No' if your not.";
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink1,
"Yes, I am in an active viewport on a sheet.");
mainDialog.AddCommandLink(TaskDialogCommandLinkId.CommandLink2,
"No, I am just in an ordinary view.");
mainDialog.CommonButtons = TaskDialogCommonButtons.Close;
mainDialog.DefaultButton = TaskDialogResult.Close;
TaskDialogResult tResult = mainDialog.Show();
bool YesOrNo = true;
if (TaskDialogResult.CommandLink1 == tResult)
{
YesOrNo = true;
}
else if (TaskDialogResult.CommandLink2 == tResult)
{
YesOrNo = false;
}
else{
return;
}
You can use the ViewSheet GetAllViewports method to determine all the viewports on a given sheet. Using that, you could put together a bi-directional dictionary lookup system map any sheet to all the viewports it hosts and vice versa. That should help solve your task. Here is some example usage:
http://thebuildingcoder.typepad.com/blog/2014/04/determining-the-size-and-location-of-viewports-on-a-sheet.html
Im late to the party - but another way to sense if the user is in a viewport is to investigate the Process.MainWindow title. Something like this (in RevitPythonShell):
import threading, clr
from System.Diagnostics import Process
# need winform libraries for feedback form only
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Form, Label
app = __revit__.Application
doc = __revit__.ActiveUIDocument.Document
ui = __revit__.ActiveUIDocument
def lookAtWindow(activeView):
# Looking for one of three conditions:
# 1. User is on a sheet (ActiveView will be DrawingSheet)
# 2. User is in an active ViewPort on a sheet (ActiveView will NOT be be DrawingSheet, but MainWindowTitle will contain " - [Sheet: " string)
# 3. User is on a View (neither of the previous two conditions)
result = False
if str(activeView.ViewType) == 'DrawingSheet':
result = 'Youre on a sheet'
else:
processes = list(Process.GetProcesses())
for process in processes:
window = process.MainWindowTitle
if window and 'Autodesk Revit '+app.VersionName[-4:] in window and ' - [Sheet: ' in window and ' - '+doc.Title+']' in window:
result = 'I reckon youre in a Viewport'
if not result:
result = 'so you must be in a '+str(activeView.ViewType)
form = Form()
form.Width = 300
form.Height = 100
label = Label()
label.Width = 280
label.Height = 70
label.Text = result
label.Parent = form
form.ShowDialog()
# need to close RevitPythonShell console before checking MainWindowTitle, so run on timer
threading.Timer(1, lookAtWindow, [ui.ActiveView]).start()
__window__.Close()
This is a jwplayer case. I have a website with music album pages. Right now I have a jwplayer playing a playlist and works fine, but I want to have a table listing all the songs by track number and a play icon that plays the song on the first of each line. So far I managed to create a play icon that plays the full playlist but no luck on how to create as many icons as the number of songs and that each plays a different song from the playlist.
This is a representation of what I want to do
play icon (song 1) | track number | title song 1 | duration
play icon (song 2) | track number | title song 2 | duration
The current code I have is this, which creates a single play icon that plays the playlist. This code, by the way is pretty awesome as it plays next song automatically and controls the pause/play of the main player. This website runs on joomla.
<script>
var playerInstance = jwplayer('container');
playerInstance.setup({
playlist: [{
//DYNAMICALLY GENERATED PLAYLIST
<?php
$album_id = $this->item->id;
// Get default database object
$db = JFactory::getDbo();
// Get a new JDatabaseQuery object
$query = $db->getQuery(true);
$query = 'SELECT position, name, length, filename FROM XXX WHERE `album_id` = ' . $db->quote( (int) $album_id ) . ' ORDER BY `num` ASC LIMIT 0 , 30';
$db->setQuery($query);
$results = $db -> loadAssocList();
foreach($results as $row){
echo "file: \"/". htmlentities($row['filename']). "\", ";
echo "title: \"". htmlentities($row['name']). "\"";
echo "},{";
}
?> }]
//END DYNAMICALLY GENERATED PLAYLIST
controls: false
});
playerInstance.on('play', function() {
document.getElementById("videoPlayPause").style.backgroundPosition = "-263px -70px";
});
playerInstance.on('pause', function() {
document.getElementById("videoPlayPause").style.backgroundPosition = "-287px -70px";
});
</script>
<br/>
<div class="videoPlayerControls playing" id="videoPlayerControls">
<button id="videoPlayPause" onclick="playerInstance.play();" onmouseout="if(playerInstance.getState() == "IDLE" || playerInstance.getState() == "PAUSED"){document.getElementById("videoPlayPause").style.backgroundPosition = "-62px 0";} if(playerInstance.getState() == "PLAYING"){document.getElementById("videoPlayPause").style.backgroundPosition = "-62px -50px";}" onmouseover="if(playerInstance.getState() == "PLAYING"){document.getElementById("videoPlayPause").style.backgroundPosition = "-263px -70px";}if(playerInstance.getState() == "IDLE" || playerInstance.getState() == "PAUSED"){document.getElementById("videoPlayPause").style.backgroundPosition = "-287px -70px";}" type="button">Play/Pause</button>
Anyone has done something like this?
In JavaScript, you just need to load the URL of the file you want to play into the player, like this.
<script>
jwplayer('yourPlayerDivId').setup({
file: 'track1.mp4'
});
</script>
Given you have a loaded playlist, you can access (play) any item in the playlist directly using the playerInstance.playlistItem(index) method.
This starts playback of the playlist item at the specified index - bearing in mind that the first item in the playlist would have an index of 0.
You should therefore be able to attach a click event to each corresponding 'Play Icon' which calls this method with an incremented index in order to access the associated playlist item.
BTW: Since JW7 the playerInstance.getState() reports the state as a lowercase string...
As the title says, I need to list the content of all child-pages on the parent-page, after its own content. Or the thing I really need is, one page with content and and a menu which links to the different headers of the content. e.g. athe parent-page with content:
**Parent Head**
parent text
*first subhead*
first subtext
*second subhead*
second subtext
and the menu should look like:
Parent
-first subhead
-second subhead
I thought it would be easier if the parent-page "collects" the content of the child-pages.
The other solution was, that the child-pages would be links to extern URLs, to the specific c-IDs of the different contents of the parent-page. But I think this isn't that easy for the website owner, who doesn't know anything about where he can find the right c-ID in the web-page-source-code.
So how would You make that? Or how can I realize the thing with the child-page-content?
EDIT: Have a solution now. Just have to fix, that the submenu will be displayed without childpages.
Here is the code:
temp.contentnav = CONTENT
temp.contentnav {
table = tt_content
select {
pidInList = 7
orderBy = sorting
where = colPos=0
languageField=sys_language_uid
}
renderObj = TEXT
renderObj {
field = header
wrap= <li>|</li>
typolink.parameter.field=pid
typolink.parameter.dataWrap=|#{field:uid}
typolink.ATagParams = class="linkClass"
if.isTrue.field=header
}
wrap = <ul id="submenuClass"> | </ul>
}
page.10.marks.MENU.2.NO.after.cObject < temp.contentnav
Try something like this
temp.pageIds = HMENU
temp.pageIds.entryLevel = 1
temp.pageIds.1 = TMENU
temp.pageIds.1 {
NO.stdWrap.field = uid
NO.allWrap = |,
NO.doNotLinkIt = 1
}
lib.container = CONTENT
lib.container.table = tt_content
lib.container.select {
pidInList.cObject < temp.pageIds
}
There is a content element "Menu/Sitemap" with has an option to render subpages with content.
If you want to do it via TypoScript, render the menu, and then replace the menu items with content of them.
# Pseudocode on menuitem
# assuming you are using css_styled_content
1.allStdWrap.cObject < styles.content.get
# Set pid for CONTENT object from styles.content.get to the uid of the page
# which gets rendered
1.allStdWrap.cObject.select.pidInList.data = uid
Can't provide you with an working snippets atm.