by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Oct 20 2019 22:59
    @dockimbel banned @SmackMacDougal
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
Toomas Vooglaid
@toomasv
@Yamoon2018 Thanks! :+1:
GiuseppeChillemi
@GiuseppeChillemi
How do I represent true and false inside a block? (Without using to-logic)
>> c: [a false] probe type? c/a
word!
== word!
>>
ne1uno
@ne1uno
#[false]
c: reduce [a to-logic false] mold/all c
GiuseppeChillemi
@GiuseppeChillemi
Thanks, I have just discovered to-logic before the path considers false as word because it is picked by path as this type and not for its content, so:
>> to-logic first [false]
== true
>> first reduce [to-logic false]
== false
>>
(Modified)
Toomas Vooglaid
@toomasv
Also
>> get first [false]
== false
>> type? get first [false]
== logic!
GiuseppeChillemi
@GiuseppeChillemi
? Why ?
Semseddin Moldibi
@endo64
You get the value of false word and it is false logic! value.
first reduce [to-logic false], when you reduce, to-logic is not necessary as false word evaluated to false logic!.
first reduce [false] or first compose [a (false)].
Python Mastermind
@Yamoon2018
@toomasv , I spend a lot of time reading & studying your code and its amazing, but I had to do some modification so it will fit my requirements also there are many things I coud not do it the same way you did it but I did it my way, here is the new code after modifications along with the notes for the errors I was unable to solve
Python Mastermind
@Yamoon2018

menu-block: layout/options [

size system/view/screens/1/size

on-menu[
    switch/default event/picked[        
        file-open[open-img]
        file-save[save-img]
        file-saveas[
            save file: request-file/filter ["png" "*.png" "jpeg" "*.jpg" "gif" "*.gif"] draw (canvas/size) (canvas/draw)
        ]
       qt[quit]
        ed-undo[undo-drawing]
        ed-redo[redo-drawing]
        menu-help[alert "My paint application"] 
    ][
        open-img/recent event/picked
    ]
]

][
menu: [
"File"[
"Open" file-open ---
"Save" file-save ---
"Save as" file-saveas ---
"Recent"[] ---
"Exit" qt
]
"Edit"[
"Undo" ed-undo
"Redo" ed-redo
]
"Help" menu-help

]

]

open-img: function[/recent file][

img-file-name: either recent[
    only-file-name: to-file to-string file
][
    img-file-name: request-file/filter ["png" "*.png" "jpeg" "*.jpg" "gif" "*.gif"]
    only-file-name: find/tail/last img-file-name  "/"
]

menu-block/text:  rejoin["File name: " only-file-name]

file-ref: to-word to-string only-file-name


if not recent [
    repend menu-block/menu/("File")/11[
        form only-file-name  file-ref  
    ]
]
probe menu-block/menu/("File")/11

img: load img-file-name


repend file-name img-file-name 

img-type: find img-file-name "."
canvas/draw/image: img 

]

Here is the notes & errors:
1) repend menu-block/menu/("File")/("Recent")
not working and give this error "Script Error: repend does not allow none! for its series argument"
so I didnt like this, repend menu-block/menu/("File")/11[

2) to-word replace/all to-string img-file-name #"/" #"|"
not working , no error , its just opening a request-file window when I click on any Recent file
so I did it like this,
file-ref: to-word to-string only-file-name

if not recent [
    repend menu-block/menu/("File")/11[
        form only-file-name  file-ref  
    ]

Soon I will upload my app on Github so everybody will get a chance to look at it and give me feedback

Thanks for support

Vladimir Vasilyev
@9214
@Yamoon2018 please use Github gists for sharing large snippets of code. Also, Gitter supports Markdown (press Ctrl + Shift + M in the message field to see the cheatsheet), so you can format code using fences — that way people who help you will have an easier time reading what you've posted.
Python Mastermind
@Yamoon2018
@9214 , Thanks for the advice, I will do it next time
nedzadarek
@nedzadarek
@GiuseppeChillemi you can as well add/change values in a block:
type? first append [] true
arr: [meh] arr/1: true type? first arr
Toomas Vooglaid
@toomasv

@Yamoon2018 Thanks for feedback!
Unfortunately the code you pasted here is not complete, so I have to invent some missing pieces.
Anyway, here are some remarks:
1) In open-img function the first expression (setting img-file-name) seems confused, as you are (re)setting same name inside either.

2) file-name (third line from bottom) is used only once and seems superfluous.

3) About your note (1): Does this work?

view/options [
   on-menu [tx/text: form next face/menu/("File")/("Recent")] 
   tx: text 200
][
   menu: ["File" ["Recent" ["Try" It works nevertheless]]]
]

If it does, then error message in your note (1) has some other cause, not because menu/("File")/("Recent") is not working.
If it doesn't, then what platform are you on?

4) About your note (2): Does this work the same for you?

>> to-word replace/all to-string %/C/some.file #"/" #"|"
== |C|some.file

If not, then what platform are you on?

5) The solution you adopted works as long as you open images from one folder only, because you save in "Recent" menu filenames without full path and switching to another folder it cannot find these files anymore.

Python Mastermind
@Yamoon2018
@toomasv , wow amazing, I got it, again let me go through it and I will upload the full code on Github soon so it will be available to anyone who would like to see it. By the way, I'm using Windows 10 and Note++ as an editor, if you suggest something better, please let me know.
Toomas Vooglaid
@toomasv
I use these too, so no suggestions :)
François Jouen
@ldci
@Yamoon2018 When programming under Windows, I using Crimson Editor http://www.crimsoneditor.com . We can directly run Red with this editor :-)
Rudolf Meijer
@meijeru
I have experience with both Crimson and Note++, they are both effective for Red.
Gregg Irwin
@greggirwin
I used Crimson for a long time. Been on UltraEdit for even longer, though I only use basic features.
I also used ConTEXT for a long time.
GaryMiller
@GaryMiller
I use Notepad++
Python Mastermind
@Yamoon2018

