ফাইল-পর্যবেক্ষণ করে এমন একটি ইউনিট লঞ্চার কীভাবে তৈরি করবেন?


11

আমি এমন একটি লঞ্চার তৈরি করতে চাই যা ট্র্যাশ আইকনের মতো একই কাজ করে যেখানে ট্র্যাশে আইটেম রয়েছে কি না তার উপর নির্ভর করে বিভিন্ন কুইকলিস্টগুলি দেখানো হয়।

আমি এর মতো কিছু চাই: যদি ফোল্ডারটি Aবিদ্যমান থাকে A,B,Cতবে দ্রুত তালিকায় প্রদর্শিত হবে, যদি ফোল্ডারটি Aউপস্থিত না থাকে, D,E,Fদ্রুত তালিকায় প্রদর্শন করুন।


3
আমি এটি আগে দেখেছি এবং এটি সম্ভবত স্টার্টআপ নোটিফিকেশন প্রোটোকলের মাধ্যমে সম্পন্ন করতে হবে । এবং .ডেস্কটপ ফাইলটিতে স্টার্টআপনোটাইফাই সেট করে by তবে আমি সেখান থেকে নিশ্চিত নই।
পল ভ্যান শ্যাচ

1
দেখুন: wiki.ubuntu.com/Unity/LauncherAPI এর গতিশীল কুইললিস্টের উদাহরণ রয়েছে
এস

উত্তর:


3

নিম্নলিখিত কাজগুলি:

  1. নীচে দেওয়া বিষয়বস্তু সহ 2 টি ফাইল তৈরি করুন: mylauncher.desktop এবং mylauncher.py।
  2. Mylauncher.desktop কে একটি এক্সিকিউটেবল করুন।
  3. Unityক্যের প্রবর্তকটিতে mylauncher.desktop যুক্ত করুন।
  4. প্রয়োজনীয় হিসাবে mylauncher.py এ ফোল্ডারনাম এবং ফোল্ডারলোকগুলি সম্পাদনা করুন।
  5. python mylauncher.pyপটভূমিতে চালান । আপনাকে এটিকে আপনার স্টার্ট আপ স্ক্রিপ্টগুলির একটিতে যুক্ত করতে হবে।

সূত্র: https://wiki.ubuntu.com/Unity/LauncherAPI


Mylauncher.desktop এর উপাদানসমূহ:

[Desktop Entry]
Name=My Launcher
Comment=A,B,C if A else D,E,F
Exec=nautilus %U
Icon=nautilus
Terminal=false
StartupNotify=true
Type=Application
OnlyShowIn=GNOME;Unity;
Actions=;

Mylauncher.py এর উপাদানসমূহ:

updateinterval = 1 #Update interval in seconds. Set it to a +ve integer.
#In Foldernames and Folderlocations, spaces shouldn't be preceded by \.
Foldernames = ["A", "B", "C", "D", "E", "F"]
Folderlocations = ["/home/prasanth/A", "/home/prasanth/B", "/home/prasanth/C", "/home/prasanth/D", "/home/prasanth/E", "/home/prasanth/F"]
#####################################

from gi.repository import Unity, Gio, GObject, Dbusmenu
import os, subprocess

def nautilusopen(junk1, junk2, location): #Function that opens `location` in nautilus. Equivalent to `nautilus location` in bash.
    subprocess.Popen(['nautilus', "%s" % location])

launcher = Unity.LauncherEntry.get_for_desktop_id("mylauncher.desktop") #You won't have to modify this, except if you rename `mylauncher.desktop`

#Code block A: This code block builds 6 quicklist entries, 3 for when A is found and 3 for when it isn't
QLentries = [Dbusmenu.Menuitem.new() for i in Foldernames]
for i in xrange(6):
    QLentries[i].property_set(Dbusmenu.MENUITEM_PROP_LABEL, "Goto %s" % Foldernames[i])
    QLentries[i].connect("item-activated", nautilusopen, Folderlocations[i])
    QLentries[i].property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
################

