Mostrando las entradas con la etiqueta Clase. Mostrar todas las entradas
Mostrando las entradas con la etiqueta Clase. Mostrar todas las entradas

viernes, 1 de mayo de 2020

Eliminar archivos duplicados


Este código lo hice al ver que una carpeta tenía muchas imágenes repetidas, es decir totalmente idénticas, de ahí surge el problema y la pregunta. ¿Como eliminar las imagenes (.png) iguales?. Pues bien se me ocurrió usar el comando de Linux de consola "sha256sum" el cual te da un hash único, en teoría es imposible que salgan dos hashes iguales si los archivos son diferentes, solamente salen iguales si son idénticos. Este método es usado para comprobar la integridad de un archivo que ha sido descargado. Un ejemplo lo tenemos en el mismo Gambas, en la granja después de elegido un proyecto y descargado Gambas comprueba el hash, si es distinto te tirar error si es igual te dice que el archivo se descargo correctamente.

El código fuente se encuentra en la granja. Saludos

https://gambas.one/gambasfarm/?id=803&action=search


lunes, 20 de abril de 2020

aspell (clase)

Puedes usar esta clase para corregir las faltas ortográficas de un texto x, usa el programa aspell y para corregir en español instala aspell-es. Después amplio el post esta en la granja de gambas.



https://gambas.one/gambasfarm/?id=785&action=search

martes, 7 de abril de 2020

BoxInteger (clase)


Esta clase hereda de textbox, todo, valga la redundancia, pero le añadiremos un comportamiento particular en su evento KeyPress(). Este evento se lanza o se produce cuando presionamos una tecla. Por medio de un observador capturaremos este evento, haremos un filtro que si la tecla presionada no es un número del 0 a 9 retornemos previamente parando el evento mediante Stop Event haciendo que no se escriba el carácter elegido por el usuario mediante el teclado. Para escribir un número tendrá que presionar nuevamente otra tecla para lanzar el evento nuevamente y ahí actuará nuestro filtro. Otras teclas que permitiremos para que el usuario pueda editar serán suprimir, retornar, inicio, fin y alguna mas.

' gambas class file

'by postapase 07 abr 2020
Export

Inherits TextBox

Public Const Properties As String = "*"
Public Const _IsControl As Boolean = True
Public Const _DefaultSize As String = "14,4"
Public Const _Group As String = "Form"

Public obs As Observer

Property Read Valor As Integer

Public Sub _new()
'aquí esta el observador con el cual podremos manipular los eventos del textbox mediante la palabra "boxinteger" (aquí podemos poner un nombre a elección"
Obs = New Observer(Me) As "BoxInteger"

End




Public Sub BoxInteger_KeyPress()

Select Case Key.Code
Case Key.Del
Return
Case Key.Return
Return
Case Key.Home
Return
Case Key.End
Return
Case 16777234
Return
Case 16777236
Return
Case 16777219
Return
Case 48 To 57 'estos son los códigos ascii del número 0 al 9
Return
Default
End Select

Stop Event
Return

End

Private Function Valor_Read() As Integer

If Me.Text = "" Then Return 0

Return CInt(Me.Text)

End


Código:
https://gambas.one/gambasfarm/?id=776&action=search

jueves, 20 de febrero de 2020

La clase MaxZ


En el programa VisorRV1960 de forma muy repetitiva estoy usando botones que lo que hacen es maximizar el formulario y minimizarlo, pues bien era hora de crear una clase pues esa es la esencia de una clase que cuando hay un tarea repetitiva en vez de repetir el código se usa una clase.

El código esta en la granja de gambas, después amplio el post, saludos

codigo de clase:

' Gambas class file

'gb.settings debe estar incluida en el proyecto

Export

Inherits UserControl

Public Const _Properties As String = "*,Borde=true,Ayuda,Pintura,IconoMax,IconoMin"
Public Const _IsControl As Boolean = True
Public Const _DefaultEvent As String = "Clic"
Public Const _DefaultSize As String = "4,4"
Public Const _Group As String = "Form"

Static Public MaxZs As New MaxZ[]

Event Clic

Property Read Maximizar As Boolean
Property Borde As Boolean
Property Ayuda As String
Property IconoMax As Picture
Property IconoMin As Picture
Property Pintura As Picture

Private $FMaxZ As FMaxZ
Private $Amo As Form
Private $Borde As Boolean
Private $Ayuda As String
Private $IconoMax As Picture
Private $IconoMin As Picture
Private $Pintura As Picture
Private $Maximizado As Boolean

Public Sub _new()
 
  $FMaxZ = New FMaxZ(Me) As "evMaxz"
  Me.Proxy = $FMaxZ
 
  ObtenerForm(Me.Parent)
 
  MaxZs.Add(Me)
 
