2013-12-03 4 views
5

बहुत पहले, मुझे कुछ कोड (PERL ... urp) पर एक त्वरित नज़र आया, मेरे प्रबंधकों में से एक लिख रहा था और वह अपने कोड में इस्तेमाल किए गए बैनर/हेडिंग सिस्टम से डर गया था। मुझे अपने कोड में विस्तार से आने का मौका नहीं मिला, लेकिन स्क्रीन पर बैनर टिप्पणियों से मैं आसानी से बता सकता था कि कोड का क्या मतलब था, यहां तक ​​कि दूर से भी।टिप्पणी बैनर/शीर्षलेख सर्वोत्तम प्रथाओं/उदाहरण?

दुर्भाग्यवश वह बहुत समय पहले था और उस समय हमारी बातचीत ने मुझे यह उधार नहीं दिया था, "हाँ, शौचालय के नीचे जाने वाले हमारे डॉट कॉम स्टार्टअप के बारे में भूल जाओ, क्या मैं आपकी कोडिंग शैली पर नोट्स ले सकता हूं?"

सालों बाद, मैंने अभी तक एक उच्च स्तरीय टिप्पणी शैली हासिल नहीं की है जिसमें स्पष्टता है (शायद अब पौराणिक) कोड मैंने उस दिन देखा था।

जब मैं कहता हूं, "बैनर", मैं उच्च स्तरीय ब्लॉक डिवीजन/हेडर का जिक्र कर रहा हूं, कई कोडर अपने कोड में उच्च स्तरीय डिवीजन बनाने के लिए उपयोग करते हैं। वे आम तौर पर सरल ASCII डैश, स्लैश, बराबर चिह्न, आदि मेरे वर्तमान दैनिक उपयोग भाषा में से बना रहे हैं, एक कोड बैनर/हैडर पदानुक्रम हो सकता है:

# ======================================================== 
# = Header 1 
# ======================================================== 

# -------------------------------------------------------- 
# - Header 2 
#--------------------------------------------------------- 

# == Header 3 ============================================ 

# -- Header 4 -------------------------------------------- 

# Header 5 

और सभी सामान्य रूपों।

हालांकि मेरी खोजों ने कुछ भी उल्लेखनीय नहीं किया है, निश्चित रूप से वेब पर कहीं किसी के उदाहरणों को इकट्ठा करने और उन्हें व्यवस्थित ढंग से पेश करने का प्रयास किया गया है?

क्या कोई बैनर टिप्पणी शैली "सिस्टम" को इंगित कर सकता है जिसे वे उपयोगी पाते हैं? मैं "ओह, मुझे तारों का उपयोग करने वाले लोगों को पसंद है", लेकिन शैलियों की एक समग्र रणनीति से अधिक जो उच्च स्तरीय कोड निर्माण को समझने में आसान और समझने में आसान और आंखों पर आसान बनाता है? स्पष्ट रूप से विवरण की तुलना करने से उदाहरणों से पसंदीदा सिस्टम चुनना आसान होगा।

नोट: मुझे सामग्री में टिप्पणियों में से कोई दिलचस्पी नहीं है, लेकिन टिप्पणियों पर उपयोग की जाने वाली "फ्लेयर" समग्र कोड सामग्री और संगठन के स्पष्ट संकेत प्रदान करती है।

उत्तर

1

टिप्पणी करने की शैली को सत्यापित करने के सर्वोत्तम तरीकों में से एक है डॉक्सिजन जैसे कोड प्रलेखन उपकरण का उपयोग करना, here की अन्य सूची है, और फिर देखें कि आउटपुट कैसा था - आउटपुट स्पष्ट बेहतर टिप्पणियां।

मैं कहूंगा कि एकल सबसे बड़ा अंक स्थिरता और रैंकिंग का एक स्पष्ट संकेत है, इसके बाद पूर्णता और एकता के बाद, यानी एक बार जब आप एक को देखते हैं तो आपको पता होना चाहिए कि अन्य क्या दिखेंगे और आप कितने महत्वपूर्ण हैं देख रहा है यह आपको बिना किसी अच्छे डिजाइन के लिए मजबूर करता है क्योंकि आप नहीं जानते कि महत्वपूर्ण चीजें क्या हैं।

