View Single Post
Old 12-03-2014, 07:30 AM   #61
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,741
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by turbulent View Post
In an output sigil plugin, is it possible to get the file name of the epub file currently opened by sigil? So it's convinient to name the generated file after the epub file.
If you have a Windows machine, you could use the win32gui library to find the Sigil title bar text. Here's a quick & dirty solution:

Code:
import win32gui
from win32gui import GetWindowText
class_name = 'Qt5QWindowIcon'
window_name = None
hwnd = win32gui.FindWindow(class_name, window_name)

if hwnd:
    print GetWindowText(hwnd)
    # returns 'untitled.epub - Sigil'
Note that this simple code will return the title bar text of the Qt app that was opened last. I.e. if you open multiple Sigil windows, you'll only get the title bar text of the last window and if you open Calibre (or any other Qt5 app) after Sigil, you'll get the Calibre title bar text.

For a more robust solution, you'll need to enumerate all windows using win32gui.EnumWindows.
Doitsu is offline   Reply With Quote