Example #1
0
File: ffs.py Project: jku/ffs
    def create_archive(self, files, callback):
        temp_dir = tempfile.mkdtemp("", "ffs-")
        if len(files) == 1:
            archive_name = os.path.join(temp_dir, GLib.path_get_basename(files[0]))
        else:
            archive_name = os.path.join(temp_dir, "archive.zip")

        cmd = ["7z", "-y", "-tzip", "-bd", "-mx=7", "a", archive_name]
        flags = GLib.SpawnFlags.SEARCH_PATH | GLib.SpawnFlags.DO_NOT_REAP_CHILD
        result = GLib.spawn_async(cmd + files, [], GLib.get_current_dir(), flags, None, None, False, True, False)
        self.out_7z = GLib.IOChannel(result[2])
        self.out_7z.set_close_on_unref(True)
        GLib.child_watch_add(result[0], self.on_child_process_exit, callback)

        return archive_name
Example #2
0
    def __init__(self):

        h = Gdk.Screen().height()
        w = Gdk.Screen.width()

        Gtk.Window.__init__(self, title="Gitmarks")
        self.props.resizable = True
        self.props.default_width = w / 3
        self.props.default_height = h
        self.status_bar = Gtk.Statusbar.new()
        self.tree_view = None
        self.item_list = None

        gm_dispatcher = dispatcher.Dispatcher()
        ofh = OpenFileHandler(self, self.status_bar, gm_dispatcher)
        handlers = [ofh]
        gm_dispatcher.load_handlers(handlers)

        self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=3)
        self.hbox = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL)

        self.add(self.vbox)

        hb_factory = widgets.HeaderBar(gm_dispatcher)
        header_bar = hb_factory.make_headerbar("Gitmarks")
        self.profile_label = hb_factory.get_profile_label()
        self.set_titlebar(header_bar)

        self.vbox.pack_start(self.hbox, True, True, 0)
        self.vbox.pack_end(self.status_bar, False, True, 0)
        self.connect("delete-event", Gtk.main_quit)

        self.gio_settings = settings.GitmarksSettings().create_gio_settings(
            GLib.get_current_dir())

        if self.init_settings() is None:
            sys.exit(0)