End

Private Sub ObtenerForm(padre As Object)
 
  If padre.parent Then
    If Object.Is(padre.parent, "Form") Then
      $Amo = padre.parent
    Else
      ObtenerForm(padre.parent)
    Endif
  Else
    'Sino tiene parent quiere decir que es un formulario
    If Object.Is(padre, "Form") Then
      $Amo = padre
    Endif
  Endif
 
End

Public Sub _Click()
 
  Raise Clic
 
  If IsNull($amo) Then Return
 
  $Amo.Maximized = Not $Amo.Maximized
  $Maximizado = $Amo.Maximized
 
  ActualizarIcono
 
  Settings[Me.Name & "/" & Me.Name & "_Maximizar"] = $Amo.Maximized
  Settings.Save
 
End

Public Sub ActualizarIcono()
 
  ' If $amo.Maximized Then
  If $Maximizado Then
    $FMaxZ.btnIcono.Picture = $IconoMin
  Else
    $FMaxZ.btnIcono.Picture = $IconoMax
  Endif
 
End

Public Sub Borrar()
 
  Settings.Clear(Me.Name)
  Settings.Save
 
End

Static Public Sub BorrarTodos() ''
 
  Dim MaxZx As MaxZ
 
  For Each MaxZx In MaxZs
    Settings.Clear(MaxZx.Name)
  Next
 
  Settings.Save
 
End

Private Function Borde_Read() As Boolean
 
  Return $Borde
 
End

Private Sub Borde_Write(Value As Boolean)
 
  $Borde = Value
 
  $FMaxZ.btnIcono.Border = Value
 
End

Private Function Maximizar_Read() As Boolean
 
  $Maximizado = Settings[Me.Name & "/" & Me.Name & "_Maximizar", False]
 
  ActualizarIcono
 
  Return Settings[Me.Name & "/" & Me.Name & "_Maximizar", False]
 
End

Private Function Ayuda_Read() As String
 
  Return $Ayuda
 
End

Private Sub Ayuda_Write(Value As String)
 
  $Ayuda = Value
 
  $FMaxZ.btnIcono.Tooltip = Value
 
End

Private Function IconoMax_Read() As Picture
 
  Return $IconoMax
 
End

Private Sub IconoMax_Write(Value As Picture)
 
  $IconoMax = Value
 
End

Private Function IconoMin_Read() As Picture
 
  Return $IconoMin
 
End

Private Sub IconoMin_Write(Value As Picture)
 
  $IconoMin = Value
 
End

Private Function Pintura_Read() As Picture
 
  Return $Pintura
 
End

Private Sub Pintura_Write(Value As Picture)
 
  $Pintura = Value
  $FMaxZ.btnIcono.Picture = Value
 
End

Codigo de formulario:

Public Sub Form_Open()

  Me.Maximized = MaxZ1.Maximizar

End

viernes, 7 de julio de 2017

Control personalizado


Aquí les dejo mi experimento en la creación de una clase o control personalizado, a medida para un fin x. El código esta en la granja.


' gambas class file

Export

Inherits UserControl

Public Const _Properties As String = "*,Texto,Seleccion,Hombre=True"
Public Const _DefaultEvent As String = "Eleccion"
Public Const _DefaultSize As String = "36,4"

Event Eleccion

Property Seleccion As Boolean
Property Texto As String
Property Hombre As Boolean

Private $Seleccion As Boolean
Private $Texto As String
Private $Hombre As Boolean

Private $hFondo As DrawingArea
Private $TextLabel As TextLabel
Private $CheckBox As CheckBox
Private $Persona As PictureBox

Public Sub _new()

$hFondo = New DrawingArea(Me) As "Fondo"
$hFondo.Background = &HFFEFBF
$hFondo.Arrangement = Arrange.Horizontal

$CheckBox = New CheckBox($hFondo) As "Check"
$CheckBox.Width = 20
$CheckBox.AutoResize = True
$CheckBox.Background = &HD2DFC3

$TextLabel = New TextLabel($hFondo) As "TexLabel"
$TextLabel.Alignment = Align.Center
$TextLabel.Expand = True
$TextLabel.Background = &HFFEFBF

$Persona = New PictureBox($hFondo) As "Persona"
Hombre_Write(True)
$Persona.Width = 40
$Persona.Stretch = True
$Persona.AutoResize = True

End

Public Sub Fondo_Enter()

$hFondo.Background = &H00FFFF

End

Public Sub Fondo_Leave()

$hFondo.Background = &HFFEFBF

End


Public Sub TexLabel_Enter()