अगला सभी जानकारी लेकिन यह इतना छोटा हो कि एक नज़र में में लेने के लिए होना चाहिए आप की जरूरत मौजूद होना चाहिए - लेकिन संतोषजनक दोनों इन बलों आप तो अपने कोडिंग शैली बदलने के लिए है कि वस्तुओं/कोड बहुत बड़ा नहीं है, अच्छी तरह से नामित है, इसमें बहुत से पैरामीटर नहीं हैं, आदि, लिंट जैसे टूल हमें सिखाने की कोशिश करते हैं।

पायथन कोड के लिए PEP-257 पर स्टाइल सारांश बहुत उपयोगी दिशानिर्देश और कुछ उदाहरण प्रदान करता है।

मेरी मशीन पर कुछ "अच्छे" कोड के लिए एक त्वरित रूप से Andrea Gavana's Aquabutton.py चालू हुआ है, मैंने नीचे दिए गए कोड का एक अनुभाग शामिल किया है लेकिन आप पूर्ण कोड here देख सकते हैं - मुझे यह कहना है कि यह एंड्रिया का पहला मॉड्यूल था मैंने खोला, वर्णमाला में शुरुआती होने पर मुझे यकीन है कि कोई भी किया होगा।

# --------------------------------------------------------------------------------- # 
# AQUABUTTON wxPython IMPLEMENTATION 
# 
# Andrea Gavana, @ 07 October 2008 
# Latest Revision: 24 Nov 2011, 22.00 GMT 
# 
# 
# TODO List 
# 
# 1) Anything to do? 
# 
# 
# For all kind of problems, requests of enhancements and bug reports, please 
# write to me at: 
# 
# [email protected] 
# [email protected] 
# 
# Or, obviously, to the wxPython mailing list!!! 
# 
# 
# End Of Comments 
# --------------------------------------------------------------------------------- # 

""" 
:class:`AquaButton` is another custom-drawn button class which *approximatively* mimics 
the behaviour of Aqua buttons on the Mac. 


Description 
=========== 

:class:`AquaButton` is another custom-drawn button class which *approximatively* mimics 
the behaviour of Aqua buttons on the Mac. At the moment this class supports: 

* Bubble and shadow effects; 
* Customizable background, foreground and hover colours; 
* Rounded-corners buttons; 
* Text-only or image+text buttons; 
* Pulse effect on gaining focus. 

And a lot more. Check the demo for an almost complete review of the functionalities. 


Usage 
===== 

Sample usage:: 

    import wx 
    import wx.lib.agw.aquabutton as AB 

    app = wx.App(0) 

    frame = wx.Frame(None, -1, "AquaButton Test") 

    mainPanel = wx.Panel(frame) 
    mainPanel.SetBackgroundColour(wx.WHITE) 

    # Initialize AquaButton 1 (with image) 
    bitmap = wx.Bitmap("my_button_bitmap.png", wx.BITMAP_TYPE_PNG) 
    btn1 = AB.AquaButton(mainPanel, -1, bitmap, "AquaButton") 

    # Initialize AquaButton 2 (no image) 
    btn2 = AB.AquaButton(mainPanel, -1, None, "Hello World!") 

    frame.Show() 

    app.MainLoop() 


Supported Platforms 
=================== 

AquaButton has been tested on the following platforms: 
    * Windows (Windows XP); 
    * Linux Ubuntu (10.10). 


Window Styles 
============= 

`No particular window styles are available for this class.` 


Events Processing 
================= 

This class processes the following events: 

================= ================================================== 
Event Name  Description 
================= ================================================== 
``wx.EVT_BUTTON`` Process a `wxEVT_COMMAND_BUTTON_CLICKED` event, when the button is clicked. 
================= ================================================== 


License And Version 
=================== 

:class:`AquaButton` control is distributed under the wxPython license. 

Latest Revision: Andrea Gavana @ 22 Nov 2011, 22.00 GMT 

Version 0.4 

""" 

import wx 

# Constants for the hovering and clicking effects 
HOVER = 1 
""" Indicates that the mouse is hovering over :class:`AquaButton` """ 
CLICK = 2 
""" Indicates that :class:`AquaButton` has been clicked """ 


