World: r3wp
[Core] Discuss core issues
older newer | first last |
Ashley 20-Jul-2009 [14282] | Here's the finished code (which obtains REBOL compatable font names under Mac): fonts: copy [] caps: make bitset! [#"A" - #"Z"] foreach file compose [(read %/System/Library/Fonts/) (read %/Library/Fonts/)] [ if %.dfont = suffix? file [ s: form first parse file "." parse next s [any [mark: caps (insert mark #" ") 2 skip | skip] end] insert tail fonts s ] ] remove-each font-name fonts: sort unique fonts [ (size-text make face [text: "A" font: make face/font [name: font-name size: 10]]) = size-text make face [text: "A" font: make face/font [name: font-name size: 12]] ] (the windows func to do this is http://www.reboltech.com/library/scripts/get-fonts-windows.r ) |
Pekr 20-Jul-2009 [14283] | there's no edge condition. What if the name would not begin with a capital letter? I would parse all string and instead of 'next I would use 'trim, which would tream initial space, in case first letter is capital :-) But if it is the rule, that the first letter is always being a capital, then your solution is absolutly correct ... |
Ashley 20-Jul-2009 [14284] | First letter is always a capital ... except where it's a # but those fonts are not usable by REBOL anyway. |
Graham 20-Jul-2009 [14285] | Pekr, skip can always be used as the first word in the parse rule if you don't like next |
Graham 21-Jul-2009 [14286x2] | What's the best way of stopping an application from starting if another instance is already running? The app is a core based app that is in a forever loop. |
I guess I could always make it a View app instead, and wait on a port ... and use a timer to trigger the other stuff I need to do. | |
Pekr 21-Jul-2009 [14288x2] | I once used lock file - you keep file openeed, and you try to delete that lock from the other app. If you can delete it, so create lock file, if not, another instance is already running. But - that works only under Windows, I've heard that under Linux, you can delete file, even if another app is using it. Dunno if true ... |
You can also use TCP ports, but if you open some port, firewall will step-in and ask for approval ... | |
Graham 21-Jul-2009 [14290x2] | so, open a file and keep it open? |
could try that .. seems easy enough | |
Pekr 21-Jul-2009 [14292x2] | yes ... |
under Windows, if you open file in one process, another one can't delete it. Easy enough. Prevents the case, where process does not remove the lock, but crashes. Then you would be in locked situation. But if app crashes, you can remove the log. Under linux, dunno how to do it. One chance is e.g. the need for process to update timestamp, and if timestamp is not updated, then app most probably crashed, so you can start another instance ... | |
sqlab 21-Jul-2009 [14294] | open a listen port, there can only one be open |
Pekr 21-Jul-2009 [14295] | sqlab ... yes, but requires firewall approval ... |
Janko 21-Jul-2009 [14296] | maybe you can use rename in the same way I used it to implement simple locking just before in DB Chat channel |
Sunanda 21-Jul-2009 [14297] | One way: On startup: -- check for your timestamp file -- If it does not exist or (it exists and timestamp is over 2 minutes in past), proceed to run -- otherwise, wait 65 seconds. Test if timestamp has changed: yes-halt; no-proceed While running: -- write the timestamp file at least once a minute with an updated time On clean closedown: -- delete the timestamp file. Drawbacks: -- application could take over a minute to restart if immediately restarted after a crash. -- manual deletion of timestamp file can lead to multiple instances running (you can minimise this by re-reading file and aborting if timestamp is not the last one you set) -- all those writes of the file. |
sqlab 22-Jul-2009 [14298] | Sunanda, does your timestamp file mean a file with the timestamp as content or just the date and time of the file? I have many times seen, that the timestamp of a file under windows does not change, although there is always data added to the file. |
Graham 22-Jul-2009 [14299] | You can use set-modes to update the timestamp |
Sunanda 22-Jul-2009 [14300] | sqlab -- I mean a file whose contents is just a timestamp, eg: write %timestamp.txt mod now/precise In practice, the actual method is a little more convoluted (to avoid, for example, two instances both starting at once -- so neither sees a pre-existing timestamp.txt file). |
Robert 22-Jul-2009 [14301] | I need to issue the combination ALT+RETURN into a string. How can I do this? Is there a control character for ALT like for CTRL? |
ChristianE 22-Jul-2009 [14302] | AFAIK, due to multi-platform issues and various platforms not supporting it the ALT-key has never been utilized for the view event engine, hence it's probably not possible to detect the ALT-key. There's no /ALT refinement for the EVENT! datatype like there is /SHIFT and /CONTROL, so most likely there's also no control sequence for the ALT-key for /CORE to work with, too. |
Robert 22-Jul-2009 [14303] | I tried various HEX codes I found in google but none worked. Excel just printed strange chars instead of doing a line-break. |
Henrik 22-Jul-2009 [14304] | is alt+return really a char? |
Pekr 22-Jul-2009 [14305] | IIRC, Alt is supported under View. What might not be supported is combination of some keys, e.g. ctrl + tab, so you can't tab between the tabs in an OS compatible manner. It would require some tricks to register for such events. Dunno if Alt + Enter should work or not ... |
Anton 22-Jul-2009 [14306] | In R2 View, Alt is not supported. If you look at the event datatype, there are fields only for control and shift. |
Pekr 22-Jul-2009 [14307] | ah, my bad, Anton is right .... |
ChristianE 22-Jul-2009 [14308] | Robert, you're mentioning Excel, so you're probably trying to do ALT+RETURN hard line-breaks with Excel thru comlib? Maybe you can use the actual character code that Excel uses whenever one presses Alt+Enter. The web says Excel just inserts a line feed #"^/", have you tried that? |
Gabriele 23-Jul-2009 [14309] | Alt+RETURN is not a character |
Robert 23-Jul-2009 [14310] | Christian, right, I try to insert a hard line-break in Excel. I tried inserting NEWLINE, which doesn't work. Will try just the LN. Thanks. |
Graham 27-Jul-2009 [14311] | Apart from chucking an error, what is the best way to determine if a path exists inside an object? So, the path might be 10 deep ... |
Sunanda 27-Jul-2009 [14312] | As far as I know, Graham, there is not a simpler way than provoking an error. If you are already at the bottom of the structure FIND can help: a: make object! [b: make object! [c: 1]] find next first a/b 'd ;; is a/b/d valid? == none find next first a/b 'c ;; is a.b.c valid? == [c] But recursing to the bottom may be slower than just trying the error?: error? try [a/b/d] error? try [a/b/c] |
Graham 27-Jul-2009 [14313] | Seems ugly to have to use an error ... |
Anton 27-Jul-2009 [14314] | It's a poorly specified way of obtaining some information. |
Henrik 27-Jul-2009 [14315] | perhaps there is merit for a feature to quickly determine the existence of a deeply stored value? |
Graham 27-Jul-2009 [14316x3] | can't even do this in object 'path/to/rebol |
because 'in expects a word | |
How is this done in R3 ?? | |
BrianH 27-Jul-2009 [14319x2] | Same as in R2: in object/path/to 'rebol |
The problem is that at some point the field names can turn into function refinements, depending on the values assigned... | |
Anton 27-Jul-2009 [14321x4] | And why is that such a problem? |
I mean, it's a solvable problem. IN could theoretically be enhanced to also accept paths, but, iIrc, Carl wasn't keen on the idea because he wanted IN to remain simple and fast. He said something like "it's for words". | |
The only thing we can do is make our own mezz version of IN that accepts paths. | |
(Ok, it's not a solvable problem for paths with dynamic elements in them like functions, but of course, there are many more "static" paths which this would be darned useful for.) | |
BrianH 27-Jul-2009 [14325] | GET and SET work with paths in R3. Perhaps as you describe could be added as well, to handle the IN function for paths. And functions wouldn't be traced through. |
Graham 27-Jul-2009 [14326] | the problem with object/path/to 'rebol is that it assumes object/path/to exists |
BrianH 27-Jul-2009 [14327x3] | Yup. |
So you have to check for 'to in object/path first, and so on. I didn't say it would be a fast mezzanine :( | |
The way this kind of thing is resolved in R3 is through liberal use of the ASSERT/type function, and not representing XML as objects. | |
Graham 27-Jul-2009 [14330x2] | I guess there's a lot of advantages to just using blocks ... as it is now, some elements in my object are blocks and some are objects which makes it very messy |
OTOH, blocks could get messy too ... at present I have structures like ccr/body/alerts/alert where alert can be either a single alert object, or a block of alert objects Ideally if I were to use blocks, it would end up that alert is always a block .. 0 ... n blocks | |
older newer | first last |