def SetBitmap(self, bitmap):
"""
Set bitmap to use for button
@param bitmap: Name of bitmap to use for button
"""
# Get wx.Bitmap object corresponding to bitmap
self.Bitmap = GetBitmap(bitmap)
python类Bitmap()的实例源码
def GetSize(self):
"""
Return size of button
@return: wx.Size object containing button size
"""
# Button size is size of bitmap
return self.Bitmap.GetSize()
def Draw(self, dc):
"""
Draw button in Graphic Viewer
@param dc: wx.DC object corresponding to Graphic Viewer device context
"""
# Only draw button if button is active and displayed
if self.Shown and self.Enabled:
dc.DrawBitmap(self.Bitmap, self.Position.x, self.Position.y, True)
def GetBitmap(bmp_name1, bmp_name2=None, size=None):
bmp = BitmapLibrary.get((bmp_name1, bmp_name2, size))
if bmp is not None:
return bmp
if bmp_name2 is None:
bmp = SearchBitmap(bmp_name1)
else:
# Bitmap with two icon
bmp1 = SearchBitmap(bmp_name1)
bmp2 = SearchBitmap(bmp_name2)
if bmp1 is not None and bmp2 is not None:
# Calculate bitmap size
width = bmp1.GetWidth() + bmp2.GetWidth() - 1
height = max(bmp1.GetHeight(), bmp2.GetHeight())
# Create bitmap with both icons
bmp = wx.EmptyBitmap(width, height)
dc = wx.MemoryDC()
dc.SelectObject(bmp)
dc.Clear()
dc.DrawBitmap(bmp1, 0, 0)
dc.DrawBitmap(bmp2, bmp1.GetWidth() - 1, 0)
dc.Destroy()
elif bmp1 is not None:
bmp = bmp1
elif bmp2 is not None:
bmp = bmp2
if bmp is not None:
BitmapLibrary[(bmp_name1, bmp_name2, size)] = bmp
return bmp
def save_bitmap(self, path):
context = wx.ClientDC( self )
memory = wx.MemoryDC( )
x, y = self.ClientSize
bitmap = wx.Bitmap( x, y, -1 )
memory.SelectObject( bitmap )
memory.Blit( 0, 0, x, y, context, 0, 0)
memory.SelectObject( wx.NullBitmap)
bitmap.SaveFile( path, wx.BITMAP_TYPE_PNG )
def init_buf(self):
box = self.GetClientSize()
self.buffer = wx.Bitmap(box.width, box.height)
def build_tools(parent, toolspath):
global host
host = parent
## get tool datas from the loader.build_tools(toolspath)
## then generate toolsbar
datas = loader.build_tools(toolspath)
toolsbar = buildToolsBar(parent, datas)
gifpath = os.path.join(root_dir, "tools/drop.gif")
#btn = wx.BitmapButton(parent, wx.ID_ANY, wx.Bitmap(gifpath), wx.DefaultPosition, (30,30), wx.BU_AUTODRAW)
#btn.Bind(wx.EVT_LEFT_DOWN, lambda x:menu_drop(parent, toolsbar, datas, btn, x))
return toolsbar#, btn
def add_tools(bar, datas, curids=[]):
##! TODO:
## datas? dirpath tree to generate menus/toolsbar?
## curids? ??
box = bar.GetSizer()
if curids!=None:
for curid in curids:
bar.RemoveChild(curid)
box.Hide(curid)
box.Detach(curid)
if curids!=None:
del curids[:]
for data in datas:
btn = wx.BitmapButton(bar, wx.ID_ANY,
make_bitmap(wx.Bitmap(data[1])),
wx.DefaultPosition, (32,32),
wx.BU_AUTODRAW|wx.RAISED_BORDER )
if curids!=None:
curids.append(btn)
if curids==None:
box.Add(btn)
else:
box.Insert(len(box.GetChildren())-2, btn)
btn.Bind( wx.EVT_LEFT_DOWN, lambda x, p=data[0]:f(p(), x))
btn.Bind( wx.EVT_ENTER_WINDOW,
lambda x, p='"{}" Tool'.format(data[0].title): set_info(p))
if not isinstance(data[0], Macros) and issubclass(data[0], Tool):
btn.Bind(wx.EVT_LEFT_DCLICK, lambda x, p=data[0]:p().show())
btn.SetDefault()
box.Layout()
bar.Refresh()
if curids==None:
sp = wx.StaticLine( bar, wx.ID_ANY,
wx.DefaultPosition, wx.DefaultSize, wx.LI_VERTICAL )
box.Add( sp, 0, wx.ALL|wx.EXPAND, 2 )
box.AddStretchSpacer(1)
def init_buf(self):
box = self.GetClientSize()
self.width, self.height = box.width, box.height
self.buffer = wx.Bitmap(self.width, self.height)
def __set_properties(self):
# begin wxGlade: ui_choice2Dialog.__set_properties
self.SetTitle("ChiantiPy")
_icon = wx.EmptyIcon()
imagefile = os.path.join(chianti.__path__[0], "images/chianti2.png")
_icon.CopyFromBitmap(wx.Bitmap(imagefile, wx.BITMAP_TYPE_ANY))
self.SetIcon(_icon)
self.SetSize((448, 556))
# end wxGlade
def __init__(self, *args, **kwds):
# begin wxGlade: sampoorna_win.__init__
kwds["style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.MAXIMIZE | wx.MAXIMIZE_BOX | wx.STAY_ON_TOP | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.CLIP_CHILDREN
wx.Frame.__init__(self, *args, **kwds)
self.panel_1 = wx.ScrolledWindow(self, wx.ID_ANY, style=wx.TAB_TRAVERSAL)
self.panel_warning = wx.Panel(self.panel_1, wx.ID_ANY, style=wx.RAISED_BORDER | wx.STATIC_BORDER | wx.TAB_TRAVERSAL)
self.label_1 = wx.StaticText(self.panel_warning, wx.ID_ANY, _("label_1"))
self.panel_login = wx.Panel(self.panel_1, wx.ID_ANY)
self.bitmap_1 = wx.StaticBitmap(self.panel_login, wx.ID_ANY, wx.Bitmap("/home/ghssvythiri/Desktop/about.jpeg", wx.BITMAP_TYPE_ANY))
self.label_2 = wx.StaticText(self.panel_login, wx.ID_ANY, _("label_2"))
self.text_ctrl_1 = wx.TextCtrl(self.panel_login, wx.ID_ANY, "")
self.label_3 = wx.StaticText(self.panel_login, wx.ID_ANY, _("label_3"))
self.text_ctrl_2 = wx.TextCtrl(self.panel_login, wx.ID_ANY, "", style=wx.TE_PASSWORD)
self.button_1 = wx.Button(self.panel_login, wx.ID_ANY, _("button_1"))
self.panel_class = wx.Panel(self.panel_1, wx.ID_ANY)
self.checkbox_1 = wx.CheckBox(self.panel_class, wx.ID_ANY, _("checkbox_1"))
self.checkbox_2 = wx.CheckBox(self.panel_class, wx.ID_ANY, _("checkbox_2"))
self.checkbox_3 = wx.CheckBox(self.panel_class, wx.ID_ANY, _("checkbox_3"))
self.button_2 = wx.Button(self.panel_class, wx.ID_ANY, _("button_2"))
self.panel_progress = wx.Panel(self.panel_1, wx.ID_ANY)
self.panel_report = wx.Panel(self.panel_1, wx.ID_ANY)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_BUTTON, self.on_next, self.button_2)
# end wxGlade
def reset_photo(self,default=False):
print "changing photo"
cur_dir=os.path.dirname(os.path.abspath((sys.argv[0])))
if default:
path=cur_dir+"/Resources/img/browse.jpg"
else:
path=cur_dir+"/Resources/profile_pic/"+str(self.current_admission_no)+".jpg"
if not os.path.isfile(path):
path=cur_dir+"/Resources/img/browse.jpg"
if self.path!=path:# changes only if it has changed
self.bitmap_photo = wx.BitmapButton(self.panel_1, wx.ID_ANY,wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
#self.bitmap_photo.SetBitmapSelected( wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
selected_index=0
print self.combo_box_adno.GetSelection()
if self.combo_box_adno.GetSelection()>0:
selected_index=self.combo_box_adno.GetItems().index(self.current_admission_no)
self.__set_properties()
self.__do_layout()
self.combo_box_adno.SetSelection(selected_index)
self.bitmap_photo.Enable(True)
self.path=path
def on_photo(self, event): # wxGlade: student_profie.<event_handler>
#wcd="Image Files(*.jpeg)|*.jpeg| JPG Files(*.jpg)|*.jpg| PNG Files(*.png)|*.png"
#return 0
print "on photo"
wcd="Image Files(*.jpeg,*.jpg,*.png)|*.jpeg;*.jpg;*.png"
dir = "/home"
open_dlg = wx.FileDialog(self, message='Select Photo', defaultDir=dir, defaultFile= '', wildcard=wcd, style=wx.OPEN)
if open_dlg.ShowModal() == wx.ID_OK:
path = open_dlg.GetPath()
result=self.VALID.validate_photo(path)
if result[0]:
self.bitmap_photo = wx.BitmapButton(self.panel_1, wx.ID_ANY,wx.Bitmap(path, wx.BITMAP_TYPE_ANY))
self.__set_properties()
self.__do_layout()
self.button_save.Enable(True)
self.prof_pic_path=path
open_dlg.Destroy
self.combo_box_adno.SetValue(str(self.current_admission_no))
else:
open_dlg.Destroy
msg=result[1]
icon=wx.ICON_ERROR
dlg = wx.MessageDialog(self, msg, 'Size Error',wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
else:
open_dlg.Destroy()
event.Skip()
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("/home/john/Pictures/jasper gui jarvis/jarvisrotator.png", wx.BITMAP_TYPE_ANY))
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(_("frame_1"))
_icon = wx.EmptyIcon()
_icon.CopyFromBitmap(wx.Bitmap("/home/john/Pictures/jasper gui jarvis/jarvisrotator.png", wx.BITMAP_TYPE_ANY))
self.SetIcon(_icon)
# end wxGlade
def switchPanels(self):
active = self.active
self.panelStart.Hide()
self.panelDrinks.Hide()
self.panelUsers.Hide()
self.panelThanks.Hide()
self.panelSorry.Hide()
self.panelRFID.Hide()
if active == 0:
if settings.enableRFID:
self.rfid.start()
self.panelStart.Show()
elif active == 1:
if not settings.onlyOneDrink:
self.panelDrinks.l_amount.SetLabel("%02d" % 1)
self.panelDrinks.l_user.SetLabel(self.user.longname)
self.panelDrinks.Show()
elif active == 2:
self.panelUsers.Show()
elif active == 3:
self.panelThanks.label_1.SetLabel(self.user.longname + "\n" + "%02d x " % int(self.panelDrinks.GetAmount()) + self.drinkl.split('\n')[0])
self.panelThanks.label_1.Wrap(340)
try:
self.panelThanks.bitmap_2.SetBitmap(wx.Bitmap("./app/static/product_%s.png" % self.drinkl.split('\n')[0], wx.BITMAP_TYPE_ANY))
except:
logging.error("no picture for drink: " + self.drinkl.split('\n')[0])
self.panelThanks.Show()
self.delayExit()
elif active == 4:
self.panelSorry.label_1.SetLabel(self.user.longname)
self.panelSorry.Show()
else: #active == 5:
self.panelRFID.label_1.SetLabel(self.rfidid)
self.panelRFID.Show()
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./gui/start.png", wx.BITMAP_TYPE_ANY), pos=(0, 0))
if not settings.hideGuiList:
self.Bind(wx.EVT_LEFT_DOWN, parent.onStart)
self.bitmap_1.Bind(wx.EVT_LEFT_DOWN, parent.onStart)
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./gui/thanks.png", wx.BITMAP_TYPE_ANY), pos=(0, 0))
self.bitmap_2 = wx.StaticBitmap(self, wx.ID_ANY, wx.NullBitmap, pos=(10, 10))
self.label_1 = wx.StaticText(self, wx.ID_ANY, 'bla blub', pos=(120, 50), size=(340, 100))
self.label_1.SetFont(wx.Font(25, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))
self.label_1.SetForegroundColour("white")
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./gui/sorry.png", wx.BITMAP_TYPE_ANY), pos=(0, 0))
self.bitmap_1.Bind(wx.EVT_LEFT_DOWN, parent.onExit)
self.label_1 = wx.StaticText(self, wx.ID_ANY, 'bla blub', pos=(100,100))
self.label_1.SetFont(wx.Font(30, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.Bitmap("./gui/rfid.png", wx.BITMAP_TYPE_ANY), pos=(0, 0))
self.bitmap_1.Bind(wx.EVT_LEFT_DOWN, parent.onExit)
self.label_1 = wx.StaticText(self, wx.ID_ANY, 'bla blub', pos=(100,100), size=(100,220))
self.label_1.SetFont(wx.Font(30, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))