Example #3
0
    def __on_command_line(self, app, app_cmd_line):
        """
            Handle command line
            @param app as Gio.Application
            @param options as Gio.ApplicationCommandLine
        """
        try:
            args = app_cmd_line.get_arguments()
            options = app_cmd_line.get_options_dict()
            if options.contains("debug"):
                self.debug = True
            # We are forced to enable scrobblers here if we want full debug
            if not self.scrobblers:
                if LastFM is not None:
                    self.scrobblers = [LastFM("lastfm"), LastFM("librefm")]
                self.load_listenbrainz()
            if options.contains("set-rating"):
                value = options.lookup_value("set-rating").get_string()
                try:
                    value = min(max(0, int(value)), 5)
                    if self.player.current_track.id is not None:
                        self.player.current_track.set_rate(value)
                except Exception as e:
                    Logger.error("Application::__on_command_line(): %s", e)
                    pass
            elif options.contains("play-pause"):
                self.player.play_pause()
            elif options.contains("stop"):
                self.player.stop()
            ## anhsirk0 edits
            elif options.contains("set-next"):
                try:
                    track_id = int(args[1])
                    try:
                        self.player.append_to_queue(track_id, notify=True)
                    except:
                        pass
                except:
                    pass

            ## anhsirk0 edits ends

            elif options.contains("play-ids"):
                try:
                    value = options.lookup_value("play-ids").get_string()
                    ids = value.split(";")
                    tracks = []
                    for id in ids:
                        if id[0:2] == "a:":
                            album = Album(int(id[2:]))
                            tracks += album.tracks
                        else:
                            tracks.append(Track(int(id[2:])))
                    self.player.load(tracks[0])
                    self.player.populate_playlist_by_tracks(
                        tracks, [Type.SEARCH])
                except Exception as e:
                    Logger.error("Application::__on_command_line(): %s", e)
                    pass
            elif options.contains("next"):
                self.player.next()
            elif options.contains("prev"):
                self.player.prev()
            elif options.contains("emulate-phone"):
                self.__window.toolbar.end.devices_popover.add_fake_phone()
            elif len(args) > 1:
                uris = []
                pls = []
                for uri in args[1:]:
                    try:
                        uri = GLib.filename_to_uri(uri)
                    except:
                        pass
                    f = Gio.File.new_for_uri(uri)
                    if not f.query_exists():
                        uri = GLib.filename_to_uri(
                            "%s/%s" % (GLib.get_current_dir(), uri))
                        f = Gio.File.new_for_uri(uri)
                    if is_audio(f):
                        uris.append(uri)
                    elif is_pls(f):
                        pls.append(uri)
                    else:
                        info = f.query_info(Gio.FILE_ATTRIBUTE_STANDARD_TYPE,
                                            Gio.FileQueryInfoFlags.NONE, None)
                        if info.get_file_type() == Gio.FileType.DIRECTORY:
                            uris.append(uri)
                if pls:
                    from gi.repository import TotemPlParser
                    parser = TotemPlParser.Parser.new()
                    parser.connect("entry-parsed", self.__on_entry_parsed,
                                   uris)
                    parser.parse_async(uri, True, None,
                                       self.__on_parse_finished, uris)
                else:
                    self.__on_parse_finished(None, None, uris)
            elif self.__window is not None:
                if not self.__window.is_visible():
                    self.__window.present()
                    self.player.emit("status-changed")
                    self.player.emit("current-changed")
            Gdk.notify_startup_complete()
        except Exception as e:
            Logger.error("Application::__on_command_line(): %s", e)
        return 0
Example #4
0
def init(_name, _version, _prefix, _libdir, _flags=0):
    """
    @params: package parameters

    Initialize directories and global variables. Must be called
    before any of other API in Package is used.
    @params must be an object with at least the following keys:
    - name: the package name ($(PACKAGE_NAME) in autotools)
    - version: the package version
    - prefix: the installation prefix

    init() will take care to check if the program is running from
    the source directory or not, by looking for a 'src' directory.

    At the end, the global variable 'pkg' will contain the
    Package module (imports.package). Additionally, the following
    module variables will be available:
    - name, version: same as in @params
    - prefix: the installation prefix (as passed in @params)
    - datadir, libdir: the final datadir and libdir when installed;
                       usually, these would be prefix + '/share' and
                       and prefix + '/lib' (or '/lib64')
    - pkgdatadir: the directory to look for private data files, such as
                  images, stylesheets and UI definitions;
                  this will be datadir + name when installed and
                  './data' when running from the source tree
    - pkglibdir: the directory to look for private typelibs and C
                 libraries;
                 this will be libdir + name when installed and
                 './lib' when running from the source tree
    - moduledir: the directory to look for JS modules;
                 this will be pkglibdir when installed and
                 './src' when running from the source tree
    - localedir: the directory containing gettext translation files;
                 this will be datadir + '/locale' when installed
                 and './po' in the source tree

    All paths are absolute and will not end with '/'.

    As a side effect, init() calls GLib.set_prgname().
    """

    import builtins

    builtins.__dict__["pkg"] = sys.modules[__name__]

    global name, version, appFlags, prefix, libdir, datadir
    global pkglibdir, libpath, pkgdatadir, localedir, moduledir
    global _base

    name = _name
    version = _version
    appFlags = _flags

    # Must call it first, because it can only be called
    # once, and other library calls might have it as a
    # side effect
    GLib.set_prgname(name)

    prefix = _prefix
    libdir = _libdir
    datadir = GLib.build_filenamev([prefix, "share"])

    if _runningFromSource():
        print("Running from source tree, using local files")

        # Running from source directory
        _base = GLib.get_current_dir()
        pkglibdir = GLib.build_filenamev([_base, "lib"])
        libpath = GLib.build_filenamev([pkglibdir, ".libs"])
        girpath = pkglibdir
        pkgdatadir = GLib.build_filenamev([_base, "data"])
        localedir = GLib.build_filenamev([_base, "po"])
        moduledir = GLib.build_filenamev([_base, "src"])
    else:
        appFlags |= Gio.ApplicationFlags.IS_SERVICE

        _base = prefix
        pkglibdir = GLib.build_filenamev([libdir, name])
        libpath = pkglibdir
        girpath = GLib.build_filenamev([pkglibdir, "girepository-1.0"])
        pkgdatadir = GLib.build_filenamev([datadir, name])
        localedir = GLib.build_filenamev([datadir, "locale"])
        moduledir = pkgdatadir

    sys.path.insert(0, moduledir)
    GIRepository.Repository.prepend_search_path(girpath)
    GIRepository.Repository.prepend_library_path(libpath)

    try:
        resource = Gio.Resource.load(GLib.build_filenamev([pkgdatadir, name + ".data.gresource"]))
        resource._register()
    except e:
        pass