#Code block B: This code block creates 2 quicklists 1 for when A is found and 1 for when it isn't. Then it adds the first 3 quicklist entries to QLifA and the next 3 to QLifnotA
QLifA = Dbusmenu.Menuitem.new() #Quicklist if A is found
QLifnotA = Dbusmenu.Menuitem.new() #Quicklist if A is not found.
for i in xrange(3):
    QLifA.child_append(QLentries[i])
for i in xrange(3, 6):
    QLifnotA.child_append(QLentries[i])
################

#The rest of the code simply monitors the file system for A's existence and switches appropriately between QLifA and QLifnotA
prevState = None
def updateql():
    global prevState
    currentState = 'A' if os.path.exists(Folderlocations[0]) else 'notA' #currentState is 'A' if Folderlocations[0] (which is /home/prasanth/A) exists, 'notA' otherwise
    if currentState != prevState:
        if currentState == 'A':
            launcher.set_property("quicklist", QLifA)
        else:
            launcher.set_property("quicklist", QLifnotA)
        prevState = currentState
    return True

#GObject.timeout_add_seconds(updateinterval, updateql)
#mainloop = GObject.MainLoop()
#mainloop.run()

#If the 3-line commented block above worked as expected, the remainder of this script would be unnecessary. Unfortunately, it doesn't.
import signal
def alarmhandler(signum, frame):
    raise Exception('Alarm has rung')
signal.signal(signal.SIGALRM, alarmhandler)

mainloop = GObject.MainLoop()

while True:
    try:
        updateql()
        signal.alarm(updateinterval)
        mainloop.run()
    except KeyboardInterrupt:
        continue

সম্পাদনা: মন্তব্যে উল্লিখিত উদ্দেশ্যটির জন্য নিম্নলিখিতটি mylauncher.py হিসাবে ব্যবহার করুন। আপনার প্রয়োজন অনুসারে সংশোধন করা সরাসরি হওয়া উচিত এবং যদি মন্তব্যগুলিতে এটি উল্লেখ না করে।

from gi.repository import Unity, Gio, GObject, Dbusmenu
import os, subprocess

updateinterval = 1 #Update interval in seconds. Set it to a +ve integer.

#Quicklist entries if already mounted:
ifMountedEntry1text = """Unmount A""" #Text shown in the quicklist menu for this entry.
ifMountedEntry1command = """unmount A""" #Bash command to execute when entry 1 is clicked. Doubt if `unmount A` will work. Modify appropriately.

ifMountedEntry2text = """Open A""" #Maybe you'll want to open A directly from the launcher. Included just so you get a hang of how this works.
ifMountedEntry2command = """nautilus A"""
#Extend as required.

#Quicklist entries if not already mounted:
ifnotMountedEntry1text = """Mount A"""
ifnotMountedEntry1command = """mount A""" #Again modify `mount A` appropriately.
#Extend as required.

#My old file monitoring should work. But in case you want to change the criteria for modifying quicklists, it is better to do the following:
filemonitoringcommand = """if [ -d /folder/to/monitor/ ]; then echo True; else echo False; fi;""" #<Bash command>/<location to script> which prints 'True' if A is mounted, 'False' otherwise.
#####################

def systemcall(junk1, junk2, command):
    os.system(command)

launcher = Unity.LauncherEntry.get_for_desktop_id("mylauncher.desktop") #You won't have to modify this, except if you rename `mylauncher.desktop`

#Quicklist if already mounted:
QLifMounted = Dbusmenu.Menuitem.new()

ifMountedEntry1 = Dbusmenu.Menuitem.new()
ifMountedEntry1.property_set(Dbusmenu.MENUITEM_PROP_LABEL, ifMountedEntry1text) #Sets the text shown in the quicklist menu for this entry.
ifMountedEntry1.connect("item-activated", systemcall, ifMountedEntry1command) #Sets the corresponding bash command.
ifMountedEntry1.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
QLifMounted.child_append(ifMountedEntry1) #Adds the first entry to the quicklist

ifMountedEntry2 = Dbusmenu.Menuitem.new()
ifMountedEntry2.property_set(Dbusmenu.MENUITEM_PROP_LABEL, ifMountedEntry2text)
ifMountedEntry2.connect("item-activated", systemcall, ifMountedEntry2command)
ifMountedEntry2.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
QLifMounted.child_append(ifMountedEntry2)
#Extend as required.