@toomasv ,
1)
view/options [
on-menu [tx/text: form next face/menu/("File")/("Recent")]
tx: text 200
][
menu: ["File" ["Recent" ["Try" It works nevertheless]]]
]
its not working and here is the error "* Syntax Error: invalid path! at "] tx: text 200 ][ m"

2) to-word replace/all to-string %/C/some.file #"/" #"|"
== |C|some.file
Also not working, I think because my Red folder has space its"Red programming" where I keep all the files, so when I use this code the result is this "|C|Users|pc|Documents|Yamin|Red"

Toomas Vooglaid
@toomasv
Interesting. Can anybody confirm that the following snippet gives error if File/Resent/Try is selected from menu:
view/options [on-menu [tx/text: form next face/menu/("File")/("Recent")] tx: text 200][menu: ["File" ["Recent" ["Try" It works nevertheless]]]]
About (2), yes spaces in folder-(or file)-names cause problem. Does something like this solve it?
>> parse file: to-string %"/C/Red programming" [any [change #"/" #"|" | change #" " "__" | skip]] fw: to-word file
== |C|Red__programming
>> parse file: to-string fw [any [change #"|" #"/" | change "__" #" " | skip]] to-file file
== %"/C/Red programming"
Semseddin Moldibi
@endo64
view/options [on-menu ... works for me, I see "It works nevertheless" message on the window.
@Yamoon2018 's sample code also works for me, so no missing brackets or something.
@Yamoon2018 Please use code formatting for your sample codes, you can see the details by pressing CRTL-SHIFT-M keys.
Python Mastermind
@Yamoon2018

1) I fix it by removing "Recent" from the menu

view/options [on-menu [tx/text: form next face/menu/("File")] tx: text 200]
[menu: ["File" ["Recent" ["Try" It works nevertheless]]]]

2) works fine with me

Thanks, everybody
mikeyaunish
@mikeyaunish
Is there a way to have a reaction lead to running a function? Other then using a timer to check changes in the variables?
Python Mastermind
@Yamoon2018
I found another way to do it whatever number of items in the menu
view/options [on-menu [tx/text:  form select  face/menu/("File") "Recent"] tx: text 200][
 menu: [
    "File" [
            "A" A 
            "B" B
            "C" C 

            "Recent" [
                "Try" YESS I DID IT]]
       ]
]
Toomas Vooglaid
@toomasv
@Yamoon2018 :+1:
@endo64 Thanks for checking it!
Semseddin Moldibi
@endo64
@mikeyaunish Is it something object ownership you are asking?
>> o: make object! [a: "test" on-change*: func [word old new] [print [word "changed"] ] ]
== make object! [
    a: "test"
]
>> o/a: "ok"
a changed
== "ok"
Python Mastermind
@Yamoon2018

@toomasv , I have your drawing pad , its amazing and I'm trying to find a way to do this

f with [extra: 'line         image: (draw 23x23 [line 5x5 17x17])]

but I still dont know how to do it and also i'm defining canvas: none out of the block, is this enough .

Toomas Vooglaid
@toomasv
@Yamoon2018 May be like this:
>> img: draw/transparent 23x23 [line 5x5 17x17]
== make image! [23x23 #{
    000000000000000000000000000000000000000000000000000000000000
    0000000000000000000000000000000000000000000000000000000...
>> view [button 25x25 with [image: img]]
Python Mastermind
@Yamoon2018
@toomasv , thanks
Toomas Vooglaid
@toomasv

@Yamoon2018 You are welcome!
If you want to do it "in-place", then:

view compose/deep [button 25x25 with [image: (draw/transparent 23x23 [line 5x5 17x17])]]

Or, without composing:

view [button 25x25 with [image: system/words/draw/transparent 23x23 [line 5x5 17x17]]]
Python Mastermind
@Yamoon2018
With or without compose, what is the difference , is it about speed,
Python Mastermind
@Yamoon2018
Here is my Red paint app link on Github, I would like to get everybody feedback on it,https://github.com/Yamoon2018/Red-paint-app
Semseddin Moldibi
@endo64
@Yamoon2018 You have a missing image, temp-img.png
Toomas Vooglaid
@toomasv
@Yamoon2018 Bravo!
Some quick notes:
  • triangle and polygon seem not to work
  • changed line-width is used not immediately on next figure but after that
Toomas Vooglaid
@toomasv

@Yamoon2018

With or without compose, what is the difference , is it about speed,

It's mainly about memory IMO, as compose will copy the block. But it will matter in case of large blocks or tight loops only. It also affects how parens in other places in the block will be interpreted, which sometimes may force you to reconsider parens for grouping purposes.

Python Mastermind
@Yamoon2018
@endo64 , I uploaded the missing image
@toomasv , It's still under development and I'm working on it.
Toomas Vooglaid
@toomasv
Ah, good!
Toomas Vooglaid
@toomasv
@Yamoon2018
  • reduce is superfluous in constructs like reduce[compose [...]]
  • Instead of recording mouse-state and then using mouse-state = 'down you can use event/down?
  • If you have already reduced or composed a block, then using rependis superfluous, use append instead. Or use repend but then no need for reduce or compose.
Semseddin Moldibi
@endo64
Good lessons from master Toomas :)
Toomas Vooglaid
@toomasv
:neckbeard: