2015-09-04 4 views
5

मैं जाँच करने के लिए है कि क्या एक खिड़की इस तरह बनाया गया है Wnck उपयोग किया है:जीटीके + संवाद बनाया गया है या नहीं, तो परीक्षण कैसे करें?

screen = Wnck.Screen.get_default() 
    screen.force_update() # recommended per Wnck documentation 
    window_list = screen.get_windows() 

    for window in window_list: 
     print(window.get_name()) 
     if window.has_name(): 
      if window.get_name() == self.xld_main_window.get_title(): 
       window_found = True 
       break 
    assert window_found, 'The Gtk.Window named {window_name} has not been found.'\ 
     .format(window_name=self.xld_main_window.get_title()) 

    # clean up Wnck (saves resources, check documentation) 
    window = None 
    screen = None 

हालांकि, बाद से संवाद कार्यों की सूची में दिखाई नहीं देती हैं, मैं उन्हें उस तरह से नहीं मिल रहा। यह जांचने का उचित तरीका क्या है कि वे प्रदर्शित होते हैं (और मोडल/मोडल नहीं)?

उत्तर

1

Wnck.Screen.get_windows विधि संवाद सहित सभी विंडोज़ लौटाता है। समारोह में कोई भेद नहीं है क्योंकि फ़ंक्शन किसी भी Wnck.Window को वर्तमान में मैप किया गया है। स्रोत इस प्रकार है:

* The #WnckScreen represents a physical screen. A screen may consist of 
* multiple monitors which are merged to form a large screen area. The 
* #WnckScreen is at the bottom of the libwnck stack of objects: #WnckWorkspace 
* objects exist a #WnckScreen and #WnckWindow objects are displayed on a 
* #WnckWorkspace. 
* 
* The #WnckScreen corresponds to the notion of 
* <classname>GdkScreen</classname> in GDK. 

GList* 
wnck_screen_get_windows (WnckScreen *screen) 
{ 
    g_return_val_if_fail (WNCK_IS_SCREEN (screen), NULL); 

    return screen->priv->mapped_windows; 
} 

WNCK_WINDOW_DIALOG सेट हो सकता है, जहां एक struct आदि कुछ WnckWindow खिड़कियों के कुछ सूचियों (मैप किया गया, खड़ी), सक्रिय विंडो के लिए सूचक, युक्त screen->priv अंक और एक संवाद होना ।

WnckWindow वर्ग भी पता करने के लिए जब एक WnckTaskList में चयनित है, तो फोकस एक क्षणिक चाइल्ड विंडो के पास जाना चाहिए या उसके माता पिता के साथ क्षणिक विंडो को छोटा करने के लिए एक समारोह transient_is_most_recently_activated() प्रदान करता है। उदाहरण के लिए, पता करने के लिए मौसम My Application खिड़की एक सबसे हाल ही में सक्रिय क्षणिक है:

screen = Wnck.Screen.get_default() 
screen.force_update() # recommended per Wnck documentation 
window_list = screen.get_windows() 

for window in window_list: 
    if window.get_name() == 'My Application': 
     print(window.transient_is_most_recently_activated()) 

स्क्रिप्ट नीचे अन्य मैप की खिड़कियों के रूप में संवाद (कोई बात नहीं अगर वे मोडल/गैर-मोडल या आवेदन वे से कर रहे हैं) पकड़ता ।

import gi 
gi.require_version('Gtk', '3.0') 
gi.require_version('Wnck', '3.0') 
from gi.repository import Gtk, Wnck 

class DialogExample(Gtk.Dialog): 

    def __init__(self, parent): 
     Gtk.Dialog.__init__(self, "My Dialog", parent, 0, #or Gtk.DialogFlags.MODAL 
      (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, 
      Gtk.STOCK_OK, Gtk.ResponseType.OK)) 

     self.set_default_size(100, 100) 

     label = Gtk.Label("This is a dialog to display additional information") 

     box = self.get_content_area() 
     box.add(label) 
     self.show_all() 