class AquaButtonEvent(wx.PyCommandEvent): 
    """ Event sent from the :class:`AquaButton` buttons when the button is activated. """ 

    def __init__(self, eventType, eventId): 
     """ 
     Default class constructor. 

     :param integer `eventType`: the event type; 
     :param integer `eventId`: the event identifier. 
     """ 

     wx.PyCommandEvent.__init__(self, eventType, eventId) 
     self.isDown = False 
     self.theButton = None 


    def SetButtonObj(self, btn): 
     """ 
     Sets the event object for the event. 

     :param `btn`: the button object, an instance of :class:`AquaButton`. 
     """ 

     self.theButton = btn 

स्निप

class AquaButton(wx.PyControl): 
    """ This is the main class implementation of :class:`AquaButton`. """ 

    def __init__(self, parent, id=wx.ID_ANY, bitmap=None, label="", pos=wx.DefaultPosition, 
       size=wx.DefaultSize, style=wx.NO_BORDER, validator=wx.DefaultValidator, 
       name="aquabutton"): 
     """ 
     Default class constructor. 

     :param Window `parent`: parent window. Must not be ``None``; 
     :param integer `id`: window identifier. A value of -1 indicates a default value; 
     :param Bitmap `bitmap`: the button bitmap (if any); 
     :param string `label`: the button text label; 
     :param `pos`: the control position. A value of (-1, -1) indicates a default position, 
     chosen by either the windowing system or wxPython, depending on platform; 
     :type `pos`: tuple or :class:`Point` 
     :param `size`: the control size. A value of (-1, -1) indicates a default size, 
     chosen by either the windowing system or wxPython, depending on platform; 
     :type `size`: tuple or :class:`Size` 
     :param integer `style`: the button style (unused); 
     :param Validator `validator`: the validator associated to the button; 
     :param string `name`: the button name. 
     """ 

     wx.PyControl.__init__(self, parent, id, pos, size, style, validator, name) 

     self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 

     self.Bind(wx.EVT_PAINT, self.OnPaint) 
     self.Bind(wx.EVT_ERASE_BACKGROUND, lambda event: None) 
     self.Bind(wx.EVT_SIZE, self.OnSize) 
     self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) 
     self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp) 
     self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseLeave) 
     self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseEnter) 
     self.Bind(wx.EVT_SET_FOCUS, self.OnGainFocus) 
     self.Bind(wx.EVT_KILL_FOCUS, self.OnLoseFocus) 
     self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) 
     self.Bind(wx.EVT_KEY_UP, self.OnKeyUp) 
     self.Bind(wx.EVT_TIMER, self.OnPulseTimer) 

     if "__WXMSW__" in wx.PlatformInfo: 
      self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDown) 

     self._mouseAction = None 
     self.SetBitmapLabel(bitmap) 
     self._hasFocus = False 
     self._saveBitmap = True 
     self._storedBitmap = wx.NullBitmap 
     self._pulseOnFocus = False 
     self._gammaFactor = 1.0 
     self._gammaIncrement = 0.1 

     self._timer = wx.Timer(self, wx.ID_ANY) 

     self.SetLabel(label) 
     self.InheritAttributes() 
     self.SetInitialSize(size) 

     # The following defaults are better suited to draw the text outline 
     if "__WXMAC__" in wx.PlatformInfo: 
      self._backColour = wx.Colour(147, 202, 255) 
      self._hoverColour = self.LightColour(self._backColour, 30) 
      self._disableColour = self.LightColour(self._backColour, 70) 
      self._textColour = wx.BLACK 
     else: 
      self._backColour = wx.SystemSettings.GetColour(wx.SYS_COLOUR_ACTIVECAPTION) 
      self._hoverColour = self.LightColour(self._backColour, 30) 
      self._disableColour = self.LightColour(self._backColour, 70) 
      self._textColour = wx.WHITE 


    def SetBitmapLabel(self, bitmap): 
     """ 
     Sets the bitmap label for the button. 

     :param `bitmap`: the bitmap label to set, an instance of :class:`Bitmap`. 
     """ 

     self._bitmap = bitmap 
     self.Refresh() 
+0

सहमत। क्या आप मुझे कुछ (वैकल्पिक रूप से पायथन) कोड पर इंगित कर सकते हैं जो इसका उदाहरण देता है? मुझे अब तक मिले/बनाए गए उदाहरण असंतोषजनक लगता है। –

+0

ऊपर जोड़ा गया एक उदाहरण। –

संबंधित मुद्दे