################################################################
#diceRollSim.py
#
#Purpose:  Provide a graphical interface to the dice_roller module; 
#   allow various die rolls using the mouse.  This program uses the wxGlade
#   GUI module.  Requires wxPython 2.6+ to be installed in addition to 
#   Python 2.3+.
#Author: Cody Jackson
#Date: 6/1/06
#
#Copyright 2006 Cody Jackson
#This program is free software; you can redistribute it and/or modify it 
#under the terms of the GNU General Public License as published by the Free 
#Software Foundation; either version 2 of the License, or (at your option) 
#any later version.
#
#This program is distributed in the hope that it will be useful, but 
#WITHOUT ANY WARRANTY; without even the implied warranty of 
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
#General Public License for more details.
#
#You should have received a copy of the GNU General Public License 
#along with this program; if not, write to the Free Software Foundation, 
#Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#----------------------------------------------------------------
#Version 1.0
#   Initial build
#################################################################
#!/usr/bin/env python
# -*- coding: ISO-8859-1 -*-
# generated by wxGlade 0.4 on Thu Jun 01 13:01:09 2006

import wx
from dice_roller import multiDie

class MyFrame(wx.Frame):
    """Container for dice roller window."""
    
    def __init__(self, *args, **kwds):
        """Creates dice roller panel with buttons and output field."""
        
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_1 = wx.Panel(self, -1)
        self.Title = wx.StaticText(self.panel_1, -1, "Dice roll simulator")
        self.roll_output = wx.TextCtrl(self.panel_1, -1, "")
        self.button_1d6 = wx.Button(self.panel_1, -1, "1d6")
        self.button_1d10 = wx.Button(self.panel_1, -1, "1d10")
        self.button_2d6 = wx.Button(self.panel_1, -1, "2d6")
        self.button_2d10 = wx.Button(self.panel_1, -1, "2d10")
        self.button_3d6 = wx.Button(self.panel_1, -1, "3d6")
        self.button_d100 = wx.Button(self.panel_1, -1, "d100 (%)")

        self.__set_properties()
        self.__do_layout()
        # end wxGlade
        
#---Button events
        wx.EVT_BUTTON(self, self.button_1d6.GetId(), self.pressed1d6)
        wx.EVT_BUTTON(self, self.button_2d6.GetId(), self.pressed2d6)
        wx.EVT_BUTTON(self, self.button_3d6.GetId(), self.pressed3d6)
        wx.EVT_BUTTON(self, self.button_1d10.GetId(), self.pressed1d10)
        wx.EVT_BUTTON(self, self.button_2d10.GetId(), self.pressed2d10)
        wx.EVT_BUTTON(self, self.button_d100.GetId(), self.pressed1d100)
    
#---Define button methods    
    def pressed1d6(self, event):
        """Roll one 6-sided die."""
        
        self.roll_output.SetValue("")   #clears any value in text box
        val = str(multiDie(1,1))
        self.roll_output.SetValue(val)
        
    def pressed2d6(self, event):
        """Roll two 6-sided dice."""
        
        self.roll_output.SetValue("")
        val = str(multiDie(2,1))
        self.roll_output.SetValue(val)
        
    def pressed3d6(self, event):
        """Roll three 6-sided dice."""
        
        self.roll_output.SetValue("")
        val = str(multiDie(3,1))
        self.roll_output.SetValue(val)
        
    def pressed1d10(self, event):
        """Roll one 10-sided die."""
        
        self.roll_output.SetValue("")
        val = str(multiDie(1,2))
        self.roll_output.SetValue(val)
        
    def pressed2d10(self, event):
        """Roll two 10-sided dice."""
        
        self.roll_output.SetValue("")
        val = str(multiDie(2,2))
        self.roll_output.SetValue(val)        

    def pressed1d100(self, event):
        """Roll one 100-sided die or roll a percentage."""
        
        self.roll_output.SetValue("")
        val = str(multiDie(1,3))
        self.roll_output.SetValue(val)

    def __set_properties(self):
        """Sets the visual presentation values of the window."""
        
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("Dice simulator")
        self.Title.SetFont(wx.Font(11, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, ""))
        self.roll_output.SetFont(wx.Font(11, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_1d6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_1d10.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_2d6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_2d10.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_3d6.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        self.button_d100.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
        # end wxGlade

    def __do_layout(self):
        """Sets the visual layout of window."""
        
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_1 = wx.GridSizer(4, 2, 0, 0)
        grid_sizer_1.Add(self.Title, 0, wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.roll_output, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_1d6, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_1d10, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_2d6, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_2d10, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_3d6, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        grid_sizer_1.Add(self.button_d100, 0, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
        self.panel_1.SetAutoLayout(True)
        self.panel_1.SetSizer(grid_sizer_1)
        grid_sizer_1.Fit(self.panel_1)
        grid_sizer_1.SetSizeHints(self.panel_1)
        sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
        self.SetAutoLayout(True)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        sizer_1.SetSizeHints(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame


class MyDice(wx.App):
    """Makes an instance of MyFrame."""
    
    def OnInit(self):
        """Initializes all settings for an instance."""
        
        wx.InitAllImageHandlers()
        diceRollSim = MyFrame(None, -1, "")
        self.SetTopWindow(diceRollSim)
        diceRollSim.Show()
        return 1

# end of class MyDice

if __name__ == "__main__":
    Dice_roll = MyDice(0)
    Dice_roll.MainLoop()