class DialogWindow(Gtk.Window): 

    def __init__(self): 
     Gtk.Window.__init__(self, title="Dialog Example") 
     self.set_border_width(6) 
     button = Gtk.Button("Open dialog") 
     button.connect("clicked", self.on_button_clicked) 
     self.add(button) 

    def on_button_clicked(self, widget): 
     dialog = DialogExample(self) 
     response = dialog.run() 

     if response == Gtk.ResponseType.OK: 
      print("The OK button was clicked") 
     elif response == Gtk.ResponseType.CANCEL: 
      print("The Cancel button was clicked") 

     screen = Wnck.Screen.get_default() 
     screen.force_update() # recommended per Wnck documentation 
     window_list = screen.get_windows() 

     for window in window_list: 
      print(window.get_name()) 

     window, window_list = (None,)*2 
     screen = None 

     dialog.destroy() 

win = DialogWindow() 
win.connect("delete-event", Gtk.main_quit) 
win.show_all() 

window = None 
screen = None 
Gtk.main() 

Wnck के बजाय को जरूर उपयोग करके, आप एक से थोड़ा निचले स्तर पर ही बात कर रहे हैं।

+0

अपने जवाब के लिए धन्यवाद, लेकिन इस afaik: _ "Wnck.Screen.get_windows विधि रिटर्न संवाद सहित सभी खिड़कियां। "_ सच नहीं है। यदि संवाद फ़ंक्शन द्वारा लौटाई गई विंडो की उस सूची में था, तो मैंने कभी इस प्रश्न को पोस्ट नहीं किया होगा। अब यह थोड़ी देर हो गया है, लेकिन एकमात्र दूसरी गलती मैं कल्पना कर सकता हूं, कि मुझे विंडो सूची प्राप्त करने से पहले थोड़ा इंतजार करना पड़ेगा, लेकिन चूंकि यह अब के लिए संवाद दिखाई देने वाला नहीं है, मुझे नहीं लगता कि संवाद के निर्माण में इतना समय लगना चाहिए। क्या आप अन्य कारणों को जानते हैं, विंडोज़ की सूची में संवाद क्यों नहीं होगा? – Zelphir

+0

ध्यान दें कि मेरे सिस्टम पर किसी भी टास्कबार में संवाद प्रकट नहीं होते हैं। तो अगर wnck किसी प्रकार की टास्कबार चेक का उपयोग करता है, तो यह इस तरह काम नहीं करेगा। – Zelphir

+0

मैं आपका उदाहरण चलाने में सक्षम था और अब मुझे आश्वस्त है कि मेरे pytest test में कुछ और गलती होनी चाहिए, जो ऐसा करता है, कि सूची सूची में प्रकट नहीं होती है। शायद मैं इसे आपके उदाहरण के साथ काम कर सकता हूं। – Zelphir

0

Eye of Hell खुले विंडो पाने के लिए कहना है कि द्वारा this answer से आंशिक रूप से ले रहा है, तो आप ऐसा कर सकते हैं:

from gtk import gdk 

name = "MyDialog" 

root = gdk.get_default_root_window() 
matches = [] 
for id in root.property_get("_NET_CLIENT_LIST"): 
    window = gdk.window_foreign_new(id) 
    if window and window.property_get("WM_NAME")[2] == name: 
     matches.append(window) 

for match in matches: 
    print(match, match.get_modal_hint()) 
+0

क्षमा करें, लेकिन मैं संवाद के बारे में पूछताछ कर रहा हूं, खिड़कियां नहीं। मैंने विंडोज़ की जांच के लिए ओपी में पहले से ही फ़ंक्शन का उपयोग किया है, लेकिन यह संवाद पर काम नहीं करता है (या कहीं और गलती है)। – Zelphir

+0

@ ज़ेलफिर: संवाद मेरे लिए काम करते हैं। – zondo

संबंधित मुद्दे