tools_view.py :  » Business-Application » hylaPEx » hylapex » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » hylaPEx 
hylaPEx » hylapex » tools_view.py
#Boa:Frame:Tools
# -*- coding: utf-8 -*-
#
# hylaPEx, an hylafax client written in python
#
# www.unipex.it/hylapex/
#
# License:
#         GNU General Public License (GPL)
#         For more info see LICENSE.txt and LICENSE-GPL.txt
#
# Copyright (C) 2004-2006  Unipex s.r.l.,  All Rights Reserved.
# Via Vittorio Veneto 83/A
# 33050 Gonars (UD) - Italy
# phone 0039 0432 931511 - fax 0039 0432 931378
# www.unipex.it - michele.petrazzo@unipex.it

import wx
import wx.lib.buttons
import wx_util, os

class Tools(wx.MiniFrame):
    def __init__(self, parent, paths, pos = wx.Size(0,0)):
        wx.MiniFrame.__init__(self, parent, -1, title='Tools')
        self.SetBackgroundColour( wx.Colour(225, 225, 225) )
        
        self.Bind(wx.EVT_CLOSE, lambda event: event )
        
        self.parent = parent
        self.paths = paths
        
        if pos: 
            self.SetPosition(pos)
        else:
            self.CenterOnParent()
        
        self.CurColor = (0,0,0)
        self.CurFontName = 'Arial'
        self.CurFontSize = 36
        
        #Sizer
        self.toolSizer = wx.FlexGridSizer(5, 3)
        undoSizer = wx.BoxSizer(wx.HORIZONTAL)
        
        #Buttons
        self.bt_pen = wx.ToggleButton(self, -1, 'Pen')
        self.bt_pen.Bind(wx.EVT_TOGGLEBUTTON, self.OnBt_penButton)
       
        self.bt_text = wx.ToggleButton(self, -1, 'Text')
        self.bt_text.Bind(wx.EVT_TOGGLEBUTTON, self.OnBt_textButton)
        
        self.bt_img = wx.ToggleButton(self, -1, 'Image')
        self.bt_img.Bind(wx.EVT_TOGGLEBUTTON, self.OnBt_imageButton)

        self.bt_none = wx.ToggleButton(self, -1, 'No')
        self.bt_none.Bind(wx.EVT_TOGGLEBUTTON, self.OnBt_NoneButton)
        self.bt_none.SetValue(True)
                
        self.bt_undo_bmp = wx.BitmapButton(self, -1, wx.NullBitmap, style=wx.BU_AUTODRAW)
        self.bt_undo_bmp.Bind(wx.EVT_BUTTON, self.OnBt_undo_bmpButton)
        
        #Text
        self.txt_line_w = wx.TextCtrl(self, -1, '10', style=wx.TE_CENTER)
        self.txt_text_w = wx.TextCtrl(self, -1, '%s' % self.CurFontSize, style=wx.TE_CENTER)
        self.txt_text_w.Bind(wx.EVT_TEXT, self.OnText)
        
        self.bmp_colour = wx.Panel(self, -1)
        self.bmp_colour.Bind(wx.EVT_LEFT_DOWN, self.OnBmp_colourLeftDown)

        self.lbl_example = wx.StaticText(self, -1, 'Example')
        self.lbl_example.SetCursor(wx.CROSS_CURSOR)
        self.lbl_example.Bind(wx.EVT_LEFT_DOWN, self.OnLbl_exampleLeftDown)
        
        #Add widgets to sizer
        flags = wx.ALIGN_CENTER | wx.ALL
        space = 2
        
        self.lbl_pen = wx.StaticText(self, -1, 'Pen')
        self.toolSizer.Add(self.lbl_pen, 0, flags, space)
        self.toolSizer.Add(self.bt_pen, 0, flags, space)
        self.toolSizer.Add(self.txt_line_w, 0, flags, space)
        
        self.lbl_text = wx.StaticText(self, -1, 'Text')
        self.toolSizer.Add(self.lbl_text , 0, flags, space)
        self.toolSizer.Add(self.bt_text, 0, flags, space)
        self.toolSizer.Add(self.txt_text_w, 0, flags, space)
        
        self.lbl_image = wx.StaticText(self, -1, 'Image')
        self.toolSizer.Add(self.lbl_image , 0, flags, space)
        self.toolSizer.Add(self.bt_img, 0, flags, space)
        self.toolSizer.Add(wx.Size(0,0) ,0)
        
        self.lbl_none = wx.StaticText(self, -1, 'Move')
        self.toolSizer.Add(self.lbl_none , 0, flags, space)
        self.toolSizer.Add(self.bt_none, 0, flags, space)
        self.toolSizer.Add(wx.Size(0,0) ,0)
        
        self.lbl_example_descr = wx.StaticText(self, -1, 'Example')
        self.toolSizer.Add(self.lbl_example_descr , 0, flags, space)
        self.toolSizer.Add(self.bmp_colour, 0, flags, space)
        self.toolSizer.Add(self.lbl_example, 0, flags, space)
        
        self.lbl_undo = wx.StaticText(self, -1, 'Undo')
        self.toolSizer.Add(self.lbl_undo , 0, flags, space)
        self.toolSizer.Add(self.bt_undo_bmp, 0, flags, space)
        self.toolSizer.Add(wx.Size(0,0) ,0)
        

        frameSizer = wx.BoxSizer(wx.VERTICAL)
        
        frameSizer.Add(self.toolSizer, 0, wx.EXPAND)
        #frameSizer.Add(undoSizer, 0, wx.EXPAND)

        #I18n
        if paths and hasattr(paths, 'my_path'):
            my_path_imgs = os.path.join(paths.my_path, 'imgs')
            self.ren = wx_util.rename_ctrls(self, 'tools_view', paths.my_path, \
                lang = paths.language)
            self.ren.rename()
        else:
            my_path_imgs = './imgs/'

        dict_img = {self.bt_undo_bmp: ('undo.jpg', (20,20))}
        for inst_but in dict_img:
            f = os.path.join(my_path_imgs, dict_img[inst_but][0])
            i = wx_util.del_mask2img(f,dict_img[inst_but][1] )
            inst_but.SetBitmapLabel(i)

        self.lbl_example.SetFont(self._GetFont())
        self._set_bmp()
        
        self.TB = wx_util.GoToggleButton( (self.bt_pen, self.bt_text, 
                          self.bt_img, self.bt_none) )

        self.SetSizerAndFit(frameSizer)
        
    
    def SetButton(self, bt, value):
        """ Set the button passed
        """
        self.TB.go(bt, value)
        self.parent.CtrlCursor()
        
    def OnBt_penButton(self, event):
        """ Pen event button
        """ 
        self.TB.go(self.bt_pen, event.IsChecked())
        self.parent.CtrlCursor()

    def OnBt_textButton(self, event):
        self.TB.go(self.bt_text, event.IsChecked())
        self.parent.CtrlCursor()
    
    def OnBt_imageButton(self, event):
        self.TB.go(self.bt_img, event.IsChecked())
        self.parent.CtrlCursor()
    
    def OnBt_NoneButton(self, event):
        self.TB.go(self.bt_none, event.IsChecked())
        self.parent.CtrlCursor()

    def OnBt_undo_bmpButton(self, event):
        """ Go with undo
        """
        self.parent.GoUndo()
    
    def OnBmp_colourLeftDown(self, event):
        dlg = wx.ColourDialog(self)
        dlg.GetColourData().SetChooseFull(True)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetColourData()
            self._set_bmp(data.GetColour().Get())
        dlg.Destroy()

    def OnLbl_exampleLeftDown(self, event):
        if not self.bt_text.GetValue():
            return
        data = wx.FontData()
        data.SetInitialFont(self._GetFont())
        data.SetColour(self.CurColor)
        
        dlg = wx.FontDialog(self, data)
        if dlg.ShowModal() == wx.ID_OK:
            data = dlg.GetFontData()
            font = data.GetChosenFont()
            self.CurFontName = font.GetFaceName()
            self.CurFontSize = font.GetPointSize()
        dlg.Destroy()
        
        self._set_bmp(self.CurColor)
        fontToSet = self._GetFont()
        self.lbl_example.SetFont(fontToSet)
        
        self.txt_text_w.SetValue(str(self.CurFontSize))
        #Fit the sizer
        self.Fit()
        
    def OnText(self, event):
        size = event.GetString()
        if not size:
            return
        
        self.CurFontSize = int( size )
        self.lbl_example.SetFont(self._GetFont())
        self.Layout()
        self.Fit()

    def _set_bmp(self, color = (0,0,0)):
        self.CurColor = color
        self.bmp_colour.SetBackgroundColour(color)
        self.lbl_example.SetForegroundColour(color)
        self.Refresh()


    def _GetFont(self, FS = 0, FN = ''):
        if FS and FN:
            return wx.Font(FS, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName=FN)
        elif FS:
            return wx.Font(FS, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName=self.CurFontName)
        elif FN:
            return wx.Font(self.CurFontSize, wx.DEFAULT, wx.NORMAL,wx.NORMAL, faceName=FN)
        else:
            return wx.Font(self.CurFontSize, wx.DEFAULT, wx.NORMAL,wx.NORMAL, faceName=self.CurFontName)        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.