It will not be easy to do Slovenia via public transportation, and impossible strictly by train.
Piran doesn't have a train station. The nearest is in Koper, so you have to take a 15-minute bus ride to Koper to get the train. Then the train to Ljubljana takes about 2 1/2 hours. You could take a bus all the way and save a little time, or drive in an hour and a half.
There is also no train station in Bled. You could take a train from Ljubljana about halfway and then switch to a bus, or you could take a bus all the way. Either way, you're looking at close to 2 hours. You could drive in 40 minutes.
There are trains between Ljubljana and Maribor and between Ljubljana and Postonja. The train from Ljubljana to Graz goes through Maribor, so if you decide you want to visit there, it makes sense to visit as a stop on the way to Graz.
But in my opinion, the best parts of Slovenia are Triglav National Park, the Julian Alps and the Soca Valley, none of which are accessible by train or bus.