#Quicklist if not already mounted:
QLifnotMounted = Dbusmenu.Menuitem.new()

ifnotMountedEntry1 = Dbusmenu.Menuitem.new()
ifnotMountedEntry1.property_set(Dbusmenu.MENUITEM_PROP_LABEL, ifnotMountedEntry1text)
ifnotMountedEntry1.connect("item-activated", systemcall, ifnotMountedEntry1command)
ifnotMountedEntry1.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
QLifnotMounted.child_append(ifnotMountedEntry1)
#Extend as required.

#The rest of the code uses `filemonitoringcommand` to monitor the filesystem and dynamically modifies (or rather switches between) quicklists.
prevState = None
def updateql():
    global prevState
    currentState = 'True' in os.popen(filemonitoringcommand).read()
    if currentState != prevState:
        if currentState == True:
            launcher.set_property("quicklist", QLifMounted) #If already mounted, sets QLifMounted as the quicklist.
        else:
            launcher.set_property("quicklist", QLifnotMounted) #Otherwise sets QLifnotMounted as the quicklist.
        prevState = currentState
    return True

#GObject.timeout_add_seconds(updateinterval, updateql)
#mainloop = GObject.MainLoop()
#mainloop.run()

#If the 3-line commented block above worked as expected, the remainder of this script would be unnecessary. Unfortunately, it doesn't.
import signal
def alarmhandler(signum, frame):
    raise Exception('Alarm has rung')
signal.signal(signal.SIGALRM, alarmhandler)

mainloop = GObject.MainLoop()

while True:
    try:
        updateql()
        signal.alarm(updateinterval)
        mainloop.run()
    except KeyboardInterrupt:
        continue

আমি এটি চেষ্টা করেছি কিন্তু এটি আমার কাজ করে না। দ্রুত তালিকা পরিবর্তন হয় না। আমি উবুন্টু 12.10 64-বিট ব্যবহার করছি।
রে লিওনার্ড আমোরাতো

আমি 12.04 32 বিট ব্যবহার করছি। ল্যাঞ্চারে লঞ্চ আইকনটি যুক্ত করার পরে পাইথন স্ক্রিপ্টটি চালানো উচিত।
এস প্রশান্ত

নিম্নলিখিতটি করুন)) la / .local / share / অ্যাপ্লিকেশনগুলিতে mylauncher.desktop রাখুন 2) সুপার-কী টিপুন এবং 'আমার লঞ্চার' অনুসন্ধান করুন। 3) unityক্য লঞ্চারের উপরে প্রদর্শিত লঞ্চার আইকনটি টানুন। 4) অজগর স্ক্রিপ্ট চালান। এই কাজ করা উচিত.
এস প্রশান্ত

পুনঃটুইট করুন এটা কি কাজ করেছিল?
এস প্রসন্ত

ওহে. দুঃখিত, আমি অনলাইনে অনলাইনে যাওয়ার সময়টি খুঁজে পাইনি, তবে আপনার সর্বশেষ পদ্ধতিটি আমার পক্ষে কাজ করেছে। যাইহোক, আমি যা চেয়েছিলাম তা স্ক্রিপ্ট যা করে তার থেকে কিছুটা আলাদা। আমি একটি ফোল্ডার অবস্থান নিরীক্ষণ করতে চাই (স্ক্রিপ্টটি ইতিমধ্যে এটি করে) এবং যদি ফোল্ডার 'এ' উপস্থিত থাকে, দ্রুত তালিকায় 'আনমাউন্ট' দেখান। অন্যথায় 'মাউন্ট' দেখান। পাইথন স্ক্রিপ্টিং সম্পর্কে আমার কোনও জ্ঞান নেই তাই আপনার সরবরাহিত স্ক্রিপ্টটি কীভাবে পরিবর্তন করতে হবে তা আমার কোনও ধারণা নেই। আপনি যদি এই চূড়ান্ত কিছুটি সাহায্য করতে পারেন তবে দুর্দান্ত হবে।
রে লিওনার্ড আমোরাতো
আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.