$TextLabel.Tooltip = Me.Name

End

Public Sub TexLabel_MouseUp()

$CheckBox.Value = Not $CheckBox.Value

End

Public Sub Persona_MouseUp()

$CheckBox.Value = Not $CheckBox.Value

End


Public Sub Check_Click()

$Seleccion = $CheckBox.Value
Raise Eleccion

End

Private Function Seleccion_Read() As Boolean

Return $Seleccion

End

Private Sub Seleccion_Write(Value As Boolean)

$Seleccion = Value

End

Private Function Texto_Read() As String

$Texto = $TextLabel.Text
Return $Texto

End

Private Sub Texto_Write(Value As String)

$Texto = Value
$TextLabel.Text = $Texto

End

Private Function Hombre_Read() As Boolean

Return $Hombre

End

Private Sub Hombre_Write(Value As Boolean)

$Hombre = Value

If $Hombre Then
$Persona.Picture = Picture.Load("hombre.png")
Else
$Persona.Picture = Picture.Load("mujer.png")
Endif

End


jueves, 26 de enero de 2017

Control fbcolor by postapase



Interfaz gráfica de la clase (form)



' gambas class file

'by Postapase 26 enero 2017
'http://novatocodegambas.blogspot.com.uy/
'control fbcolor (foreground, background color)

Event CambioTrazo
Event CambioFondo
Event EnterTrazo
Event EnterFondo
Event Reseteo
Event EnterReseteo


Public Sub cbtnTrazo_Change()

Raise CambioTrazo

End

Public Sub cbtnFondo_Change()

Raise CambioFondo

End

Public Sub tbtnReseteo_Click()

Raise Reseteo

End

Public Sub cbtnTrazo_Enter()

Raise EnterTrazo

End

Public Sub cbtnFondo_Enter()

Raise EnterFondo

End

Public Sub tbtnReseteo_Enter()

Raise EnterReseteo

End





Clase fbcolor

' gambas class file

'by Postapase 26 enero 2017
'http://novatocodegambas.blogspot.com.uy/
'control fbcolor (foreground y background color)

Export

Inherits UserControl

Public Const _Properties As String = "*,Trazo{Color},Fondo{Color},TrazoPredeterminado{Color},FondoPredeterminado{Color}"
Public Const _DefaultEvent As String = "Modificacion"
Public Const _DefaultSize As String = "18,4"
Public Const _Group As String = "Chooser"

Event Reseteo
Event Modificacion

Property Trazo As Integer
Property Fondo As Integer
Property TrazoPredeterminado As Integer
Property FondoPredeterminado As Integer

Private $ffbcolor As Ffbcolor
Private $Trazo As Integer
Private $Fondo As Integer
Private $TrazoPredeterminado As Integer
Private $FondoPredeterminado As Integer

Public Sub _new()

$ffbcolor = New Ffbcolor(Me) As "Ev"
Me.Proxy = $ffbcolor
Reinicio()

End

Public Sub Ev_CambioTrazo()

$Trazo = $ffbcolor.cbtnTrazo.Value
Raise Modificacion

End

Public Sub Ev_CambioFondo()

$Fondo = $ffbcolor.cbtnFondo.Value
Raise Modificacion

End

Public Sub Ev_Reseteo()

Reinicio()
Raise Reseteo

End

Public Sub Reinicio()

$Fondo = $FondoPredeterminado
$Trazo = $TrazoPredeterminado
$ffbcolor.cbtnFondo.Value = $Fondo
$ffbcolor.cbtnTrazo.Value = $Trazo

End

Public Sub Ev_EnterTrazo()

$ffbcolor.cbtnTrazo.Tooltip = "Color de Trazo (clic para cambiar)"

End

Public Sub Ev_EnterFondo()

$ffbcolor.cbtnFondo.Tooltip = "Color de Fondo (clic para cambiar)"

End

Public Sub Ev_EnterReseteo()

$ffbcolor.tbtnReseteo.Tooltip = "Poner colores predeterminados"

End

Private Function Trazo_Read() As Integer

Return $Trazo

End

Private Sub Trazo_Write(Value As Integer)

$Trazo = Value
$ffbcolor.cbtnTrazo.Value = $Trazo
Raise Modificacion

End

Private Function Fondo_Read() As Integer

Return $Fondo

End

Private Sub Fondo_Write(Value As Integer)

$Fondo = Value
$ffbcolor.cbtnFondo.Value = $Fondo
Raise Modificacion

End

Private Function TrazoPredeterminado_Read() As Integer

Return $TrazoPredeterminado

End

Private Sub TrazoPredeterminado_Write(Value As Integer)

$TrazoPredeterminado = Value
Raise Modificacion