Example #5
0
def init(_name, _version, _prefix, _libdir, _flags=0):
    """
    @params: package parameters

    Initialize directories and global variables. Must be called
    before any of other API in Package is used.
    @params must be an object with at least the following keys:
    - name: the package name ($(PACKAGE_NAME) in autotools)
    - version: the package version
    - prefix: the installation prefix

    init() will take care to check if the program is running from
    the source directory or not, by looking for a 'src' directory.

    At the end, the global variable 'pkg' will contain the
    Package module (imports.package). Additionally, the following
    module variables will be available:
    - name, version: same as in @params
    - prefix: the installation prefix (as passed in @params)
    - datadir, libdir: the final datadir and libdir when installed;
                       usually, these would be prefix + '/share' and
                       and prefix + '/lib' (or '/lib64')
    - pkgdatadir: the directory to look for private data files, such as
                  images, stylesheets and UI definitions;
                  this will be datadir + name when installed and
                  './data' when running from the source tree
    - pkglibdir: the directory to look for private typelibs and C
                 libraries;
                 this will be libdir + name when installed and
                 './lib' when running from the source tree
    - moduledir: the directory to look for JS modules;
                 this will be pkglibdir when installed and
                 './src' when running from the source tree
    - localedir: the directory containing gettext translation files;
                 this will be datadir + '/locale' when installed
                 and './po' in the source tree

    All paths are absolute and will not end with '/'.

    As a side effect, init() calls GLib.set_prgname().
    """

    import builtins
    builtins.__dict__['pkg'] = sys.modules[__name__]

    global name, version, appFlags, prefix, libdir, datadir
    global pkglibdir, libpath, pkgdatadir, localedir, moduledir
    global _base

    name = _name
    version = _version
    appFlags = _flags

    # Must call it first, because it can only be called
    # once, and other library calls might have it as a
    # side effect
    GLib.set_prgname(name)

    prefix = _prefix
    libdir = _libdir
    datadir = GLib.build_filenamev([prefix, 'share'])

    if _runningFromSource():
        print('Running from source tree, using local files')

        # Running from source directory
        _base = GLib.get_current_dir()
        pkglibdir = GLib.build_filenamev([_base, 'lib'])
        libpath = GLib.build_filenamev([pkglibdir, '.libs'])
        girpath = pkglibdir
        pkgdatadir = GLib.build_filenamev([_base, 'data'])
        localedir = GLib.build_filenamev([_base, 'po'])
        moduledir = GLib.build_filenamev([_base, 'src'])
    else:
        appFlags |= Gio.ApplicationFlags.IS_SERVICE

        _base = prefix
        pkglibdir = GLib.build_filenamev([libdir, name])
        libpath = pkglibdir
        girpath = GLib.build_filenamev([pkglibdir, 'girepository-1.0'])
        pkgdatadir = GLib.build_filenamev([datadir, name])
        localedir = GLib.build_filenamev([datadir, 'locale'])
        moduledir = pkgdatadir

    sys.path.insert(0, moduledir)
    GIRepository.Repository.prepend_search_path(girpath)
    GIRepository.Repository.prepend_library_path(libpath)

    try:
        resource = Gio.Resource.load(
            GLib.build_filenamev([pkgdatadir, name + '.data.gresource']))
        resource._register()
    except e:
        pass
