#83 a external command that cover both case


line 224-244 in https://sourceforge.net/p/mcomix/code/HEAD/tree/mcomix/openwith.py

it would be good be able to have %D and #C in a single letter for if i want to open the dir that contain the current open item, the code would be something like those below i think:

  elif identifier == u'': #insert a letter here
    if(context_type & IMAGE_FILE_CONTEXT)
        return os.path.normpath(os.path.dirname(window.imagehandler.get_path_to_page()))
    elif(context_type & ARCHIVE_CONTEXT):
      return os.path.dirname(window.filehandler.get_path_to_base())


Bugs: #73


  • asl97

    asl97 - 2014-02-16

    the ticket management in sourceforge is horrible >.>
    i can't even edit my own ticket to fix things like indent <.<

  • Ark

    Ark - 2014-02-17

    So it's about a new variable that expands to the same value %C expands to while viewing archived images, and that expands to the same value %D expands to while viewing non-archived images, right?

    How about this workaround? You make two commands, one that uses %C and the other one that uses %D instead, and you disable the command that uses %D for archives. This way, only one of both commands will work at the same time. (The %C command will fail if there is no archive, and the %D command will fail if there is an archive because you told it to.)

    If this workaround doesn't work for you, could you please tell us more about the way you want to use this new variable? (That is, what does your use case look like?) In the only examples I can think of right now, the program that is being called (with the value of this new variable) must know more about the environment than MComix needs to know. That is, there must be a specific directory structure and the program knows about this structure, or the program needs user interaction (that is, you want to open a file manager or something).

  • asl97

    asl97 - 2014-02-17

    if i make two commands, both would show (it doesn't hide it) and if i click the wrong one when opening an image folder, it show an error but if i click it when opening an archive, it would open the tmp folder (on linux, eg: /tmp/mcomix.DSFlLs/archive name[SCS]) unless i disable it

    so having a set of variable which point to current open item(image or archive)
    might be useful unless you could make an command run differently depending on the current open item

  • Ark

    Ark - 2014-02-17

    I think it is not that useful to have a variable that points to different types of files (images and archives in this case).

    The following part looks more like a think-aloud protocol.

    Imagine a directory structure like this:


    Let's say the new variable is exemplarily identified by %X and expands as described, and MComix has been launched with one of these paths as its only argument. If you run a command C with %X, that is,

    C %X

    which, in this case, always expands to

    C /the

    then C just cannot necessarily tell whether you talk about archive.7z or image.jpg. That is, at least one of the following statements holds:

    • C knows by itself which file(s) to process.
    • C knows what to do with /the and is not particularily interested in the actual files.
    • C needs user interaction (e.g. C refers to Nautilus or C asks the user about the file to process).

    Assuming that there is no other possible case, it shows that the use cases for %X are quite limited because the requirements C has to satisfy are quite high.

    Please don't get me wrong. I only want to evaluate as much cases as possible because the namespace is limited (practically, not theoretically) and I don't want to flood it with useless or misnamed identifiers.

    For example, there might be another variable, let's call it %Y, which expands to the value of either %A or %D. Then, a command like

    cp -a %Y /mnt/sdb1

    would copy the whole comic book to the storage device mounted at /mnt/sdb1. Another use case for %Y is that you want to run another instance of MComix or a program that accepts both archives and directories as arguments.

    Now, let's assume that in future versions, MComix might be able to open directories within archives the same way it currently does for directories outside of any archives. (Note that there might be archives within archives!) In this case, it would be even harder to tell what %Y should expand to because there are even more reasonable choices.

    Again, please don't get me wrong. It's just that we must be careful when choosing reasonable variables/identifiers. For this reason, we should think about other scenarios as well. For example, what about a variable that expands to the path to the image within an archive? (Right now, this is only a rhetorical question for you.)

    The approach I can think of right now looks like this:

    1. There are four new variables, %S, %s, %B, %b.
    2. %b (as in book) expands to either the name of the archive (such as archive.7z) or the name of the directory that contains the images the user is currently looking at.
    3. %S (as in shelf) expands to the absolute path of the directory that contains the "book" the user is currently looking at.
    4. %s is the name of the directory %S points to.
    5. %B is short for %S%/%b in most cases.
    6. Special case: If there is neither an archive nor a named directory, that is, if the user is at / and currently looking at an image such as /image.jpg, then
      • %S expands to "/"
      • %s expands to ""
      • %b expands to ""
      • %B expands to "/"
        and similar for Windows-like systems.

    This way, the differences between the lowercase identifiers and their respective uppercase counterparts are similar to the differences in the identifiers that are currently available. Furthermore, all these variables expand to similar things regardless of whether you are working with archives or directories. This should make it easier to expand the set of available variables in future versions.

    The downside of this approach is that it does not perfectly match the originally requested semantics: If the user is not in an archive, then %S points to the directory that contains the current directory (rather than the current directory itself).

    What do you think about this approach? If this doesn't work for you, please describe your case in more detail.

  • Ark

    Ark - 2014-05-26

    @asl97: I just added %b, %B, %s, %S following the semantics I described above. As I said, this doesn't perfectly match the semantics you asked for. Is this okay for you? If not, please describe your case in more detail.

    @Oddegamra: Are you okay with it? If so, please test these changes on Windows.

  • asl97

    asl97 - 2014-08-13

    @Ark, i think we both are misunderstanding each other.

    From my understanding, %B is %Y in your example, it would expand to different things, if it was an archive, it would expand into the archive itself, while if it is the directory, it would expand to the directory.

    Maybe i need to explain a little more on what i mean in the main post (which i can't edit),

    i was thinking of

    %I (stand for ITEM) which will expand to ether %F or %A (the absolute path to the currently opened item)

    %i (also stand for item) which will expand to ether %f or %a (the name of the currently opened item)

    %P (stand for PATH) which will expand to ether %D or %C (the directory containing the currently opened item)

    %p (also stand for path) which will expand to ether %d or %c (the name of the directory containing the currently opened item)

    basically, those are shortcut to expend to what the current namespace expend to depending on what is open.

    %P is just a shortcut to "if it is image then use %D else if it is archive then use %C",
    it's not like we could easily put a if statement into the command to run nor
    do we have a single label that run different command depending on what is open

    let's use the example in the wiki to show it better

    lets say the image path is /home/user/Downloads/cats.jpg
    and the archive path is /home/user/comic-2014.zip

    %B would expend to /home/user/Downloads/ and /home/user/comic-2014.zip
    %b would expend to Downloads/ and comic-2014.zip
    %S would expand to /home/user/ and /home/user/
    %s would expand to user/ and user/

    %I would expend to /home/user/Downloads/cats.jpg and /home/user/comic-2014.zip
    %i would expend to cats.jpg and comic-2014.zip
    %P would expand to /home/user/Downloads/ and /home/user/
    %p would expand to Downloads/ and user/

    for a more readable view, see http://notehub.org/2014/8/13/namespace--homeusercomic-2014zip--homeus
    special case also shown in the link above

    if we could have a more powerful command system, it would be better and we wouldn't need those additional namespace

    better than the current one which can only just grey out when in archive and not in directory, it would be better to just hide the unusable label instead of grey it out, that way, i can have two label with the same name and it would show only one depending on what is open, something like one of them have "hide when in archive" tick and other other have "hide when in directory" tick

    Last edit: asl97 2014-08-13
  • Ark

    Ark - 2014-08-13

    Concerning variables: I think I know what you mean but still: What does a typical use case for these variables look like? What exactly is that kind of program you need to run with %I, %i, %P or %p?

    Concerning "a more powerful command system", I'm not sure what you are talking about. Do you talk about a scripting language like bash?

    Concerning hiding commands vs. disabling commands: One problem I see here is that currently, keyboard shortcuts for the first 9 commands are assigned automatically. If you hide a command, it's hard to tell whether it's a good idea to "hide" the corresponding shortcut as well which means that, if the user isn't careful enough, shortcuts get reassigned and he or she might end up hitting the wrong keys by accident.

    @Oddegamra: I don't want to update the docs yet because there is currently no official release that makes use of the new variables. Thanks for pointing that out, though.

  • asl97

    asl97 - 2014-08-13

    i never knew there are shortcuts for those...

    What does a typical use case for the current variables look like? what kind of program would people use with %A, %a, %D, %d, %C, %c, %F, %f, %B, %b, %S, %s?

    all i could think of is that those are very limited to certain program like cp,mv,file manager,homemake/custom script,clamav (antivirus scan) and others like it

    and tbh, i don't really see a usage for %I or %i and the usage of %P and %p are very limited too but i do use %P

    maybe something it could be done something like what is shown in the attachment

    leaving it blank basically mean nothing get executed instead of ticking the disable in archive

    Last edit: asl97 2014-08-13
  • Ark

    Ark - 2014-08-13

    Thank you for the suggestions but in my opinion the current "Open with" feature is quite advanced now and the changes to the dialog you suggested make things way more complicated.

    I made a shell script that runs thunar just the way you asked for. Use MComix to run /path/to/this_script.sh %B %S and you're done. Is this okay for you?

    [ -d "$1" ] && pathtouse="$1"
    exec thunar "$pathtouse"

    About the other variables, I can think of (and actually do have!) a lot of different use cases for many of them, including but not limited to: copying files or entire books to some device, running gimp, running mpv --loop-file %F, linking favorites, querying a database, running a terminal.

    About the shortcuts: Use the 1 to 9 keys for the first 9 commands as listed in the "Open with" dialog.

  • Ark

    Ark - 2015-02-14
    • status: open --> closed

Log in to post a comment.