End

Private Function FondoPredeterminado_Read() As Integer

Return $FondoPredeterminado

End

Private Sub FondoPredeterminado_Write(Value As Integer)

$FondoPredeterminado = Value
Raise Modificacion

End



Dropbox fbcolor-0.1.1.tar.gz

jueves, 19 de enero de 2017

Control FontName by postapase


Control pensado para seleccionar tipo de fuente rapidamente y comodamente, con la opción de poner fuente predeterminada con un solo clic.

parte gráfica del control (ffontname) formulario

' gambas class file

'by postapase 18 de enero 2017
'http://novatocodegambas.blogspot.com.uy/
'control FontName

Event Reset
Event Seleccion
Event Enter

Public Sub Form_Open()

End

Public Sub btnFontDefault_Click()

Raise Reset

End

Public Sub cbxNombreFuentes_Click()

Raise Seleccion

End

Public Sub btnFontDefault_Enter()

Raise Enter

End



clase fontname

' gambas class file

'by postapase 18 de enero 2017
'http://novatocodegambas.blogspot.com.uy/
'control FontName

Export

Inherits UserControl

Public Const _Properties As String = "*,Predeterminada,Seleccionada,Index"
Public Const _DefaultEvent As String = "Seleccion"
Public Const _DefaultSize As String = "32,4"
Public Const _Group As String = "Chooser"

Event Seleccion
Event Reseteo ''Selecciona la fuente predeterminada de la aplicación

Property Predeterminada As String
Property Seleccionada As String
Property Index As Integer

Private $xfontname As Ffontname
Private $Predeterminada As String
Private $Seleccionada As String
Private $Index As Integer
Private $ListaFuentes As New String[]

Public Sub _new()

$xfontname = New Ffontname(Me) As "Ev"
$Predeterminada = Application.Font.Name
$Seleccionada = $Predeterminada
Me.Proxy = $xfontname.cbxNombreFuentes
ActualizarFuentes()

End

Public Sub Ev_Reset()

Reinicio()

Raise Reseteo

End

Public Sub Ev_Seleccion()

$Seleccionada = $xfontname.cbxNombreFuentes.Current.Text
$Index = $xfontname.cbxNombreFuentes.Index

Raise Seleccion

End

Public Sub EV_Enter()

$xfontname.btnFontDefault.Tooltip = "Seleccionar fuente predeterminada [ " & $Predeterminada & " ]"

End

Public Sub ActualizarFuentes()

Dim NombreFuente As String

For Each NombreFuente In Fonts
$ListaFuentes.Add(NombreFuente)
Next

$xfontname.cbxNombreFuentes.List = $ListaFuentes
$xfontname.cbxNombreFuentes.Add($Predeterminada, 0)

End

Private Function Predeterminada_Read() As String

Return $Predeterminada

End

Private Sub Predeterminada_Write(Value As String)

$Predeterminada = Value

End

Private Function Seleccionada_Read() As String

Return $Seleccionada

End

Private Sub Seleccionada_Write(Value As String)

$Seleccionada = Value

End

Private Function Index_Read() As Integer

Return $Index

End

Private Sub Index_Write(Value As Integer)

$Index = Value
$xfontname.cbxNombreFuentes.Index = $Index

End

Public Sub Reinicio()

$xfontname.cbxNombreFuentes.Index = 0
$Index = 0

En


Saludos y espero sus opiniones.

Necesario estar registrado en  https://www.gambas-es.org/
Descargar 

Dropbox:  fontname-0.1.2.tar.gz

miércoles, 18 de enero de 2017

FontName control supersimplificado




Este pequeño control surge de tener una lista completa de todos los nombres de fuentes disponibles comodamente en un combobox.
Pero a veces, podríamos necesitar ese combobox en muchos formularios.
Entonces es ahí donde hacer una clase tiene sentido,su poder o ventaja (ahorro de código) pues sera una tarea repetitiva.


' gambas class file

'by postapase
'http://novatocodegambas.blogspot.com.uy/

Export

Inherits ComboBox

Public Const _DefaultSize As String = "32,4"
Public Const _Group As String = "Chooser"

Private $ListaFuentes As New String[]

Public Sub _new()

Me.ReadOnly = True
Me.List = ObtenerFuentes()

End

Public Sub ObtenerFuentes() As String[]

Dim NombreFuente As String

For Each NombreFuente In Fonts
$ListaFuentes.Add(NombreFuente)
Next

Return $ListaFuentes

End


El nombre de la fuente seleccionada la obtenemos con:
FontName1.Current.Text

La lista de nombres de fuentes estan en la propiedad list de FontName:
FontName1.List



Descargar control