Example #6
0
 def __on_command_line(self, app, app_cmd_line):
     """
         Handle command line
         @param app as Gio.Application
         @param options as Gio.ApplicationCommandLine
     """
     try:
         args = app_cmd_line.get_arguments()
         options = app_cmd_line.get_options_dict()
         if options.contains("debug"):
             self.debug = True
         if options.contains("set-rating"):
             value = options.lookup_value("set-rating").get_string()
             try:
                 value = min(max(0, int(value)), 5)
                 if self.player.current_track.id is not None:
                     self.player.current_track.set_rate(value)
             except Exception as e:
                 Logger.error("Application::__on_command_line(): %s", e)
                 pass
         elif options.contains("play-pause"):
             self.player.play_pause()
         elif options.contains("stop"):
             self.player.stop()
         elif options.contains("play-ids"):
             try:
                 value = options.lookup_value("play-ids").get_string()
                 ids = value.split(";")
                 albums = []
                 for id in ids:
                     if id[0:2] == "a:":
                         album = Album(int(id[2:]))
                         self.player.add_album(album)
                         albums.append(album)
                     else:
                         track = Track(int(id[2:]))
                         self.player.add_album(track.album)
                         albums.append(track.album)
                 if albums and albums[0].tracks:
                     self.player.load(albums[0].tracks[0])
             except Exception as e:
                 Logger.error("Application::__on_command_line(): %s", e)
                 pass
         elif options.contains("next"):
             self.player.next()
         elif options.contains("prev"):
             self.player.prev()
         elif options.contains("emulate-phone"):
             self.__window.toolbar.end.devices_popover.add_fake_phone()
         elif len(args) > 1:
             audio_uris = []
             playlist_uris = []
             for uri in args[1:]:
                 parsed = urlparse(uri)
                 if parsed.scheme not in ["http", "https"]:
                     try:
                         uri = GLib.filename_to_uri(uri)
                     except:
                         pass
                     f = Gio.File.new_for_uri(uri)
                     # Try ./filename
                     if not f.query_exists():
                         uri = GLib.filename_to_uri(
                             "%s/%s" % (GLib.get_current_dir(), uri))
                         print(uri)
                         f = Gio.File.new_for_uri(uri)
                 file_type = get_file_type(uri)
                 if file_type == FileType.PLS:
                     playlist_uris.append(uri)
                 else:
                     audio_uris.append(uri)
             if playlist_uris:
                 self.__parse_uris(playlist_uris, audio_uris)
             else:
                 self.__on_parse_finished(None, None, [], audio_uris)
         elif self.__window is not None:
             if not self.__window.is_visible():
                 self.__window.present()
                 emit_signal(self.player, "status-changed")
                 emit_signal(self.player, "current-changed")
         Gdk.notify_startup_complete()
     except Exception as e:
         Logger.error("Application::__on_command_line(): %s", e)
     return 0
Example #7
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
from gi.repository import Gtk
from gi.repository import GLib

realpath = GLib.get_current_dir()
sys.path.append(realpath + '/Modules/')
sys.path.append(realpath + '/Apps/')
sys.path.append(realpath + '/Plugins/')

GLib.threads_init()
from Apps.AppsWindow import AppsWindow
win = AppsWindow()

main_loop = GLib.MainLoop() 
main_loop.run()